forked from bartvdbraak/blender
Fix #36064: cycles direct/indirect light passes with materials that have zero
RGB color components gave non-grey results when you might no expect it. What happens is that some of the color channels are zero in the direct light pass because their channel is zero in the color pass. The direct light pass is defined as lighting divided by the color pass, and we can't divide by zero. We do a division after all samples are added together to ensure that multiplication in the compositor gives the exact combined pass even with antialiasing, DoF, .. Found a simple tweak here, instead of setting such channels to zero it will set it to the average of other non-zero color channels, which makes the results look like the expected grey.
This commit is contained in:
parent
b2b6d56443
commit
3d847ed6e6
@ -223,7 +223,7 @@ bool RenderBuffers::get_pass_rect(PassType type, float exposure, int sample, int
|
||||
float3 f = make_float3(in[0], in[1], in[2]);
|
||||
float3 f_divide = make_float3(in_divide[0], in_divide[1], in_divide[2]);
|
||||
|
||||
f = safe_divide_color(f*exposure, f_divide);
|
||||
f = safe_divide_even_color(f*exposure, f_divide);
|
||||
|
||||
pixels[0] = f.x;
|
||||
pixels[1] = f.y;
|
||||
|
@ -1100,6 +1100,42 @@ __device_inline float3 safe_divide_color(float3 a, float3 b)
|
||||
return make_float3(x, y, z);
|
||||
}
|
||||
|
||||
__device_inline float3 safe_divide_even_color(float3 a, float3 b)
|
||||
{
|
||||
float x, y, z;
|
||||
|
||||
x = (b.x != 0.0f)? a.x/b.x: 0.0f;
|
||||
y = (b.y != 0.0f)? a.y/b.y: 0.0f;
|
||||
z = (b.z != 0.0f)? a.z/b.z: 0.0f;
|
||||
|
||||
/* try to get grey even if b is zero */
|
||||
if(b.x == 0.0f) {
|
||||
if(b.y == 0.0f) {
|
||||
x = z;
|
||||
y = z;
|
||||
}
|
||||
else if(b.z == 0.0f) {
|
||||
x = y;
|
||||
z = y;
|
||||
}
|
||||
else
|
||||
x = 0.5f*(y + z);
|
||||
}
|
||||
else if(b.y == 0.0f) {
|
||||
if(b.z == 0.0f) {
|
||||
y = x;
|
||||
z = x;
|
||||
}
|
||||
else
|
||||
y = 0.5f*(x + z);
|
||||
}
|
||||
else if(b.z == 0.0f) {
|
||||
z = 0.5f*(x + y);
|
||||
}
|
||||
|
||||
return make_float3(x, y, z);
|
||||
}
|
||||
|
||||
/* Rotation of point around axis and angle */
|
||||
|
||||
__device_inline float3 rotate_around_axis(float3 p, float3 axis, float angle)
|
||||
|
Loading…
Reference in New Issue
Block a user