@@ -2,20 +2,20 @@ import { ShaderChunk } from 'three';
22
33const CSMShader = {
44 lights_fragment_begin : /* glsl */ `
5- GeometricContext geometry;
5+ vec3 geometryPosition = - vViewPosition;
6+ vec3 geometryNormal = normal;
7+ vec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );
68
7- geometry.position = - vViewPosition;
8- geometry.normal = normal;
9- geometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );
9+ vec3 geometryClearcoatNormal;
1010
1111#ifdef USE_CLEARCOAT
1212
13- geometry.clearcoatNormal = clearcoatNormal;
13+ geometryClearcoatNormal = clearcoatNormal;
1414
1515#endif
1616
1717#ifdef USE_IRIDESCENCE
18- float dotNVi = saturate( dot( normal, geometry.viewDir ) );
18+ float dotNVi = saturate( dot( normal, geometryViewDir ) );
1919 if ( material.iridescenceThickness == 0.0 ) {
2020 material.iridescence = 0.0;
2121 } else {
@@ -42,14 +42,14 @@ IncidentLight directLight;
4242
4343 pointLight = pointLights[ i ];
4444
45- getPointLightInfo( pointLight, geometry , directLight );
45+ getPointLightInfo( pointLight, geometryPosition , directLight );
4646
4747 #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )
4848 pointLightShadow = pointLightShadows[ i ];
4949 directLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;
5050 #endif
5151
52- RE_Direct( directLight, geometry , material, reflectedLight );
52+ RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal , material, reflectedLight );
5353
5454 }
5555 #pragma unroll_loop_end
@@ -72,7 +72,7 @@ IncidentLight directLight;
7272
7373 spotLight = spotLights[ i ];
7474
75- getSpotLightInfo( spotLight, geometry , directLight );
75+ getSpotLightInfo( spotLight, geometryPosition , directLight );
7676
7777 // spot lights are ordered [shadows with maps, shadows without maps, maps without shadows, none]
7878 #if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )
@@ -96,7 +96,7 @@ IncidentLight directLight;
9696
9797 #endif
9898
99- RE_Direct( directLight, geometry , material, reflectedLight );
99+ RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal , material, reflectedLight );
100100
101101 }
102102 #pragma unroll_loop_end
@@ -123,7 +123,7 @@ IncidentLight directLight;
123123 for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
124124
125125 directionalLight = directionalLights[ i ];
126- getDirectionalLightInfo( directionalLight, geometry, directLight );
126+ getDirectionalLightInfo( directionalLight, directLight );
127127
128128 #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
129129 // NOTE: Depth gets larger away from the camera.
@@ -147,7 +147,7 @@ IncidentLight directLight;
147147 directLight.color = mix( prevColor, directLight.color, shouldFadeLastCascade ? ratio : 1.0 );
148148
149149 ReflectedLight prevLight = reflectedLight;
150- RE_Direct( directLight, geometry , material, reflectedLight );
150+ RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal , material, reflectedLight );
151151
152152 bool shouldBlend = UNROLLED_LOOP_INDEX != CSM_CASCADES - 1 || UNROLLED_LOOP_INDEX == CSM_CASCADES - 1 && linearDepth < cascadeCenter;
153153 float blendRatio = shouldBlend ? ratio : 1.0;
@@ -168,14 +168,14 @@ IncidentLight directLight;
168168 for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
169169
170170 directionalLight = directionalLights[ i ];
171- getDirectionalLightInfo( directionalLight, geometry, directLight );
171+ getDirectionalLightInfo( directionalLight, directLight );
172172
173173 #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
174174
175175 directionalLightShadow = directionalLightShadows[ i ];
176176 if(linearDepth >= CSM_cascades[UNROLLED_LOOP_INDEX].x && linearDepth < CSM_cascades[UNROLLED_LOOP_INDEX].y) directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
177177
178- if(linearDepth >= CSM_cascades[UNROLLED_LOOP_INDEX].x && (linearDepth < CSM_cascades[UNROLLED_LOOP_INDEX].y || UNROLLED_LOOP_INDEX == CSM_CASCADES - 1)) RE_Direct( directLight, geometry , material, reflectedLight );
178+ if(linearDepth >= CSM_cascades[UNROLLED_LOOP_INDEX].x && (linearDepth < CSM_cascades[UNROLLED_LOOP_INDEX].y || UNROLLED_LOOP_INDEX == CSM_CASCADES - 1)) RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal , material, reflectedLight );
179179
180180 #endif
181181
@@ -192,9 +192,9 @@ IncidentLight directLight;
192192
193193 directionalLight = directionalLights[ i ];
194194
195- getDirectionalLightInfo( directionalLight, geometry, directLight );
195+ getDirectionalLightInfo( directionalLight, directLight );
196196
197- RE_Direct( directLight, geometry , material, reflectedLight );
197+ RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal , material, reflectedLight );
198198
199199 }
200200 #pragma unroll_loop_end
@@ -216,14 +216,14 @@ IncidentLight directLight;
216216
217217 directionalLight = directionalLights[ i ];
218218
219- getDirectionalLightInfo( directionalLight, geometry, directLight );
219+ getDirectionalLightInfo( directionalLight, directLight );
220220
221221 #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
222222 directionalLightShadow = directionalLightShadows[ i ];
223223 directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
224224 #endif
225225
226- RE_Direct( directLight, geometry , material, reflectedLight );
226+ RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal , material, reflectedLight );
227227
228228 }
229229 #pragma unroll_loop_end
@@ -238,7 +238,7 @@ IncidentLight directLight;
238238 for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {
239239
240240 rectAreaLight = rectAreaLights[ i ];
241- RE_Direct_RectArea( rectAreaLight, geometry , material, reflectedLight );
241+ RE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal , material, reflectedLight );
242242
243243 }
244244 #pragma unroll_loop_end
@@ -253,7 +253,7 @@ IncidentLight directLight;
253253
254254 #if defined( USE_LIGHT_PROBES )
255255
256- irradiance += getLightProbeIrradiance( lightProbe, geometry.normal );
256+ irradiance += getLightProbeIrradiance( lightProbe, geometryNormal );
257257
258258 #endif
259259
@@ -262,7 +262,7 @@ IncidentLight directLight;
262262 #pragma unroll_loop_start
263263 for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {
264264
265- irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry.normal );
265+ irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );
266266
267267 }
268268 #pragma unroll_loop_end
0 commit comments