Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LightShadow: Add intensity. #28588

Merged
merged 3 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/api/ar/lights/shadows/LightShadow.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ <h3>[property:Float bias]</h3>

<h3>[property:Integer blurSamples]</h3>
<p>عدد العينات المستخدمة عند طمس خريطة ظل VSM.</p>

<h3>[property:Float intensity]</h3>
<p>
The intensity of the shadow. The default is `1`. Valid values are in the range `[0, 1]`.
</p>

<h3>[property:WebGLRenderTarget map]</h3>
<p>
Expand Down
5 changes: 5 additions & 0 deletions docs/api/en/lights/shadows/LightShadow.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ <h3>[property:Float bias]</h3>
<h3>[property:Integer blurSamples]</h3>
<p>The amount of samples to use when blurring a VSM shadow map.</p>

<h3>[property:Float intensity]</h3>
<p>
The intensity of the shadow. The default is `1`. Valid values are in the range `[0, 1]`.
</p>

<h3>[property:WebGLRenderTarget map]</h3>
<p>
The depth map generated using the internal camera; a location beyond a
Expand Down
5 changes: 5 additions & 0 deletions docs/api/it/lights/shadows/LightShadow.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ <h3>[property:Integer blurSamples]</h3>
La quantità di campioni da utilizzare durante la sfocatura di una mappa ombra VSM.
</p>

<h3>[property:Float intensity]</h3>
<p>
The intensity of the shadow. The default is `1`. Valid values are in the range `[0, 1]`.
</p>

<h3>[property:WebGLRenderTarget map]</h3>
<p>
La mappa di profondità generata usando la telecamera interna; una posizione oltre la profondità di un pixel è in ombra.
Expand Down
5 changes: 5 additions & 0 deletions docs/api/zh/lights/shadows/LightShadow.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ <h3>[property:Integer blurSamples]</h3>
The amount of samples to use when blurring a VSM shadow map.
</p>

<h3>[property:Float intensity]</h3>
<p>
The intensity of the shadow. The default is `1`. Valid values are in the range `[0, 1]`.
</p>

<h3>[property:WebGLRenderTarget map]</h3>
<p>
使用内置摄像头生成的深度图;超出像素深度的位置在阴影中。在渲染期间内部计算。
Expand Down
8 changes: 4 additions & 4 deletions examples/jsm/csm/CSMShader.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ IncidentLight directLight;

#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
spotLightShadow = spotLightShadows[ i ];
directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;
directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;

#endif

Expand Down Expand Up @@ -141,7 +141,7 @@ IncidentLight directLight;

vec3 prevColor = directLight.color;
directionalLightShadow = directionalLightShadows[ i ];
directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;

bool shouldFadeLastCascade = UNROLLED_LOOP_INDEX == CSM_CASCADES - 1 && linearDepth > cascadeCenter;
directLight.color = mix( prevColor, directLight.color, shouldFadeLastCascade ? ratio : 1.0 );
Expand Down Expand Up @@ -173,7 +173,7 @@ IncidentLight directLight;
#if ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )

directionalLightShadow = directionalLightShadows[ i ];
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;
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.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;

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 );

Expand Down Expand Up @@ -225,7 +225,7 @@ IncidentLight directLight;

#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
directionalLightShadow = directionalLightShadows[ i ];
directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
#endif

RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
Expand Down
7 changes: 4 additions & 3 deletions examples/jsm/nodes/lighting/AnalyticLightNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import LightingNode from './LightingNode.js';
import { NodeUpdateType } from '../core/constants.js';
import { uniform } from '../core/UniformNode.js';
import { addNodeClass } from '../core/Node.js';
import { /*vec2,*/ vec3, vec4 } from '../shadernode/ShaderNode.js';
import { vec3, vec4 } from '../shadernode/ShaderNode.js';
import { reference } from '../accessors/ReferenceNode.js';
import { texture } from '../accessors/TextureNode.js';
import { positionWorld } from '../accessors/PositionNode.js';
import { normalWorld } from '../accessors/NormalNode.js';
import { WebGPUCoordinateSystem } from 'three';
//import { add } from '../math/OperatorNode.js';
import { mix } from '../math/MathNode.js';

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

