Skip to content

Commit 167a8cb

Browse files
committed
LightShadow: Add intensity.
1 parent 001fd89 commit 167a8cb

File tree

14 files changed

+62
-14
lines changed

14 files changed

+62
-14
lines changed

docs/api/ar/lights/shadows/LightShadow.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ <h3>[property:Float bias]</h3>
4646

4747
<h3>[property:Integer blurSamples]</h3>
4848
<p>عدد العينات المستخدمة عند طمس خريطة ظل VSM.</p>
49+
50+
<h3>[property:Float intensity]</h3>
51+
<p>
52+
The intensity of the shadow. The default is `1`. Valid values are in the range `[0, 1]`.
53+
</p>
4954

5055
<h3>[property:WebGLRenderTarget map]</h3>
5156
<p>

docs/api/en/lights/shadows/LightShadow.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ <h3>[property:Float bias]</h3>
4747
<h3>[property:Integer blurSamples]</h3>
4848
<p>The amount of samples to use when blurring a VSM shadow map.</p>
4949

50+
<h3>[property:Float intensity]</h3>
51+
<p>
52+
The intensity of the shadow. The default is `1`. Valid values are in the range `[0, 1]`.
53+
</p>
54+
5055
<h3>[property:WebGLRenderTarget map]</h3>
5156
<p>
5257
The depth map generated using the internal camera; a location beyond a

docs/api/it/lights/shadows/LightShadow.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ <h3>[property:Integer blurSamples]</h3>
5050
La quantità di campioni da utilizzare durante la sfocatura di una mappa ombra VSM.
5151
</p>
5252

53+
<h3>[property:Float intensity]</h3>
54+
<p>
55+
The intensity of the shadow. The default is `1`. Valid values are in the range `[0, 1]`.
56+
</p>
57+
5358
<h3>[property:WebGLRenderTarget map]</h3>
5459
<p>
5560
La mappa di profondità generata usando la telecamera interna; una posizione oltre la profondità di un pixel è in ombra.

docs/api/zh/lights/shadows/LightShadow.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ <h3>[property:Integer blurSamples]</h3>
4848
The amount of samples to use when blurring a VSM shadow map.
4949
</p>
5050

51+
<h3>[property:Float intensity]</h3>
52+
<p>
53+
The intensity of the shadow. The default is `1`. Valid values are in the range `[0, 1]`.
54+
</p>
55+
5156
<h3>[property:WebGLRenderTarget map]</h3>
5257
<p>
5358
使用内置摄像头生成的深度图;超出像素深度的位置在阴影中。在渲染期间内部计算。

examples/jsm/nodes/lighting/AnalyticLightNode.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import LightingNode from './LightingNode.js';
22
import { NodeUpdateType } from '../core/constants.js';
33
import { uniform } from '../core/UniformNode.js';
44
import { addNodeClass } from '../core/Node.js';
5-
import { /*vec2,*/ vec3, vec4 } from '../shadernode/ShaderNode.js';
5+
import { vec3, vec4 } from '../shadernode/ShaderNode.js';
66
import { reference } from '../accessors/ReferenceNode.js';
77
import { texture } from '../accessors/TextureNode.js';
88
import { positionWorld } from '../accessors/PositionNode.js';
99
import { normalWorld } from '../accessors/NormalNode.js';
1010
import { WebGPUCoordinateSystem } from 'three';
11-
//import { add } from '../math/OperatorNode.js';
11+
import { mix } from '../math/MathNode.js';
1212

1313
import { Color, DepthTexture, NearestFilter, LessCompare, NoToneMapping } from 'three';
1414

@@ -83,6 +83,7 @@ class AnalyticLightNode extends LightingNode {
8383

8484
//
8585

86+
const shadowIntensity = reference( 'intensity', 'float', shadow );
8687
const bias = reference( 'bias', 'float', shadow );
8788
const normalBias = reference( 'normalBias', 'float', shadow );
8889

@@ -159,7 +160,7 @@ class AnalyticLightNode extends LightingNode {
159160
const shadowMaskNode = frustumTest.mix( 1, shadowNode.mix( shadowColor.a.mix( 1, shadowColor ), 1 ) );
160161

161162
this.rtt = rtt;
162-
this.colorNode = this.colorNode.mul( shadowMaskNode );
163+
this.colorNode = this.colorNode.mul( mix( 1, shadowMaskNode, shadowIntensity ) );
163164

164165
this.shadowNode = shadowNode;
165166
this.shadowMaskNode = shadowMaskNode;

examples/webgl_lights_hemisphere.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,19 @@
218218
dirLight.visible = ! dirLight.visible;
219219
dirLightHelper.visible = ! dirLightHelper.visible;
220220

221-
}
221+
},
222+
shadowIntensity: 1
222223
};
223224

