Skip to content

Commit

Permalink
Revert "WebGPURenderer: Add SpotLight.map support (#29989)"
Browse files Browse the repository at this point in the history
This reverts commit e2e04d3.
  • Loading branch information
sunag committed Dec 7, 2024
1 parent 50c6e14 commit 9a2e6c2
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 305 deletions.
1 change: 0 additions & 1 deletion examples/files.json
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@
"webgpu_lights_physical",
"webgpu_lights_rectarealight",
"webgpu_lights_selective",
"webgpu_lights_spotlight",
"webgpu_lights_tiled",
"webgpu_lines_fat_raycasting",
"webgpu_lines_fat_wireframe",
Expand Down
Binary file removed examples/screenshots/webgpu_lights_spotlight.jpg
Binary file not shown.
252 changes: 0 additions & 252 deletions examples/webgpu_lights_spotlight.html

This file was deleted.

32 changes: 0 additions & 32 deletions src/nodes/accessors/Lights.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { uniform } from '../core/UniformNode.js';
import { renderGroup } from '../core/UniformGroupNode.js';
import { Vector3 } from '../../math/Vector3.js';
import { cameraViewMatrix } from './Camera.js';
import { positionWorld } from './Position.js';

let uniformsLib;

Expand All @@ -18,37 +17,6 @@ function getLightData( light ) {

}

export function lightShadowMatrix( light ) {

const data = getLightData( light );

return data.shadowMatrix || ( data.shadowMatrix = uniform( 'mat4' ).setGroup( renderGroup ).onRenderUpdate( () => {

light.shadow.updateMatrices( light );

return light.shadow.matrix;

} ) );

}

export function lightProjectionUV( light ) {

const data = getLightData( light );

if ( data.projectionUV === undefined ) {

const spotLightCoord = lightShadowMatrix( light ).mul( positionWorld );

data.projectionUV = spotLightCoord.xyz.div( spotLightCoord.w );


}

return data.projectionUV;

}

export function lightPosition( light ) {

const data = getLightData( light );
Expand Down
6 changes: 3 additions & 3 deletions src/nodes/lighting/AnalyticLightNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ class AnalyticLightNode extends LightingNode {

super();

this.updateType = NodeUpdateType.FRAME;

this.light = light;

this.color = new Color();
this.colorNode = ( light && light.colorNode ) || uniform( this.color ).setGroup( renderGroup );
this.colorNode = uniform( this.color ).setGroup( renderGroup );

this.baseColorNode = null;

Expand All @@ -31,8 +33,6 @@ class AnalyticLightNode extends LightingNode {

this.isAnalyticLightNode = true;

this.updateType = NodeUpdateType.FRAME;

}

getCacheKey() {
Expand Down
8 changes: 5 additions & 3 deletions src/nodes/lighting/ShadowNode.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Node from '../core/Node.js';
import { NodeUpdateType } from '../core/constants.js';
import { uniform } from '../core/UniformNode.js';
import { float, vec2, vec3, vec4, If, int, Fn, nodeObject } from '../tsl/TSLBase.js';
import { reference } from '../accessors/ReferenceNode.js';
import { texture } from '../accessors/TextureNode.js';
Expand All @@ -16,7 +17,6 @@ import { HalfFloatType, LessCompare, RGFormat, VSMShadowMap, WebGPUCoordinateSys
import { renderGroup } from '../core/UniformGroupNode.js';
import { viewZToLogarithmicDepth } from '../display/ViewportDepthNode.js';
import { objectPosition } from '../accessors/Object3DNode.js';
import { lightShadowMatrix } from '../accessors/Lights.js';

const shadowWorldPosition = /*@__PURE__*/ vec3().toVar( 'shadowWorldPosition' );

Expand Down Expand Up @@ -383,7 +383,7 @@ class ShadowNode extends Node {
const shadowIntensity = reference( 'intensity', 'float', shadow ).setGroup( renderGroup );
const normalBias = reference( 'normalBias', 'float', shadow ).setGroup( renderGroup );

const shadowPosition = lightShadowMatrix( light ).mul( shadowWorldPosition.add( transformedNormalWorld.mul( normalBias ) ) );
const shadowPosition = uniform( shadow.matrix ).setGroup( renderGroup ).mul( shadowWorldPosition.add( transformedNormalWorld.mul( normalBias ) ) );
const shadowCoord = this.setupShadowCoord( builder, shadowPosition );

//
Expand Down Expand Up @@ -446,9 +446,11 @@ class ShadowNode extends Node {

renderShadow( frame ) {

const { shadow, shadowMap } = this;
const { shadow, shadowMap, light } = this;
const { renderer, scene } = frame;

shadow.updateMatrices( light );

shadowMap.setSize( shadow.mapSize.width, shadow.mapSize.height );

renderer.render( scene, shadow.camera );
Expand Down
16 changes: 2 additions & 14 deletions src/nodes/lighting/SpotLightNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { uniform } from '../core/UniformNode.js';
import { smoothstep } from '../math/MathNode.js';
import { positionView } from '../accessors/Position.js';
import { renderGroup } from '../core/UniformGroupNode.js';
import { lightViewPosition, lightTargetDirection, lightProjectionUV } from '../accessors/Lights.js';
import { texture } from '../accessors/TextureNode.js';
import { lightViewPosition, lightTargetDirection } from '../accessors/Lights.js';

class SpotLightNode extends AnalyticLightNode {

Expand Down Expand Up @@ -71,18 +70,7 @@ class SpotLightNode extends AnalyticLightNode {
decayExponent: decayExponentNode
} );

let lightColor = colorNode.mul( spotAttenuation ).mul( lightAttenuation );

if ( light.map ) {

const spotLightCoord = lightProjectionUV( light );
const projectedTexture = texture( light.map, spotLightCoord.xy ).onRenderUpdate( () => light.map );

const inSpotLightMap = spotLightCoord.mul( 2. ).sub( 1. ).abs().lessThan( 1. ).all();

lightColor = inSpotLightMap.select( lightColor.mul( projectedTexture ), lightColor );

}
const lightColor = colorNode.mul( spotAttenuation ).mul( lightAttenuation );

const reflectedLight = builder.context.reflectedLight;

Expand Down

0 comments on commit 9a2e6c2

Please sign in to comment.