Skip to content
Merged
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
10 changes: 10 additions & 0 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1781,6 +1781,16 @@ function WebGLRenderer( parameters ) {

}

if ( material.isMeshPhongMaterial ||
material.isMeshLambertMaterial ||
material.isMeshBasicMaterial ||
material.isMeshStandardMaterial ||
material.isShaderMaterial ) {

p_uniforms.setValue( _gl, 'isOrthographic', camera.isOrthographicCamera === true );

}

if ( material.isMeshPhongMaterial ||
material.isMeshLambertMaterial ||
material.isMeshBasicMaterial ||
Expand Down
16 changes: 13 additions & 3 deletions src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,28 @@ export default /* glsl */`

#ifdef ENV_WORLDPOS

vec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );
vec3 cameraToFrag;

if ( isOrthographic ) {

cameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );

} else {

cameraToFrag = normalize( vWorldPosition - cameraPosition );

}

// Transforming Normal Vectors with the Inverse Transformation
vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );

#ifdef ENVMAP_MODE_REFLECTION

vec3 reflectVec = reflect( cameraToVertex, worldNormal );
vec3 reflectVec = reflect( cameraToFrag, worldNormal );

#else

vec3 reflectVec = refract( cameraToVertex, worldNormal, refractionRatio );
vec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );

#endif

Expand Down
12 changes: 11 additions & 1 deletion src/renderers/shaders/ShaderChunk/envmap_vertex.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ export default /* glsl */`

#else

vec3 cameraToVertex = normalize( worldPosition.xyz - cameraPosition );
vec3 cameraToVertex;

if ( isOrthographic ) {

cameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );

} else {

cameraToVertex = normalize( worldPosition.xyz - cameraPosition );

}

vec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ GeometricContext geometry;

geometry.position = - vViewPosition;
geometry.normal = normal;
geometry.viewDir = normalize( vViewPosition );
geometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );

#ifdef CLEARCOAT

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ vec3 diffuse = vec3( 1.0 );
GeometricContext geometry;
geometry.position = mvPosition.xyz;
geometry.normal = normalize( transformedNormal );
geometry.viewDir = normalize( -mvPosition.xyz );
geometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( -mvPosition.xyz );

GeometricContext backGeometry;
backGeometry.position = geometry.position;
Expand Down
2 changes: 2 additions & 0 deletions src/renderers/webgl/WebGLProgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters
'uniform mat4 viewMatrix;',
'uniform mat3 normalMatrix;',
'uniform vec3 cameraPosition;',
'uniform bool isOrthographic;',

'#ifdef USE_INSTANCING',

Expand Down Expand Up @@ -617,6 +618,7 @@ function WebGLProgram( renderer, extensions, code, material, shader, parameters

'uniform mat4 viewMatrix;',
'uniform vec3 cameraPosition;',
'uniform bool isOrthographic;',

( parameters.toneMapping !== NoToneMapping ) ? '#define TONE_MAPPING' : '',
( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
Expand Down