Skip to content

Conversation

shotamatsuda
Copy link
Contributor

Description

Following the discussion in #31760, this PR fixes an issue where texture() in WebGLBackend generating incorrect UV code, resulting a GLSL compilation error.

The argument to GLSL's texture() can be vec4, when the sampler is sampler2DArrayShadow for example, but the uvSnippet in generateTexture should not be assumed to be vec3, and it should be handled separately.
https://github.com/mrdoob/three.js/blob/r179/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js#L403

Copy link

github-actions bot commented Aug 28, 2025

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 338.91
79.11
338.91
79.11
+0 B
+0 B
WebGPU 579.39
159.66
579.36
159.65
-32 B
-11 B
WebGPU Nodes 578
159.42
577.97
159.4
-32 B
-12 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 470.78
113.9
470.78
113.9
+0 B
+0 B
WebGPU 649.54
175.53
649.51
175.52
-32 B
-11 B
WebGPU Nodes 603.64
164.67
603.6
164.66
-32 B
-10 B

@RenaudRohlinger
Copy link
Collaborator

Nice, we could simplify a bit like this:

generateTexture( texture, textureProperty, uvSnippet, depthSnippet, offsetSnippet ) {

	if ( depthSnippet ) uvSnippet = `vec3( ${ uvSnippet }, ${ depthSnippet } )`;

	if ( texture.isDepthTexture ) {

		if ( offsetSnippet ) return `textureOffset( ${ textureProperty }, ${ uvSnippet }, ${ offsetSnippet } ).x`;

		return `texture( ${ textureProperty }, ${ uvSnippet } ).x`;

	}

	if ( offsetSnippet ) return `textureOffset( ${ textureProperty }, ${ uvSnippet }, ${ offsetSnippet } )`;

	return `texture( ${ textureProperty }, ${ uvSnippet } )`;

}

@Mugen87 Mugen87 merged commit 4d69cdc into mrdoob:dev Aug 28, 2025
9 checks passed
@Mugen87 Mugen87 added this to the r180 milestone Aug 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants