未验证 提交 a5584f2a 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #17767 from sciecode/dev-ortho-light

ShaderChunks: Fix orthographic view direction
...@@ -1781,6 +1781,16 @@ function WebGLRenderer( parameters ) { ...@@ -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 || if ( material.isMeshPhongMaterial ||
material.isMeshLambertMaterial || material.isMeshLambertMaterial ||
material.isMeshBasicMaterial || material.isMeshBasicMaterial ||
......
...@@ -3,18 +3,28 @@ export default /* glsl */` ...@@ -3,18 +3,28 @@ export default /* glsl */`
#ifdef ENV_WORLDPOS #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 // Transforming Normal Vectors with the Inverse Transformation
vec3 worldNormal = inverseTransformDirection( normal, viewMatrix ); vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
#ifdef ENVMAP_MODE_REFLECTION #ifdef ENVMAP_MODE_REFLECTION
vec3 reflectVec = reflect( cameraToVertex, worldNormal ); vec3 reflectVec = reflect( cameraToFrag, worldNormal );
#else #else
vec3 reflectVec = refract( cameraToVertex, worldNormal, refractionRatio ); vec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );
#endif #endif
......
...@@ -7,7 +7,17 @@ export default /* glsl */` ...@@ -7,7 +7,17 @@ export default /* glsl */`
#else #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 ); vec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );
......
...@@ -18,7 +18,7 @@ GeometricContext geometry; ...@@ -18,7 +18,7 @@ GeometricContext geometry;
geometry.position = - vViewPosition; geometry.position = - vViewPosition;
geometry.normal = normal; geometry.normal = normal;
geometry.viewDir = normalize( vViewPosition ); geometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );
#ifdef CLEARCOAT #ifdef CLEARCOAT
......
...@@ -4,7 +4,7 @@ vec3 diffuse = vec3( 1.0 ); ...@@ -4,7 +4,7 @@ vec3 diffuse = vec3( 1.0 );
GeometricContext geometry; GeometricContext geometry;
geometry.position = mvPosition.xyz; geometry.position = mvPosition.xyz;
geometry.normal = normalize( transformedNormal ); geometry.normal = normalize( transformedNormal );
geometry.viewDir = normalize( -mvPosition.xyz ); geometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( -mvPosition.xyz );
GeometricContext backGeometry; GeometricContext backGeometry;
backGeometry.position = geometry.position; backGeometry.position = geometry.position;
......
...@@ -496,6 +496,7 @@ function WebGLProgram( renderer, extensions, cacheKey, material, shader, paramet ...@@ -496,6 +496,7 @@ function WebGLProgram( renderer, extensions, cacheKey, material, shader, paramet
'uniform mat4 viewMatrix;', 'uniform mat4 viewMatrix;',
'uniform mat3 normalMatrix;', 'uniform mat3 normalMatrix;',
'uniform vec3 cameraPosition;', 'uniform vec3 cameraPosition;',
'uniform bool isOrthographic;',
'#ifdef USE_INSTANCING', '#ifdef USE_INSTANCING',
...@@ -619,6 +620,7 @@ function WebGLProgram( renderer, extensions, cacheKey, material, shader, paramet ...@@ -619,6 +620,7 @@ function WebGLProgram( renderer, extensions, cacheKey, material, shader, paramet
'uniform mat4 viewMatrix;', 'uniform mat4 viewMatrix;',
'uniform vec3 cameraPosition;', 'uniform vec3 cameraPosition;',
'uniform bool isOrthographic;',
( parameters.toneMapping !== NoToneMapping ) ? '#define TONE_MAPPING' : '', ( 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 ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册