Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntonioya <blendergit@gmail.com>2018-11-27 00:52:28 +0300
committerAntonioya <blendergit@gmail.com>2018-11-27 00:52:28 +0300
commitf753fd17799cc92410b6115ea5ad9f3c2151072f (patch)
treed0bfe829b64251a6fea65cbb9af545689f79733c /source/blender/draw
parent26df95cff6620f17d6631c83efe05177b7a90e87 (diff)
GP: Correct Tonemapping for Blend Layers
Diffstat (limited to 'source/blender/draw')
-rw-r--r--source/blender/draw/engines/gpencil/gpencil_engine.c3
-rw-r--r--source/blender/draw/engines/gpencil/shaders/gpencil_blend_frag.glsl28
2 files changed, 29 insertions, 2 deletions
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index a7141ff93bb..483d6a80991 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -506,6 +506,7 @@ void GPENCIL_cache_init(void *vedata)
DRW_shgroup_uniform_int(blend_shgrp, "mode", &stl->storage->blend_mode, 1);
DRW_shgroup_uniform_int(blend_shgrp, "clamp_layer", &stl->storage->clamp_layer, 1);
DRW_shgroup_uniform_float(blend_shgrp, "blend_opacity", &stl->storage->blend_opacity, 1);
+ DRW_shgroup_uniform_int(mix_shgrp, "tonemapping", &stl->storage->tonemapping, 1);
/* create effects passes */
if (!stl->storage->simplify_fx) {
@@ -813,7 +814,9 @@ void GPENCIL_draw_scene(void *ved)
stl->storage->blend_mode = array_elm->mode;
stl->storage->clamp_layer = (int)array_elm->clamp_layer;
stl->storage->blend_opacity = array_elm->blend_opacity;
+ stl->storage->tonemapping = stl->storage->is_render ? 1 : 0;
DRW_draw_pass(psl->blend_pass);
+ stl->storage->tonemapping = 0;
/* Copy B texture to A texture to follow loop */
e_data.input_depth_tx = e_data.temp_depth_tx_b;
diff --git a/source/blender/draw/engines/gpencil/shaders/gpencil_blend_frag.glsl b/source/blender/draw/engines/gpencil/shaders/gpencil_blend_frag.glsl
index 8eeb0b8bc7f..877693724f9 100644
--- a/source/blender/draw/engines/gpencil/shaders/gpencil_blend_frag.glsl
+++ b/source/blender/draw/engines/gpencil/shaders/gpencil_blend_frag.glsl
@@ -9,6 +9,7 @@ uniform sampler2D blendDepth;
uniform int mode;
uniform int clamp_layer;
uniform float blend_opacity;
+uniform int tonemapping;
#define ON 1
#define OFF 0
@@ -76,6 +77,28 @@ vec4 get_blend_color(int mode, vec4 src_color, vec4 blend_color)
return outcolor;
}
+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;
+}
+
+vec4 tone(vec4 stroke_color)
+{
+ if (tonemapping == 1) {
+ vec4 color = vec4(0, 0, 0, stroke_color.a);
+ color.r = linearrgb_to_srgb(stroke_color.r);
+ color.g = linearrgb_to_srgb(stroke_color.g);
+ color.b = linearrgb_to_srgb(stroke_color.b);
+ return color;
+ }
+ else {
+ return stroke_color;
+ }
+}
+
void main()
{
vec4 outcolor;
@@ -115,17 +138,18 @@ void main()
gl_FragDepth = mix_depth;
}
}
+ FragColor = tone(FragColor);
return;
}
/* if not using mask, return mix color */
if ((stroke_color.a == 0) && (clamp_layer == OFF)) {
- FragColor = mix_color;
+ FragColor = tone(mix_color);
gl_FragDepth = mix_depth;
return;
}
/* apply blend mode */
- FragColor = get_blend_color(mode, stroke_color, mix_color);
+ FragColor = tone(get_blend_color(mode, stroke_color, mix_color));
gl_FragDepth = stroke_depth;
}