Shading: Retain alpha in Mix Color shader code
The Mix Color shader node does not retain the alpha channel of the first input in both the Linear Light and Soft Light modes, while it is retain for other modes. Further, result clamping also ignores the alpha due to using the vector clamp function, which introduces implicit conversion that removes the alpha. This does not matter for EEVEE because it does nothing with the alpha channel. But the code will now be shared with the compositor, which does care about the alpha channel. So adjust the code accordingly to retain the alpha in those cases. Pull Request: https://projects.blender.org/blender/blender/pulls/135632
This commit is contained in:
@@ -467,6 +467,7 @@ void node_mix_soft(float fac,
|
||||
vec4 one = vec4(1.0);
|
||||
vec4 scr = one - (one - col2) * (one - col1);
|
||||
outcol = facm * col1 + fac * ((one - col1) * col2 * col1 + col1 * scr);
|
||||
outcol.a = col1.a;
|
||||
}
|
||||
|
||||
void node_mix_linear(float fac,
|
||||
@@ -483,6 +484,7 @@ void node_mix_linear(float fac,
|
||||
{
|
||||
|
||||
outcol = col1 + fac * (2.0 * (col2 - vec4(0.5)));
|
||||
outcol.a = col1.a;
|
||||
}
|
||||
|
||||
void node_mix_float(float fac,
|
||||
@@ -547,6 +549,11 @@ void node_mix_rgba(float fac,
|
||||
outcol = mix(col1, col2, fac);
|
||||
}
|
||||
|
||||
void node_mix_clamp_color(vec4 col, vec4 min, vec4 max, out vec4 out_col)
|
||||
{
|
||||
out_col = clamp(col, min, max);
|
||||
}
|
||||
|
||||
void node_mix_clamp_vector(vec3 vec, vec3 min, vec3 max, out vec3 outvec)
|
||||
{
|
||||
outvec = clamp(vec, min, max);
|
||||
|
||||
@@ -395,10 +395,10 @@ static int gpu_shader_mix(GPUMaterial *mat,
|
||||
int ret = GPU_stack_link(mat, node, name, in, out);
|
||||
|
||||
if (ret && is_color_mode && storage.clamp_result) {
|
||||
const float min[3] = {0.0f, 0.0f, 0.0f};
|
||||
const float max[3] = {1.0f, 1.0f, 1.0f};
|
||||
const float min[4] = {0.0f, 0.0f, 0.0f, 0.0f};
|
||||
const float max[4] = {1.0f, 1.0f, 1.0f, 1.0f};
|
||||
GPU_link(mat,
|
||||
"node_mix_clamp_vector",
|
||||
"node_mix_clamp_color",
|
||||
out[2].link,
|
||||
GPU_constant(min),
|
||||
GPU_constant(max),
|
||||
|
||||
Reference in New Issue
Block a user