@@ -62,7 +62,7 @@ IncidentLight directLight;
62
62
vec4 spotColor;
63
63
vec3 spotLightCoord;
64
64
bool inSpotLightMap;
65
-
65
+
66
66
#if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0
67
67
SpotLightShadow spotLightShadow;
68
68
#endif
@@ -112,76 +112,81 @@ IncidentLight directLight;
112
112
#endif
113
113
114
114
#if defined( USE_SHADOWMAP ) && defined( CSM_FADE )
115
- vec2 cascade;
116
- float cascadeCenter;
117
- float closestEdge;
118
- float margin;
119
- float csmx;
120
- float csmy;
115
+ vec2 cascade;
116
+ float cascadeCenter;
117
+ float closestEdge;
118
+ float margin;
119
+ float csmx;
120
+ float csmy;
121
121
122
- #pragma unroll_loop_start
123
- for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
122
+ #pragma unroll_loop_start
123
+ for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
124
124
125
- directionalLight = directionalLights[ i ];
126
- getDirectionalLightInfo( directionalLight, directLight );
125
+ directionalLight = directionalLights[ i ];
126
+ getDirectionalLightInfo( directionalLight, directLight );
127
127
128
- #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
129
- // NOTE: Depth gets larger away from the camera.
130
- // cascade.x is closer, cascade.y is further
131
- cascade = CSM_cascades[ i ];
132
- cascadeCenter = ( cascade.x + cascade.y ) / 2.0;
133
- closestEdge = linearDepth < cascadeCenter ? cascade.x : cascade.y;
134
- margin = 0.25 * pow( closestEdge, 2.0 );
135
- csmx = cascade.x - margin / 2.0;
136
- csmy = cascade.y + margin / 2.0;
137
- if( linearDepth >= csmx && ( linearDepth < csmy || UNROLLED_LOOP_INDEX == CSM_CASCADES - 1 ) ) {
138
-
139
- float dist = min( linearDepth - csmx, csmy - linearDepth );
140
- float ratio = clamp( dist / margin, 0.0, 1.0 );
141
-
142
- vec3 prevColor = directLight.color;
143
- directionalLightShadow = directionalLightShadows[ i ];
144
- directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
128
+ #if ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
129
+ // NOTE: Depth gets larger away from the camera.
130
+ // cascade.x is closer, cascade.y is further
131
+ cascade = CSM_cascades[ i ];
132
+ cascadeCenter = ( cascade.x + cascade.y ) / 2.0;
133
+ closestEdge = linearDepth < cascadeCenter ? cascade.x : cascade.y;
134
+ margin = 0.25 * pow( closestEdge, 2.0 );
135
+ csmx = cascade.x - margin / 2.0;
136
+ csmy = cascade.y + margin / 2.0;
137
+ if( linearDepth >= csmx && ( linearDepth < csmy || UNROLLED_LOOP_INDEX == CSM_CASCADES - 1 ) ) {
145
138
146
- bool shouldFadeLastCascade = UNROLLED_LOOP_INDEX == CSM_CASCADES - 1 && linearDepth > cascadeCenter ;
147
- directLight.color = mix( prevColor, directLight.color, shouldFadeLastCascade ? ratio : 1.0 );
139
+ float dist = min( linearDepth - csmx, csmy - linearDepth ) ;
140
+ float ratio = clamp( dist / margin, 0.0, 1.0 );
148
141
149
- ReflectedLight prevLight = reflectedLight;
150
- RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
142
+ vec3 prevColor = directLight.color;
143
+ directionalLightShadow = directionalLightShadows[ i ];
144
+ directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
151
145
152
- bool shouldBlend = UNROLLED_LOOP_INDEX != CSM_CASCADES - 1 || UNROLLED_LOOP_INDEX == CSM_CASCADES - 1 && linearDepth < cascadeCenter;
153
- float blendRatio = shouldBlend ? ratio : 1.0;
146
+ bool shouldFadeLastCascade = UNROLLED_LOOP_INDEX == CSM_CASCADES - 1 && linearDepth > cascadeCenter;
147
+ directLight.color = mix( prevColor, directLight.color, shouldFadeLastCascade ? ratio : 1.0 ) ;
154
148
155
- reflectedLight.directDiffuse = mix( prevLight.directDiffuse, reflectedLight.directDiffuse, blendRatio );
156
- reflectedLight.directSpecular = mix( prevLight.directSpecular, reflectedLight.directSpecular, blendRatio );
157
- reflectedLight.indirectDiffuse = mix( prevLight.indirectDiffuse, reflectedLight.indirectDiffuse, blendRatio );
158
- reflectedLight.indirectSpecular = mix( prevLight.indirectSpecular, reflectedLight.indirectSpecular, blendRatio );
149
+ ReflectedLight prevLight = reflectedLight;
150
+ RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
159
151
160
- }
161
- #endif
152
+ bool shouldBlend = UNROLLED_LOOP_INDEX != CSM_CASCADES - 1 || UNROLLED_LOOP_INDEX == CSM_CASCADES - 1 && linearDepth < cascadeCenter;
153
+ float blendRatio = shouldBlend ? ratio : 1.0;
162
154
163
- }
164
- #pragma unroll_loop_end
165
- #else
155
+ reflectedLight.directDiffuse = mix( prevLight.directDiffuse, reflectedLight.directDiffuse, blendRatio );
156
+ reflectedLight.directSpecular = mix( prevLight.directSpecular, reflectedLight.directSpecular, blendRatio );
157
+ reflectedLight.indirectDiffuse = mix( prevLight.indirectDiffuse, reflectedLight.indirectDiffuse, blendRatio );
158
+ reflectedLight.indirectSpecular = mix( prevLight.indirectSpecular, reflectedLight.indirectSpecular, blendRatio );
159
+
160
+ }
161
+ #endif
162
+
163
+ }
164
+ #pragma unroll_loop_end
165
+ #elif defined (USE_SHADOWMAP)
166
166
167
167
#pragma unroll_loop_start
168
168
for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {
169
169
170
170
directionalLight = directionalLights[ i ];
171
171
getDirectionalLightInfo( directionalLight, directLight );
172
172
173
- #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
173
+ #if ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
174
174
175
- directionalLightShadow = directionalLightShadows[ i ];
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;
175
+ directionalLightShadow = directionalLightShadows[ i ];
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, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, 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
182
182
}
183
183
#pragma unroll_loop_end
184
184
185
+ #elif ( NUM_DIR_LIGHT_SHADOWS > 0 )
186
+ // note: no loop here - all CSM lights are in fact one light only
187
+ getDirectionalLightInfo( directionalLights[0], directLight );
188
+ RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
189
+
185
190
#endif
186
191
187
192
#if ( NUM_DIR_LIGHTS > NUM_DIR_LIGHT_SHADOWS)
0 commit comments