[Bf-blender-cvs] [14533f446c5] greasepencil-object: Change tonemapping to shader
Antonio Vazquez
noreply at git.blender.org
Sun Feb 18 12:25:58 CET 2018
Commit: 14533f446c51caa5cf7b3e543df246300863c91f
Author: Antonio Vazquez
Date: Sun Feb 18 12:04:43 2018 +0100
Branches: greasepencil-object
https://developer.blender.org/rB14533f446c51caa5cf7b3e543df246300863c91f
Change tonemapping to shader
This makes faster the tonemapping and fix texture issues.
Still pending clear old colorspace code.
===================================================================
M source/blender/draw/engines/gpencil/gpencil_engine.c
M source/blender/draw/engines/gpencil/gpencil_engine.h
M source/blender/draw/engines/gpencil/gpencil_geom.c
M source/blender/draw/engines/gpencil/shaders/gpencil_zdepth_mix_frag.glsl
===================================================================
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index 0b4fb88fa26..460f5abf52b 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -227,6 +227,7 @@ static void GPENCIL_cache_init(void *vedata)
stl->g_data->tot_sh_stroke = 0;
stl->g_data->tot_sh_fill = 0;
stl->g_data->tot_sh_point = 0;
+ stl->storage->tonemapping = 0;
stl->g_data->shgrps_edit_line = NULL;
stl->g_data->shgrps_edit_point = NULL;
@@ -370,6 +371,7 @@ static void GPENCIL_cache_init(void *vedata)
DRW_shgroup_call_add(mix_shgrp, quad, NULL);
DRW_shgroup_uniform_buffer(mix_shgrp, "strokeColor", &e_data.input_color_tx);
DRW_shgroup_uniform_buffer(mix_shgrp, "strokeDepth", &e_data.input_depth_tx);
+ DRW_shgroup_uniform_int(mix_shgrp, "tonemapping", &stl->storage->tonemapping, 1);
/* mix pass no blend */
struct Gwn_Batch *quad_noblend = DRW_cache_fullscreen_quad_get();
@@ -379,6 +381,7 @@ static void GPENCIL_cache_init(void *vedata)
DRW_shgroup_call_add(mix_shgrp_noblend, quad_noblend, NULL);
DRW_shgroup_uniform_buffer(mix_shgrp_noblend, "strokeColor", &e_data.input_color_tx);
DRW_shgroup_uniform_buffer(mix_shgrp_noblend, "strokeDepth", &e_data.input_depth_tx);
+ DRW_shgroup_uniform_int(mix_shgrp_noblend, "tonemapping", &stl->storage->tonemapping, 1);
/* vfx copy pass from txtb to txta */
struct Gwn_Batch *vfxquad = DRW_cache_fullscreen_quad_get();
@@ -388,6 +391,7 @@ static void GPENCIL_cache_init(void *vedata)
DRW_shgroup_call_add(vfx_copy_shgrp, vfxquad, NULL);
DRW_shgroup_uniform_buffer(vfx_copy_shgrp, "strokeColor", &e_data.vfx_color_tx_b);
DRW_shgroup_uniform_buffer(vfx_copy_shgrp, "strokeDepth", &e_data.vfx_depth_tx_b);
+ DRW_shgroup_uniform_int(vfx_copy_shgrp, "tonemapping", &stl->storage->tonemapping, 1);
/* VFX pass */
psl->vfx_wave_pass = DRW_pass_create("GPencil VFX Wave Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
@@ -825,7 +829,11 @@ static void GPENCIL_draw_scene(void *vedata)
else {
DRW_framebuffer_bind(fbl->main);
}
+ /* tonemapping */
+ stl->storage->tonemapping = stl->storage->is_render ? 1 : 0;
DRW_draw_pass(psl->mix_pass);
+
+ stl->storage->tonemapping = 0;
/* prepare for fast drawing */
if (!is_render) {
gpencil_prepare_fast_drawing(stl, dfbl, fbl, psl->mix_pass_noblend, clearcol);
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.h b/source/blender/draw/engines/gpencil/gpencil_engine.h
index ddab26c8e95..d66fd35653b 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.h
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.h
@@ -170,6 +170,7 @@ typedef struct GPENCIL_Storage {
float gridcolor[3];
const float *pixsize;
float render_pixsize;
+ int tonemapping;
/* Render Matrices and data */
float persmat[4][4], persinv[4][4];
diff --git a/source/blender/draw/engines/gpencil/gpencil_geom.c b/source/blender/draw/engines/gpencil/gpencil_geom.c
index e0a9a66b5a4..6aa5bdea1ac 100644
--- a/source/blender/draw/engines/gpencil/gpencil_geom.c
+++ b/source/blender/draw/engines/gpencil/gpencil_geom.c
@@ -55,13 +55,13 @@
/* helper to convert color space to linear */
static void gpencil_linear_colorspace(const float color[4], ColorSpace *colorspace, float r_color[4])
{
- if ((DRW_state_is_image_render()) && (colorspace != NULL)) {
+ //if ((DRW_state_is_image_render()) && (colorspace != NULL)) {
+ // copy_v4_v4(r_color, color);
+ // IMB_colormanagement_colorspace_to_scene_linear_v4(r_color, false, colorspace);
+ //}
+ //else {
copy_v4_v4(r_color, color);
- IMB_colormanagement_colorspace_to_scene_linear_v4(r_color, false, colorspace);
- }
- else {
- copy_v4_v4(r_color, color);
- }
+ //}
}
/* set stroke point to vbo */
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_zdepth_mix_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_zdepth_mix_frag.glsl
index 4f6075d3bbf..25a245a5379 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_zdepth_mix_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_zdepth_mix_frag.glsl
@@ -4,6 +4,23 @@ out vec4 FragColor;
uniform sampler2D strokeColor;
uniform sampler2D strokeDepth;
+uniform int tonemapping;
+
+float srgb_to_linearrgb(float c)
+{
+ if (c < 0.04045)
+ return (c < 0.0) ? 0.0 : c * (1.0 / 12.92);
+ else
+ return pow((c + 0.055) * (1.0 / 1.055), 2.4);
+}
+
+float linearrgb_to_srgb(float c)
+{
+ if (c < 0.0031308)
+ return (c < 0.0) ? 0.0 : c * 12.92;
+ else
+ return 1.055 * pow(c, 1.0 / 2.4) - 0.055;
+}
void main()
{
@@ -11,6 +28,15 @@ void main()
float stroke_depth = texelFetch(strokeDepth, uv, 0).r;
vec4 stroke_color = texelFetch(strokeColor, uv, 0).rgba;
- FragColor = stroke_color;
+ if (tonemapping == 1) {
+ FragColor.r = srgb_to_linearrgb(stroke_color.r);
+ FragColor.g = srgb_to_linearrgb(stroke_color.g);
+ FragColor.b = srgb_to_linearrgb(stroke_color.b);
+ FragColor.a = stroke_color.a;
+ }
+ else {
+ FragColor = stroke_color;
+ }
+
gl_FragDepth = stroke_depth;
}
More information about the Bf-blender-cvs
mailing list