diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-05-02 16:36:09 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-05-02 17:45:08 +0300 |
commit | a2b05accea6e2879832ae4ac4465ca11d49622c5 (patch) | |
tree | 55f92258fd9e16d4081c480b7f6ece31d3cd9083 /source/blender/gpu | |
parent | 648de1be52d0d205c657a130f462882c4d54b296 (diff) |
Eevee: Fix vertex color being in srgb space.
Now they are properly converted to Linear space before interpolation.
Since the only way to get vertex color in eevee and cycles is via the
attribute node with the CD_AUTO_FROM_NAME flag, we have to know at binding
time which type of buffer will be connected to this auto input.
We store this information inside the batch cache (together with the according
uniform name) and pass it as uniform to the shader which does conversion if
needed. The same shader can then be reused to draw another mesh with
different auto layers configuration.
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/intern/gpu_codegen.c | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c index d66aaf0a33d..7a4af0521bb 100644 --- a/source/blender/gpu/intern/gpu_codegen.c +++ b/source/blender/gpu/intern/gpu_codegen.c @@ -914,6 +914,12 @@ static char *code_generate_vertex(ListBase *nodes, const char *vert_code, bool u GPU_DATATYPE_STR[input->type], attrib_prefix_get(input->attribtype), hash); BLI_dynstr_appendf(ds, "#define att%d %s%u\n", input->attribid, attrib_prefix_get(input->attribtype), hash); + /* Auto attrib can be vertex color byte buffer. + * We need to know and convert them to linear space in VS. */ + if (!use_geom && input->attribtype == CD_AUTO_FROM_NAME) { + BLI_dynstr_appendf(ds, "uniform bool ba%u;\n", hash); + BLI_dynstr_appendf(ds, "#define att%d_is_srgb ba%u\n", input->attribid, hash); + } } BLI_dynstr_appendf(ds, "out %s var%d%s;\n", GPU_DATATYPE_STR[input->type], input->attribid, use_geom ? "g" : ""); @@ -923,8 +929,17 @@ static char *code_generate_vertex(ListBase *nodes, const char *vert_code, bool u BLI_dynstr_append(ds, "\n"); - BLI_dynstr_append(ds, "#define ATTRIB\n"); - BLI_dynstr_append(ds, "uniform mat3 NormalMatrix;\n"); + BLI_dynstr_append(ds, + "#define ATTRIB\n" + "uniform mat3 NormalMatrix;\n" + "vec3 srgb_to_linear_attrib(vec3 c) {\n" + "\tc = max(c, vec3(0.0));\n" + "\tvec3 c1 = c * (1.0 / 12.92);\n" + "\tvec3 c2 = pow((c + 0.055) * (1.0 / 1.055), vec3(2.4));\n" + "\treturn mix(c1, c2, step(vec3(0.04045), c));\n" + "}\n\n" + ); + BLI_dynstr_append(ds, "void pass_attrib(in vec3 position) {\n"); for (node = nodes->first; node; node = node->next) { @@ -942,6 +957,15 @@ static char *code_generate_vertex(ListBase *nodes, const char *vert_code, bool u BLI_dynstr_appendf(ds, "\tvar%d%s = OrcoTexCoFactors[0] + position * OrcoTexCoFactors[1];\n", input->attribid, use_geom ? "g" : ""); } + else if (input->attribtype == CD_MCOL) { + BLI_dynstr_appendf(ds, "\tvar%d%s = srgb_to_linear_attrib(att%d);\n", + input->attribid, use_geom ? "g" : "", input->attribid); + } + else if (input->attribtype == CD_AUTO_FROM_NAME) { + BLI_dynstr_appendf(ds, "\tvar%d%s = (att%d_is_srgb) ? srgb_to_linear_attrib(att%d) : att%d;\n", + input->attribid, use_geom ? "g" : "", + input->attribid, input->attribid, input->attribid); + } else { BLI_dynstr_appendf(ds, "\tvar%d%s = att%d;\n", input->attribid, use_geom ? "g" : "", input->attribid); |