Expand Down Expand Up @@ -83,6 +83,7 @@ class AnalyticLightNode extends LightingNode {

//

const shadowIntensity = reference( 'intensity', 'float', shadow );
const bias = reference( 'bias', 'float', shadow );
const normalBias = reference( 'normalBias', 'float', shadow );

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

this.rtt = rtt;
this.colorNode = this.colorNode.mul( shadowMaskNode );
this.colorNode = this.colorNode.mul( mix( 1, shadowMaskNode, shadowIntensity ) );

this.shadowNode = shadowNode;
this.shadowMaskNode = shadowMaskNode;
Expand Down
8 changes: 7 additions & 1 deletion examples/webgl_lights_hemisphere.html
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,19 @@
dirLight.visible = ! dirLight.visible;
dirLightHelper.visible = ! dirLightHelper.visible;

}
},
shadowIntensity: 1
};

const gui = new GUI();

gui.add( params, 'toggleHemisphereLight' ).name( 'toggle hemisphere light' );
gui.add( params, 'toggleDirectionalLight' ).name( 'toggle directional light' );
gui.add( params, 'shadowIntensity', 0, 1 ).name( 'shadow intensity' ).onChange( ( value ) => {

dirLight.shadow.intensity = value;

} );
gui.open();

//
Expand Down
5 changes: 5 additions & 0 deletions src/lights/LightShadow.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class LightShadow {

this.camera = camera;

this.intensity = 1;

this.bias = 0;
this.normalBias = 0;
this.radius = 1;
Expand Down Expand Up @@ -111,6 +113,8 @@ class LightShadow {

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

this.intensity = source.intensity;

this.bias = source.bias;
this.radius = source.radius;

Expand All @@ -130,6 +134,7 @@ class LightShadow {

const object = {};

if ( this.intensity !== 1 ) object.intensity = this.intensity;
if ( this.bias !== 0 ) object.bias = this.bias;
if ( this.normalBias !== 0 ) object.normalBias = this.normalBias;
if ( this.radius !== 1 ) object.radius = this.radius;
Expand Down
1 change: 1 addition & 0 deletions src/loaders/ObjectLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,7 @@ class ObjectLoader extends Loader {

if ( data.shadow ) {

if ( data.shadow.intensity !== undefined ) object.shadow.intensity = data.shadow.intensity;
if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
if ( data.shadow.normalBias !== undefined ) object.shadow.normalBias = data.shadow.normalBias;
if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ IncidentLight directLight;

#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )
pointLightShadow = pointLightShadows[ i ];
directLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;
directLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowIntensity, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;
#endif

RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
Expand Down Expand Up @@ -116,7 +116,7 @@ IncidentLight directLight;

#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )
spotLightShadow = spotLightShadows[ i ];
directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;
directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowIntensity, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;
#endif

RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
Expand All @@ -142,7 +142,7 @@ IncidentLight directLight;

#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )
directionalLightShadow = directionalLightShadows[ i ];
directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowIntensity, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
#endif

RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default /* glsl */`
varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];

struct DirectionalLightShadow {
float shadowIntensity;
float shadowBias;
float shadowNormalBias;
float shadowRadius;
Expand All @@ -34,6 +35,7 @@ export default /* glsl */`
uniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];

struct SpotLightShadow {
float shadowIntensity;
float shadowBias;
float shadowNormalBias;
float shadowRadius;
Expand All @@ -50,6 +52,7 @@ export default /* glsl */`
varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];

struct PointLightShadow {
float shadowIntensity;
float shadowBias;
float shadowNormalBias;
float shadowRadius;
Expand Down Expand Up @@ -103,7 +106,7 @@ export default /* glsl */`

}

float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {
float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord ) {

float shadow = 1.0;

Expand Down Expand Up @@ -196,7 +199,7 @@ export default /* glsl */`

}

return shadow;
return mix( 1.0, shadow, shadowIntensity );

}

Expand Down Expand Up @@ -271,7 +274,7 @@ export default /* glsl */`

}

float getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {
float getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowIntensity, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {

float shadow = 1.0;

Expand Down Expand Up @@ -316,7 +319,7 @@ export default /* glsl */`

}

return shadow;
return mix( 1.0, shadow, shadowIntensity );

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default /* glsl */`
varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];

struct DirectionalLightShadow {
float shadowIntensity;
float shadowBias;
float shadowNormalBias;
float shadowRadius;
Expand All @@ -28,6 +29,7 @@ export default /* glsl */`
#if NUM_SPOT_LIGHT_SHADOWS > 0

struct SpotLightShadow {
float shadowIntensity;
float shadowBias;
float shadowNormalBias;
float shadowRadius;
Expand All @@ -44,6 +46,7 @@ export default /* glsl */`
varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];

struct PointLightShadow {
float shadowIntensity;
float shadowBias;
float shadowNormalBias;
float shadowRadius;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ float getShadowMask() {
for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {

directionalLight = directionalLightShadows[ i ];
shadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;
shadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowIntensity, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;

}
#pragma unroll_loop_end
Expand All @@ -28,7 +28,7 @@ float getShadowMask() {
for ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {

spotLight = spotLightShadows[ i ];
shadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;
shadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowIntensity, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;

}
#pragma unroll_loop_end
Expand All @@ -43,7 +43,7 @@ float getShadowMask() {
for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {

pointLight = pointLightShadows[ i ];
shadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;
shadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowIntensity, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;

}
#pragma unroll_loop_end
Expand Down
3 changes: 3 additions & 0 deletions src/renderers/shaders/UniformsLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ const UniformsLib = {
} },

directionalLightShadows: { value: [], properties: {
shadowIntensity: 1,
shadowBias: {},
shadowNormalBias: {},
shadowRadius: {},
Expand All @@ -150,6 +151,7 @@ const UniformsLib = {
} },

spotLightShadows: { value: [], properties: {
shadowIntensity: 1,
shadowBias: {},
shadowNormalBias: {},
shadowRadius: {},
Expand All @@ -168,6 +170,7 @@ const UniformsLib = {
} },

pointLightShadows: { value: [], properties: {
shadowIntensity: 1,
shadowBias: {},
shadowNormalBias: {},
shadowRadius: {},
Expand Down
6 changes: 6 additions & 0 deletions src/renderers/webgl/WebGLLights.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ function ShadowUniformsCache() {

case 'DirectionalLight':
uniforms = {
shadowIntensity: 1,
shadowBias: 0,
shadowNormalBias: 0,
shadowRadius: 1,
Expand All @@ -108,6 +109,7 @@ function ShadowUniformsCache() {

case 'SpotLight':
uniforms = {
shadowIntensity: 1,
shadowBias: 0,
shadowNormalBias: 0,
shadowRadius: 1,
Expand All @@ -117,6 +119,7 @@ function ShadowUniformsCache() {

case 'PointLight':
uniforms = {
shadowIntensity: 1,
shadowBias: 0,
shadowNormalBias: 0,
shadowRadius: 1,
Expand Down Expand Up @@ -266,6 +269,7 @@ function WebGLLights( extensions ) {

const shadowUniforms = shadowCache.get( light );

shadowUniforms.shadowIntensity = shadow.intensity;
shadowUniforms.shadowBias = shadow.bias;
shadowUniforms.shadowNormalBias = shadow.normalBias;
shadowUniforms.shadowRadius = shadow.radius;
Expand Down Expand Up @@ -319,6 +323,7 @@ function WebGLLights( extensions ) {

const shadowUniforms = shadowCache.get( light );

shadowUniforms.shadowIntensity = shadow.intensity;
shadowUniforms.shadowBias = shadow.bias;
shadowUniforms.shadowNormalBias = shadow.normalBias;
shadowUniforms.shadowRadius = shadow.radius;
Expand Down Expand Up @@ -360,6 +365,7 @@ function WebGLLights( extensions ) {

const shadowUniforms = shadowCache.get( light );

shadowUniforms.shadowIntensity = shadow.intensity;
shadowUniforms.shadowBias = shadow.bias;
shadowUniforms.shadowNormalBias = shadow.normalBias;
shadowUniforms.shadowRadius = shadow.radius;
Expand Down