Skip to content
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
2 changes: 1 addition & 1 deletion examples/webgpu_caustics.html
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animate );
renderer.shadowMap.enabled = true;
renderer.shadowMap.color = true;
renderer.shadowMap.colored = true;
renderer.inspector = new Inspector();
document.body.appendChild( renderer.domElement );

Expand Down
2 changes: 1 addition & 1 deletion examples/webgpu_shadowmap_opacity.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
renderer.toneMapping = THREE.AgXToneMapping;
renderer.toneMappingExposure = 1.5;
renderer.shadowMap.enabled = true;
renderer.shadowMap.color = true;
renderer.shadowMap.colored = true;
renderer.inspector = new Inspector();
container.appendChild( renderer.domElement );

Expand Down
2 changes: 1 addition & 1 deletion examples/webgpu_volume_caustics.html
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@

renderer = new THREE.WebGPURenderer( { antialias: true } );
renderer.shadowMap.enabled = true;
renderer.shadowMap.color = true;
renderer.shadowMap.colored = true;
renderer.inspector = new Inspector();
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
Expand Down
11 changes: 10 additions & 1 deletion src/nodes/core/NodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,16 @@ class NodeBuilder {
const uniforms = bindings[ shaderStage ][ groupName ];

const groupUniforms = groups[ groupName ] || ( groups[ groupName ] = [] );
groupUniforms.push( ...uniforms );

for ( const uniform of uniforms ) {

if ( groupUniforms.includes( uniform ) === false ) {

groupUniforms.push( uniform );

}

}

}

Expand Down
2 changes: 1 addition & 1 deletion src/nodes/lighting/ShadowNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ class ShadowNode extends ShadowBaseNode {

let shadowColor;

if ( renderer.shadowMap.color === true ) {
if ( renderer.shadowMap.colored === true ) {

if ( shadowMap.texture.isCubeTexture ) {

Expand Down
8 changes: 4 additions & 4 deletions src/renderers/common/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ class Renderer {
* Shadow map configuration
* @typedef {Object} ShadowMapConfig
* @property {boolean} enabled - Whether to globally enable shadows or not.
* @property {boolean} color - Whether to include shadow color or not.
* @property {boolean} colored - Whether shadows can have a custom color or not.
* @property {number} type - The shadow map type.
*/

Expand All @@ -669,7 +669,7 @@ class Renderer {
*/
this.shadowMap = {
enabled: false,
color: false,
colored: false,
type: PCFShadowMap
};

Expand Down Expand Up @@ -3053,9 +3053,9 @@ class Renderer {
shadowRGB = material.castShadowNode.rgb;
shadowAlpha = material.castShadowNode.a;

if ( this.shadowMap.color !== true ) {
if ( this.shadowMap.colored !== true ) {

warnOnce( 'Renderer: `shadowMap.color` needs to be enabled when using `material.castShadowNode`.' );
warnOnce( 'Renderer: `shadowMap.colored` needs to be set to `true` when using `material.castShadowNode`.' );

}

Expand Down
29 changes: 26 additions & 3 deletions src/renderers/webgpu/nodes/WGSLNodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ class WGSLNodeBuilder extends NodeBuilder {
*/
this.uniformGroups = {};

/**
* A dictionary that holds the assigned binding indices for each uniform group.
* This ensures the same binding index is used across all shader stages.
*
* @type {Object<string,{index: number, id: number}>}
*/
this.uniformGroupsBindings = {};

/**
* A dictionary that holds for each shader stage a Map of builtins.
*
Expand Down Expand Up @@ -1859,7 +1867,7 @@ ${ flowData.code }

const groupName = uniform.groupNode.name;

// Check if this group has already been processed
// Check if this group has already been processed in this shader stage
if ( uniformGroups[ groupName ] === undefined ) {

// Get the shared uniform group that contains uniforms from all stages
Expand All @@ -1878,9 +1886,24 @@ ${ flowData.code }

}

// Check if this group already has an assigned binding index (from another shader stage)
let groupBinding = this.uniformGroupsBindings[ groupName ];

if ( groupBinding === undefined ) {

// First time processing this group - assign a new binding index
groupBinding = {
index: uniformIndexes.binding ++,
id: uniformIndexes.group
};

this.uniformGroupsBindings[ groupName ] = groupBinding;

}

uniformGroups[ groupName ] = {
index: uniformIndexes.binding ++,
id: uniformIndexes.group,
index: groupBinding.index,
id: groupBinding.id,
snippets: snippets
};

Expand Down