diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2019-03-22 05:53:13 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2019-03-22 05:53:21 +0300 |
commit | c49a70bcd113904b239079413e32fc1228776967 (patch) | |
tree | d94b9f28d6d0cdf90aec84d0261af2cd537be3f3 /source | |
parent | 875b50f94f993eabcd03e3c4485ba3a4b0990df8 (diff) |
Eevee: Add small optimisation for Curve Mapping nodes
This remove the RGB texture lookups if the curve is only used for "Luma"
correction and does not affect individual RGB channels.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_material.glsl | 19 | ||||
-rw-r--r-- | source/blender/nodes/shader/nodes/node_shader_curves.c | 38 |
2 files changed, 50 insertions, 7 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl index ccc2b7f8ae5..6ce3f6e0cd6 100644 --- a/source/blender/gpu/shaders/gpu_shader_material.glsl +++ b/source/blender/gpu/shaders/gpu_shader_material.glsl @@ -525,6 +525,25 @@ void curves_rgb( outcol = mix(col, outcol, fac); } +void curves_rgb_opti( + float fac, vec4 col, sampler1DArray curvemap, float layer, + vec4 range, vec4 ext_a, + out vec4 outcol) +{ + vec4 co = vec4(RANGE_RESCALE(col.rgb, ext_a.x, range.a), layer); + vec3 samp; + samp.r = texture(curvemap, co.xw).a; + samp.g = texture(curvemap, co.yw).a; + samp.b = texture(curvemap, co.zw).a; + + outcol.r = curve_extrapolate(co.x, samp.r, ext_a); + outcol.g = curve_extrapolate(co.y, samp.g, ext_a); + outcol.b = curve_extrapolate(co.z, samp.b, ext_a); + outcol.a = col.a; + + outcol = mix(col, outcol, fac); +} + void set_value(float val, out float outval) { outval = val; diff --git a/source/blender/nodes/shader/nodes/node_shader_curves.c b/source/blender/nodes/shader/nodes/node_shader_curves.c index f57d1bfbc9e..2b4c3581fc0 100644 --- a/source/blender/nodes/shader/nodes/node_shader_curves.c +++ b/source/blender/nodes/shader/nodes/node_shader_curves.c @@ -115,6 +115,7 @@ static int gpu_shader_curve_rgb(GPUMaterial *mat, bNode *node, bNodeExecData *UN { float *array, layer; int size; + bool use_opti = true; CurveMapping *cumap = node->storage; @@ -139,15 +140,38 @@ static int gpu_shader_curve_rgb(GPUMaterial *mat, bNode *node, bNodeExecData *UN ext_rgba[a][1] = 0.0f; ext_rgba[a][3] = 0.0f; } + + /* Check if rgb comps are just linear. */ + if (a < 3) { + if (range_rgba[a] != 1.0f || + ext_rgba[a][1] != 1.0f || + ext_rgba[a][2] != 1.0f || + cm->totpoint != 2 || + cm->curve[0].x != 0.0f || + cm->curve[0].y != 0.0f || + cm->curve[1].x != 1.0f || + cm->curve[1].y != 1.0f) + { + use_opti = false; + } + } } - return GPU_stack_link(mat, node, "curves_rgb", in, out, tex, - GPU_constant(&layer), - GPU_uniform(range_rgba), - GPU_uniform(ext_rgba[0]), - GPU_uniform(ext_rgba[1]), - GPU_uniform(ext_rgba[2]), - GPU_uniform(ext_rgba[3])); + if (use_opti) { + return GPU_stack_link(mat, node, "curves_rgb_opti", in, out, tex, + GPU_constant(&layer), + GPU_uniform(range_rgba), + GPU_uniform(ext_rgba[3])); + } + else { + return GPU_stack_link(mat, node, "curves_rgb", in, out, tex, + GPU_constant(&layer), + GPU_uniform(range_rgba), + GPU_uniform(ext_rgba[0]), + GPU_uniform(ext_rgba[1]), + GPU_uniform(ext_rgba[2]), + GPU_uniform(ext_rgba[3])); + } } void register_node_type_sh_curve_rgb(void) |