@@ -2,20 +2,20 @@ import { ShaderChunk } from 'three';
2
2
3
3
const CSMShader = {
4
4
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 );
6
8
7
- geometry.position = - vViewPosition;
8
- geometry.normal = normal;
9
- geometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );
9
+ vec3 geometryClearcoatNormal;
10
10
11
11
#ifdef USE_CLEARCOAT
12
12
13
- geometry.clearcoatNormal = clearcoatNormal;
13
+ geometryClearcoatNormal = clearcoatNormal;
14
14
15
15
#endif
16
16
17
17
#ifdef USE_IRIDESCENCE
18
- float dotNVi = saturate( dot( normal, geometry.viewDir ) );
18
+ float dotNVi = saturate( dot( normal, geometryViewDir ) );
19
19
if ( material.iridescenceThickness == 0.0 ) {
20
20
material.iridescence = 0.0;
21
21
} else {
@@ -42,14 +42,14 @@ IncidentLight directLight;
42
42
43
43
pointLight = pointLights[ i ];
44
44
45
- getPointLightInfo( pointLight, geometry , directLight );
45
+ getPointLightInfo( pointLight, geometryPosition , directLight );
46
46
47
47
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )
48
48
pointLightShadow = pointLightShadows[ i ];
49
49
directLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;
50
50
#endif
51
51
52
- RE_Direct( directLight, geometry , material, reflectedLight );
52
+ RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal , material, reflectedLight );
53
53
54
54
}
55
55
#pragma unroll_loop_end
@@ -72,7 +72,7 @@ IncidentLight directLight;
72
72
73
73
spotLight = spotLights[ i ];
74
74
75
- getSpotLightInfo( spotLight, geometry , directLight );
75
+ getSpotLightInfo( spotLight, geometryPosition , directLight );
76
76
77
77
// spot lights are ordered [shadows with maps, shadows without maps, maps without shadows, none]
78
78
#if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )
@@ -96,7 +96,7 @@ IncidentLight directLight;
96
96
97
97
#endif
98
98
99
- RE_Direct( directLight, geometry , material, reflectedLight );
99
+ RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal , material, reflectedLight );
100
100
101
101
}
102
102
#pragma unroll_loop_end
@@ -123,7 +123,7 @@ IncidentLight directLight;
123
123
for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
124
124
125
125
directionalLight = directionalLights[ i ];
126
- getDirectionalLightInfo( directionalLight, geometry, directLight );
126
+ getDirectionalLightInfo( directionalLight, directLight );
127
127
128
128
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
129
129
// NOTE: Depth gets larger away from the camera.
@@ -147,7 +147,7 @@ IncidentLight directLight;
147
147
directLight.color = mix( prevColor, directLight.color, shouldFadeLastCascade ? ratio : 1.0 );
148
148
149
149
ReflectedLight prevLight = reflectedLight;
150
- RE_Direct( directLight, geometry , material, reflectedLight );
150
+ RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal , material, reflectedLight );
151
151
152
152
bool shouldBlend = UNROLLED_LOOP_INDEX != CSM_CASCADES - 1 || UNROLLED_LOOP_INDEX == CSM_CASCADES - 1 && linearDepth < cascadeCenter;
153
153
float blendRatio = shouldBlend ? ratio : 1.0;
@@ -168,14 +168,14 @@ IncidentLight directLight;
168
168
for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
169
169
170
170
directionalLight = directionalLights[ i ];
171
- getDirectionalLightInfo( directionalLight, geometry, directLight );
171
+ getDirectionalLightInfo( directionalLight, directLight );
172
172
173
173
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
174
174
175
175
directionalLightShadow = directionalLightShadows[ i ];
176
176
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;
177
177
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 );
179
179
180
180
#endif
181
181
@@ -192,9 +192,9 @@ IncidentLight directLight;
192
192
193
193
directionalLight = directionalLights[ i ];
194
194
195
- getDirectionalLightInfo( directionalLight, geometry, directLight );
195
+ getDirectionalLightInfo( directionalLight, directLight );
196
196
197
- RE_Direct( directLight, geometry , material, reflectedLight );
197
+ RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal , material, reflectedLight );
198
198
199
199
}
200
200
#pragma unroll_loop_end
@@ -216,14 +216,14 @@ IncidentLight directLight;
216
216
217
217
directionalLight = directionalLights[ i ];
218
218
219
- getDirectionalLightInfo( directionalLight, geometry, directLight );
219
+ getDirectionalLightInfo( directionalLight, directLight );
220
220
221
221
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
222
222
directionalLightShadow = directionalLightShadows[ i ];
223
223
directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
224
224
#endif
225
225
226
- RE_Direct( directLight, geometry , material, reflectedLight );
226
+ RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal , material, reflectedLight );
227
227
228
228
}
229
229
#pragma unroll_loop_end
@@ -238,7 +238,7 @@ IncidentLight directLight;
238
238
for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {
239
239
240
240
rectAreaLight = rectAreaLights[ i ];
241
- RE_Direct_RectArea( rectAreaLight, geometry , material, reflectedLight );
241
+ RE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal , material, reflectedLight );
242
242
243
243
}
244
244
#pragma unroll_loop_end
@@ -253,7 +253,7 @@ IncidentLight directLight;
253
253
254
254
#if defined( USE_LIGHT_PROBES )
255
255
256
- irradiance += getLightProbeIrradiance( lightProbe, geometry.normal );
256
+ irradiance += getLightProbeIrradiance( lightProbe, geometryNormal );
257
257
258
258
#endif
259
259
@@ -262,7 +262,7 @@ IncidentLight directLight;
262
262
#pragma unroll_loop_start
263
263
for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {
264
264
265
- irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry.normal );
265
+ irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );
266
266
267
267
}
268
268
#pragma unroll_loop_end
0 commit comments