Fix #136303: Normalize the normals on the Ambient Occlusion node

This commit simply normalizes the normals of the Ambient occlusion
node before computing the output to avoid odd behaviour with
unnormalized normals.

Pull Request: https://projects.blender.org/blender/blender/pulls/136315
This commit is contained in:
Alaska
2025-03-27 02:58:19 +01:00
committed by Alaska
parent fd2a187355
commit 2e829ca4cf
3 changed files with 7 additions and 4 deletions

View File

@@ -15,13 +15,15 @@ shader node_ambient_occlusion(color ColorIn = color(1.0, 1.0, 1.0),
{
int global_radius = (Distance == 0.0 && !isconnected(Distance));
normal normalized_normal = normalize(Normal);
/* Abuse texture call with special @ao token. */
AO = texture("@ao",
samples,
Distance,
Normal[0],
Normal[1],
Normal[2],
normalized_normal[0],
normalized_normal[1],
normalized_normal[2],
inside,
"sblur",
only_local,

View File

@@ -124,6 +124,7 @@ ccl_device_noinline
{
float dist = stack_load_float_default(stack, dist_offset, node.w);
float3 normal = stack_valid(normal_offset) ? stack_load_float3(stack, normal_offset) : sd->N;
normal = safe_normalize(normal);
# ifdef __KERNEL_OPTIX__
ao = optixDirectCall<float>(0, kg, state, sd, normal, dist, samples, flags);

View File

@@ -10,6 +10,6 @@ void node_ambient_occlusion(vec4 color,
out vec4 result_color,
out float result_ao)
{
result_ao = ambient_occlusion_eval(normal, dist, inverted, sample_count);
result_ao = ambient_occlusion_eval(safe_normalize(normal), dist, inverted, sample_count);
result_color = result_ao * color;
}