Skip to content

Commit e74c655

Browse files
aardgooseaardgoose
and
aardgoose
authored
WebGPURenderer: Texture fixes for WebGL backend (mrdoob#26797)
* misc texture fixes handle VideoTexture. handle depth textures in GLSL shaders (depth in x component in returned vec4()) map WGSL textureDimensions to GLSL textureSize() Examples fixed lights / ies /spotlights video / panorama material / video (partial) * remove surplus entry --------- Co-authored-by: aardgoose <[email protected]>
1 parent 18febaf commit e74c655

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

examples/jsm/nodes/accessors/TextureSizeNode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class TextureSizeNode extends Node {
2020
const textureProperty = this.textureNode.build( builder, 'property' );
2121
const levelNode = this.levelNode.build( builder, 'int' );
2222

23-
return builder.format( `textureDimensions( ${textureProperty}, ${levelNode} )`, this.getNodeType( builder ), output );
23+
return builder.format( `${builder.getMethod( 'textureDimensions' )}( ${textureProperty}, ${levelNode} )`, this.getNodeType( builder ), output );
2424

2525
}
2626

examples/jsm/renderers/webgl/WebGLBackend.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,12 @@ class WebGLBackend extends Backend {
282282
textureUtils.setTextureParameters( glTextureType, texture );
283283

284284
gl.bindTexture( glTextureType, textureGPU );
285-
gl.texStorage2D( glTextureType, levels, glInternalFormat, width, height );
285+
286+
if ( ! texture.isVideoTexture ) {
287+
288+
gl.texStorage2D( glTextureType, levels, glInternalFormat, width, height );
289+
290+
}
286291

287292
this.set( texture, {
288293
textureGPU,
@@ -298,17 +303,21 @@ class WebGLBackend extends Backend {
298303

299304
const { gl } = this;
300305
const { width, height } = options;
301-
const { textureGPU, glTextureType, glFormat, glType } = this.get( texture );
306+
const { textureGPU, glTextureType, glFormat, glType, glInternalFormat } = this.get( texture );
302307

303308
const getImage = ( source ) => {
304309

305310
if ( source.isDataTexture ) {
306311

307312
return source.image.data;
308313

314+
} else if ( source instanceof ImageBitmap || source instanceof OffscreenCanvas ) {
315+
316+
return source;
317+
309318
}
310319

311-
return source;
320+
return source.data;
312321

313322
};
314323

@@ -326,6 +335,13 @@ class WebGLBackend extends Backend {
326335

327336
}
328337

338+
} else if ( texture.isVideoTexture ) {
339+
340+
texture.update();
341+
342+
gl.texImage2D( glTextureType, 0, glInternalFormat, glFormat, glType, options.image );
343+
344+
329345
} else {
330346

331347
const image = getImage( options.image );

examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import UniformsGroup from '../../common/UniformsGroup.js';
44
import { NodeSampledTexture, NodeSampledCubeTexture } from '../../common/nodes/NodeSampledTexture.js';
55

66
const glslMethods = {
7-
[ MathNode.ATAN2 ]: 'atan'
7+
[ MathNode.ATAN2 ]: 'atan',
8+
textureDimensions: 'textureSize'
89
};
910

1011
const precisionLib = {
@@ -35,6 +36,10 @@ class GLSLNodeBuilder extends NodeBuilder {
3536

3637
return `textureCube( ${textureProperty}, ${uvSnippet} )`;
3738

39+
} else if ( texture.isDepthTexture ) {
40+
41+
return `texture( ${textureProperty}, ${uvSnippet} ).x`;
42+
3843
} else {
3944

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

0 commit comments

Comments
 (0)