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.
This commit is contained in:
Clément Foucault 2019-03-22 03:53:13 +01:00
parent 875b50f94f
commit c49a70bcd1
2 changed files with 50 additions and 7 deletions

View File

@ -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;

View File

@ -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)