Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 5 additions & 4 deletions examples/jsm/helpers/LightProbeHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ class LightProbeHelper extends Mesh {

#define RECIPROCAL_PI 0.318309886

vec3 inverseTransformDirection( in vec3 normal, in mat4 matrix ) {

// matrix is assumed to be orthogonal
vec3 transformNormalByInverseViewMatrix( in vec3 normal, in mat4 viewMatrix ) {

return normalize( ( vec4( normal, 0.0 ) * matrix ).xyz );
// upper-left 3x3 of view matrix is assumed to be orthogonal

return normalize( ( vec4( normal, 0.0 ) * viewMatrix ).xyz );

}

Expand Down Expand Up @@ -101,7 +102,7 @@ class LightProbeHelper extends Mesh {

vec3 normal = normalize( vNormal );

vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
vec3 worldNormal = transformNormalByInverseViewMatrix( normal, viewMatrix );

vec3 irradiance = shGetIrradianceAt( worldNormal, sh );

Expand Down
7 changes: 3 additions & 4 deletions src/renderers/shaders/ShaderChunk/common.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,11 @@ vec3 transformDirection( in vec3 dir, in mat4 matrix ) {

}

vec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {
vec3 transformNormalByInverseViewMatrix( in vec3 normal, in mat4 viewMatrix ) {

// dir can be either a direction vector or a normal vector
// upper-left 3x3 of matrix is assumed to be orthogonal
// upper-left 3x3 of view matrix is assumed to be orthogonal

return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );
return normalize( ( vec4( normal, 0.0 ) * viewMatrix ).xyz );

}

Expand Down
2 changes: 1 addition & 1 deletion src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default /* glsl */`
}
// Transforming Normal Vectors with the Inverse Transformation
vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
vec3 worldNormal = transformNormalByInverseViewMatrix( normal, viewMatrix );
#ifdef ENVMAP_MODE_REFLECTION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default /* glsl */`
#ifdef ENVMAP_TYPE_CUBE_UV
vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
vec3 worldNormal = transformNormalByInverseViewMatrix( normal, viewMatrix );
vec4 envMapColor = textureCubeUV( envMap, envMapRotation * worldNormal, 1.0 );
Expand All @@ -28,7 +28,7 @@ export default /* glsl */`
// Mixing the reflection with the normal is more accurate and keeps rough objects from gathering light from behind their tangent plane.
reflectVec = normalize( mix( reflectVec, normal, pow4( roughness ) ) );
reflectVec = inverseTransformDirection( reflectVec, viewMatrix );
reflectVec = transformNormalByInverseViewMatrix( reflectVec, viewMatrix );
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Hmm... reflectVec. What to make of applying this method to this particular vector?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Maybe we add transformDirectionByInverseViewMatrix() for clarity? The code would be the same. It would be a small duplication of code, but more clear.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I added it.

vec4 envMapColor = textureCubeUV( envMap, envMapRotation * reflectVec, roughness );
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/shaders/ShaderChunk/envmap_vertex.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default /* glsl */`

}

vec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );
vec3 worldNormal = transformNormalByInverseViewMatrix( transformedNormal, viewMatrix );

#ifdef ENVMAP_MODE_REFLECTION

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ vec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {
vec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) {
vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
vec3 worldNormal = transformNormalByInverseViewMatrix( normal, viewMatrix );
vec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export default /* glsl */`
#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 )
// Offsetting the position used for querying occlusion along the world normal can be used to reduce shadow acne.
vec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );
vec3 shadowWorldNormal = transformNormalByInverseViewMatrix( transformedNormal, viewMatrix );
vec4 shadowWorldPosition;
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default /* glsl */`
vec3 pos = vWorldPosition;
vec3 v = normalize( cameraPosition - pos );
vec3 n = inverseTransformDirection( normal, viewMatrix );
vec3 n = transformNormalByInverseViewMatrix( normal, viewMatrix );
vec4 transmitted = getIBLVolumeRefraction(
n, v, material.roughness, material.diffuseContribution, material.specularColorBlended, material.specularF90,
Expand Down
Loading