diff options
-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) |