Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build/three.cjs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions build/three.module.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/three.module.min.js

Large diffs are not rendered by default.

Binary file modified examples/screenshots/webgl_animation_keyframes.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_loader_gltf_compressed.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_loader_gltf_iridescence.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_random_uv.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions src/renderers/shaders/ShaderChunk/aomap_fragment.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ export default /* glsl */`
// reads channel R, compatible with a combined OcclusionRoughnessMetallic (RGB) texture
float ambientOcclusion = ( texture2D( aoMap, vAoMapUv ).r - 1.0 ) * aoMapIntensity + 1.0;

reflectedLight.indirectDiffuse *= ambientOcclusion;
// Use multi-bounce AO for diffuse to add energy back
vec3 aoFactor = computeMultiBounceAO( ambientOcclusion, material.diffuseColor );
reflectedLight.indirectDiffuse *= aoFactor;

#if defined( USE_CLEARCOAT )
clearcoatSpecularIndirect *= ambientOcclusion;
Expand All @@ -18,7 +20,8 @@ export default /* glsl */`

float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );

reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );
// Use improved specular occlusion with horizon fading
reflectedLight.indirectSpecular *= computeSpecularOcclusionImproved( dotNV, ambientOcclusion, material.roughness );

#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,5 +551,36 @@ float computeSpecularOcclusion( const in float dotNV, const in float ambientOccl

return saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );

}

// Improved specular occlusion with horizon fading
// Based on "Practical Real-Time Strategies for Accurate Indirect Occlusion"
float computeSpecularOcclusionImproved( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {

// Start with the base specular occlusion formula
float baseOcclusion = computeSpecularOcclusion( dotNV, ambientOcclusion, roughness );

// Horizon fade term - slightly reduces AO influence at extreme grazing angles only
float horizonFade = saturate( 1.0 - pow( 1.0 - dotNV, 3.0 ) );

// Blend towards less occlusion at grazing angles, but keep most of the effect
return mix( baseOcclusion, 1.0, ( 1.0 - horizonFade ) * 0.3 );

}

// Multi-bounce ambient occlusion approximation
// Adds energy back that would bounce in occluded areas
vec3 computeMultiBounceAO( const in float ambientOcclusion, const in vec3 albedo ) {

vec3 a = 2.0 * albedo - 0.33;
vec3 b = -4.8 * albedo + 0.64;
vec3 c = 2.53 * albedo + 0.69;

float x = ambientOcclusion;
vec3 multiBounce = ( ( x * a + b ) * x + c ) * x;

// Blend between simple AO and multi-bounce (50/50) to keep it conservative
return mix( vec3( x ), max( vec3( x ), multiBounce ), 0.5 );

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would love for this 50% to be tweak-able uniform. or the whole computeSpecularOcclusionImproved to be a glsl fragment in-off itself, so it could be dynamically disabled, similar to how Tone-Mapping is a dynamically included or excluded glsl fragment.


}
`;