Skip to content

Commit

Permalink
WebGPURenderer: Texture fixes for WebGL backend (mrdoob#26797)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
aardgoose and aardgoose authored Sep 18, 2023
1 parent 18febaf commit e74c655
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/jsm/nodes/accessors/TextureSizeNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TextureSizeNode extends Node {
const textureProperty = this.textureNode.build( builder, 'property' );
const levelNode = this.levelNode.build( builder, 'int' );

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

}

Expand Down
22 changes: 19 additions & 3 deletions examples/jsm/renderers/webgl/WebGLBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,12 @@ class WebGLBackend extends Backend {
textureUtils.setTextureParameters( glTextureType, texture );

gl.bindTexture( glTextureType, textureGPU );
gl.texStorage2D( glTextureType, levels, glInternalFormat, width, height );

if ( ! texture.isVideoTexture ) {

gl.texStorage2D( glTextureType, levels, glInternalFormat, width, height );

}

this.set( texture, {
textureGPU,
Expand All @@ -298,17 +303,21 @@ class WebGLBackend extends Backend {

const { gl } = this;
const { width, height } = options;
const { textureGPU, glTextureType, glFormat, glType } = this.get( texture );
const { textureGPU, glTextureType, glFormat, glType, glInternalFormat } = this.get( texture );

const getImage = ( source ) => {

if ( source.isDataTexture ) {

return source.image.data;

} else if ( source instanceof ImageBitmap || source instanceof OffscreenCanvas ) {

return source;

}

return source;
return source.data;

};

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

}

} else if ( texture.isVideoTexture ) {

texture.update();

gl.texImage2D( glTextureType, 0, glInternalFormat, glFormat, glType, options.image );


} else {

const image = getImage( options.image );
Expand Down
7 changes: 6 additions & 1 deletion examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import UniformsGroup from '../../common/UniformsGroup.js';
import { NodeSampledTexture, NodeSampledCubeTexture } from '../../common/nodes/NodeSampledTexture.js';

const glslMethods = {
[ MathNode.ATAN2 ]: 'atan'
[ MathNode.ATAN2 ]: 'atan',
textureDimensions: 'textureSize'
};

const precisionLib = {
Expand Down Expand Up @@ -35,6 +36,10 @@ class GLSLNodeBuilder extends NodeBuilder {

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

} else if ( texture.isDepthTexture ) {

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

} else {

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

0 comments on commit e74c655

Please sign in to comment.