Properly handle vertex color color space for Cycles GLSL

A bit tricky, need to pass additional information about what the attribute
is and how to deal with it.

BI path stays unchanged, just to make things simplier for now.

Fixes T48555: Cycles GLSL- Incorrect Vertex Color results from Attribute node
This commit is contained in:
2016-05-31 14:39:49 +02:00
parent 19cfc84328
commit e9c8917e10
12 changed files with 95 additions and 8 deletions

View File

@@ -14,6 +14,58 @@ varying vec3 varnormal;
varying float gl_ClipDistance[6];
#endif
float srgb_to_linearrgb(float c)
{
if (c < 0.04045)
return (c < 0.0) ? 0.0 : c * (1.0 / 12.92);
else
return pow((c + 0.055) * (1.0 / 1.055), 2.4);
}
void srgb_to_linearrgb(vec3 col_from, out vec3 col_to)
{
col_to.r = srgb_to_linearrgb(col_from.r);
col_to.g = srgb_to_linearrgb(col_from.g);
col_to.b = srgb_to_linearrgb(col_from.b);
}
void srgb_to_linearrgb(vec4 col_from, out vec4 col_to)
{
col_to.r = srgb_to_linearrgb(col_from.r);
col_to.g = srgb_to_linearrgb(col_from.g);
col_to.b = srgb_to_linearrgb(col_from.b);
col_to.a = col_from.a;
}
bool is_srgb(int info)
{
#ifdef USE_NEW_SHADING
return (info == 1)? true: false;
#else
return false;
#endif
}
void set_var_from_attr(vec3 attr, int info, out vec3 var)
{
if (is_srgb(info)) {
srgb_to_linearrgb(attr, var);
}
else {
var = attr;
}
}
void set_var_from_attr(vec4 attr, int info, out vec4 var)
{
if (is_srgb(info)) {
srgb_to_linearrgb(attr, var);
}
else {
var = attr;
}
}
void main()
{
#ifndef USE_OPENSUBDIV