Fix #124621: EEVEE closure reservoir sampling not considering color weight
color was not taken into consideration when picking a closure using reservoir sampling, giving closures with dark color much higher weights than they should have. This fix multiplies the weight by the average color when picking the closure, similar as what has been done in principled BSDF. Pull Request: https://projects.blender.org/blender/blender/pulls/124730
This commit is contained in:
committed by
Weizhen Huang
parent
4f46493eae
commit
3fcd80db68
@@ -103,10 +103,13 @@ void closure_select(inout ClosureUndetermined destination,
|
||||
inout float random,
|
||||
ClosureUndetermined candidate)
|
||||
{
|
||||
if (closure_select_check(candidate.weight, destination.weight, random)) {
|
||||
float tmp = destination.weight;
|
||||
float candidate_color_weight = reduce_add(candidate.color) / 3.0;
|
||||
if (closure_select_check(candidate.weight * candidate_color_weight, destination.weight, random))
|
||||
{
|
||||
float total_weight = destination.weight;
|
||||
destination = candidate;
|
||||
destination.weight = tmp;
|
||||
destination.color /= candidate_color_weight;
|
||||
destination.weight = total_weight;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -209,10 +209,8 @@ void node_bsdf_principled(vec4 base_color,
|
||||
reflection_data.N = N;
|
||||
reflection_data.roughness = roughness;
|
||||
reflection_data.color = (reflection_color + weight * reflectance) * coat_tint.rgb;
|
||||
|
||||
/* Adjust the weight of picking the closure. */
|
||||
reflection_data.weight = math_average(reflection_data.color);
|
||||
reflection_data.color *= safe_rcp(reflection_data.weight);
|
||||
/* `weight` is already applied in `color`. */
|
||||
reflection_data.weight = 1.0f;
|
||||
closure_eval(reflection_data);
|
||||
|
||||
/* Attenuate lower layers */
|
||||
@@ -229,10 +227,8 @@ void node_bsdf_principled(vec4 base_color,
|
||||
sss_data.color = (subsurface_weight * weight) * clamped_base_color.rgb * coat_tint.rgb;
|
||||
/* Add energy of the sheen layer until we have proper sheen BSDF. */
|
||||
sss_data.color += sheen_data_color;
|
||||
|
||||
/* Adjust the weight of picking the closure. */
|
||||
sss_data.weight = math_average(sss_data.color);
|
||||
sss_data.color *= safe_rcp(sss_data.weight);
|
||||
/* `weight` is already applied in `color`. */
|
||||
sss_data.weight = 1.0f;
|
||||
closure_eval(sss_data);
|
||||
|
||||
/* Attenuate lower layers */
|
||||
@@ -246,10 +242,8 @@ void node_bsdf_principled(vec4 base_color,
|
||||
diffuse_data.color = weight * base_color.rgb * coat_tint.rgb;
|
||||
/* Add energy of the sheen layer until we have proper sheen BSDF. */
|
||||
diffuse_data.color += sheen_data_color;
|
||||
|
||||
diffuse_data.weight = math_average(diffuse_data.color);
|
||||
diffuse_data.color *= safe_rcp(diffuse_data.weight);
|
||||
|
||||
/* `weight` is already applied in `color`. */
|
||||
diffuse_data.weight = 1.0f;
|
||||
closure_eval(diffuse_data);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user