224225
const gui = new GUI();
225226

226227
gui.add( params, 'toggleHemisphereLight' ).name( 'toggle hemisphere light' );
227228
gui.add( params, 'toggleDirectionalLight' ).name( 'toggle directional light' );
229+
gui.add( params, 'shadowIntensity', 0, 1 ).name( 'shadow intensity' ).onChange( ( value ) => {
230+
231+
dirLight.shadow.intensity = value;
232+
233+
} );
228234
gui.open();
229235

230236
//

src/lights/LightShadow.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class LightShadow {
1414

1515
this.camera = camera;
1616

17+
this.intensity = 1;
18+
1719
this.bias = 0;
1820
this.normalBias = 0;
1921
this.radius = 1;
@@ -111,6 +113,8 @@ class LightShadow {
111113

112114
this.camera = source.camera.clone();
113115

116+
this.intensity = source.intensity;
117+
114118
this.bias = source.bias;
115119
this.radius = source.radius;
116120

@@ -130,6 +134,7 @@ class LightShadow {
130134

131135
const object = {};
132136

137+
if ( this.intensity !== 1 ) object.intensity = this.intensity;
133138
if ( this.bias !== 0 ) object.bias = this.bias;
134139
if ( this.normalBias !== 0 ) object.normalBias = this.normalBias;
135140
if ( this.radius !== 1 ) object.radius = this.radius;

src/loaders/ObjectLoader.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,7 @@ class ObjectLoader extends Loader {
10321032

10331033
if ( data.shadow ) {
10341034

1035+
if ( data.shadow.intensity !== undefined ) object.shadow.intensity = data.shadow.intensity;
10351036
if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
10361037
if ( data.shadow.normalBias !== undefined ) object.shadow.normalBias = data.shadow.normalBias;
10371038
if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;

src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ IncidentLight directLight;
6868
6969
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )
7070
pointLightShadow = pointLightShadows[ i ];
71-
directLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;
71+
directLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;
7272
#endif
7373
7474
RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
@@ -116,7 +116,7 @@ IncidentLight directLight;
116116
117117
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
118118
spotLightShadow = spotLightShadows[ i ];
119-
directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;
119+
directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;
120120
#endif
121121
122122
RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
@@ -142,7 +142,7 @@ IncidentLight directLight;
142142
143143
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
144144
directionalLightShadow = directionalLightShadows[ i ];
145-
directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
145+
directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
146146
#endif
147147
148148
RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );

src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default /* glsl */`
1919
varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];
2020
2121
struct DirectionalLightShadow {
22+
float shadowIntensity;
2223
float shadowBias;
2324
float shadowNormalBias;
2425
float shadowRadius;
@@ -34,6 +35,7 @@ export default /* glsl */`
3435
uniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];
3536
3637
struct SpotLightShadow {
38+
float shadowIntensity;
3739
float shadowBias;
3840
float shadowNormalBias;
3941
float shadowRadius;
@@ -50,6 +52,7 @@ export default /* glsl */`
5052
varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];
5153
5254
struct PointLightShadow {
55+
float shadowIntensity;
5356
float shadowBias;
5457
float shadowNormalBias;
5558
float shadowRadius;
@@ -103,7 +106,7 @@ export default /* glsl */`
103106
104107
}
105108
106-
float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {
109+
float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {
107110
108111
float shadow = 1.0;
109112
@@ -196,7 +199,7 @@ export default /* glsl */`
196199
197200
}
198201
199-
return shadow;
202+
return mix( 1.0, shadow, shadowIntensity );
200203
201204
}
202205
@@ -271,7 +274,7 @@ export default /* glsl */`
271274
272275
}
273276
274-
float getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {
277+
float getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {
275278
276279
float shadow = 1.0;
277280
@@ -316,7 +319,7 @@ export default /* glsl */`
316319
317320
}
318321
319-
return shadow;
322+
return mix( 1.0, shadow, shadowIntensity );
320323
321324
}
322325

src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default /* glsl */`
1515
varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];
1616
1717
struct DirectionalLightShadow {
18+
float shadowIntensity;
1819
float shadowBias;
1920
float shadowNormalBias;
2021
float shadowRadius;
@@ -28,6 +29,7 @@ export default /* glsl */`
2829
#if NUM_SPOT_LIGHT_SHADOWS > 0
2930
3031
struct SpotLightShadow {
32+
float shadowIntensity;
3133
float shadowBias;
3234
float shadowNormalBias;
3335
float shadowRadius;
@@ -44,6 +46,7 @@ export default /* glsl */`
4446
varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];
4547
4648
struct PointLightShadow {
49+
float shadowIntensity;
4750
float shadowBias;
4851
float shadowNormalBias;
4952
float shadowRadius;

src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ float getShadowMask() {
1313
for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {
1414
1515
directionalLight = directionalLightShadows[ i ];
16-
shadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
16+
shadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
1717
1818
}
1919
#pragma unroll_loop_end
@@ -28,7 +28,7 @@ float getShadowMask() {
2828
for ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {
2929
3030
spotLight = spotLightShadows[ i ];
31-
shadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;
31+
shadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowIntensity, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;
3232
3333
}
3434
#pragma unroll_loop_end
@@ -43,7 +43,7 @@ float getShadowMask() {
4343
for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {
4444
4545
pointLight = pointLightShadows[ i ];
46-
shadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;
46+
shadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowIntensity, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;
4747
4848
}
4949
#pragma unroll_loop_end

src/renderers/shaders/UniformsLib.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ const UniformsLib = {
130130
} },
131131

132132
directionalLightShadows: { value: [], properties: {
133+
shadowIntensity: 1,
133134
shadowBias: {},
134135
shadowNormalBias: {},
135136
shadowRadius: {},
@@ -150,6 +151,7 @@ const UniformsLib = {
150151
} },
151152

152153
spotLightShadows: { value: [], properties: {
154+
shadowIntensity: 1,
153155
shadowBias: {},
154156
shadowNormalBias: {},
155157
shadowRadius: {},
@@ -168,6 +170,7 @@ const UniformsLib = {
168170
} },
169171

170172
pointLightShadows: { value: [], properties: {
173+
shadowIntensity: 1,
171174
shadowBias: {},
172175
shadowNormalBias: {},
173176
shadowRadius: {},

src/renderers/webgl/WebGLLights.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ function ShadowUniformsCache() {
9999

100100
case 'DirectionalLight':
101101
uniforms = {
102+
shadowIntensity: 1,
102103
shadowBias: 0,
103104
shadowNormalBias: 0,
104105
shadowRadius: 1,
@@ -108,6 +109,7 @@ function ShadowUniformsCache() {
108109

109110
case 'SpotLight':
110111
uniforms = {
112+
shadowIntensity: 1,
111113
shadowBias: 0,
112114
shadowNormalBias: 0,
113115
shadowRadius: 1,
@@ -117,6 +119,7 @@ function ShadowUniformsCache() {
117119

118120
case 'PointLight':
119121
uniforms = {
122+
shadowIntensity: 1,
120123
shadowBias: 0,
121124
shadowNormalBias: 0,
122125
shadowRadius: 1,
@@ -266,6 +269,7 @@ function WebGLLights( extensions ) {
266269

267270
const shadowUniforms = shadowCache.get( light );
268271

272+
shadowUniforms.shadowIntensity = shadow.intensity;
269273
shadowUniforms.shadowBias = shadow.bias;
270274
shadowUniforms.shadowNormalBias = shadow.normalBias;
271275
shadowUniforms.shadowRadius = shadow.radius;
@@ -319,6 +323,7 @@ function WebGLLights( extensions ) {
319323

320324
const shadowUniforms = shadowCache.get( light );
321325

326+
shadowUniforms.shadowIntensity = shadow.intensity;
322327
shadowUniforms.shadowBias = shadow.bias;
323328
shadowUniforms.shadowNormalBias = shadow.normalBias;
324329
shadowUniforms.shadowRadius = shadow.radius;
@@ -360,6 +365,7 @@ function WebGLLights( extensions ) {
360365

361366
const shadowUniforms = shadowCache.get( light );
362367

368+
shadowUniforms.shadowIntensity = shadow.intensity;
363369
shadowUniforms.shadowBias = shadow.bias;
364370
shadowUniforms.shadowNormalBias = shadow.normalBias;
365371
shadowUniforms.shadowRadius = shadow.radius;

0 commit comments

Comments
 (0)