Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextureNode: Add biasNode. #28786

Merged
merged 1 commit into from
Jul 2, 2024
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
15 changes: 11 additions & 4 deletions src/nodes/accessors/TextureNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import { IntType, UnsignedIntType } from '../../constants.js';

class TextureNode extends UniformNode {

constructor( value, uvNode = null, levelNode = null ) {
constructor( value, uvNode = null, levelNode = null, biasNode = null ) {

super( value );

this.isTextureNode = true;

this.uvNode = uvNode;
this.levelNode = levelNode;
this.biasNode = biasNode;
this.compareNode = null;
this.depthNode = null;
this.gradNode = null;
Expand Down Expand Up @@ -168,6 +169,7 @@ class TextureNode extends UniformNode {

properties.uvNode = uvNode;
properties.levelNode = levelNode;
properties.biasNode = this.biasNode;
properties.compareNode = this.compareNode;
properties.gradNode = this.gradNode;
properties.depthNode = this.depthNode;
Expand All @@ -180,7 +182,7 @@ class TextureNode extends UniformNode {

}

generateSnippet( builder, textureProperty, uvSnippet, levelSnippet, depthSnippet, compareSnippet, gradSnippet ) {
generateSnippet( builder, textureProperty, uvSnippet, levelSnippet, biasSnippet, depthSnippet, compareSnippet, gradSnippet ) {

const texture = this.value;

Expand All @@ -190,6 +192,10 @@ class TextureNode extends UniformNode {

snippet = builder.generateTextureLevel( texture, textureProperty, uvSnippet, levelSnippet, depthSnippet );

} else if ( biasSnippet ) {

snippet = builder.generateTextureBias( texture, textureProperty, uvSnippet, biasSnippet, depthSnippet );

} else if ( gradSnippet ) {

snippet = builder.generateTextureGrad( texture, textureProperty, uvSnippet, gradSnippet, depthSnippet );
Expand Down Expand Up @@ -242,10 +248,11 @@ class TextureNode extends UniformNode {

if ( propertyName === undefined ) {

const { uvNode, levelNode, compareNode, depthNode, gradNode } = properties;
const { uvNode, levelNode, biasNode, compareNode, depthNode, gradNode } = properties;

const uvSnippet = this.generateUV( builder, uvNode );
const levelSnippet = levelNode ? levelNode.build( builder, 'float' ) : null;
const biasSnippet = biasNode ? biasNode.build( builder, 'float' ) : null;
const depthSnippet = depthNode ? depthNode.build( builder, 'int' ) : null;
const compareSnippet = compareNode ? compareNode.build( builder, 'float' ) : null;
const gradSnippet = gradNode ? [ gradNode[ 0 ].build( builder, 'vec2' ), gradNode[ 1 ].build( builder, 'vec2' ) ] : null;
Expand All @@ -254,7 +261,7 @@ class TextureNode extends UniformNode {

propertyName = builder.getPropertyName( nodeVar );

const snippet = this.generateSnippet( builder, textureProperty, uvSnippet, levelSnippet, depthSnippet, compareSnippet, gradSnippet );
const snippet = this.generateSnippet( builder, textureProperty, uvSnippet, levelSnippet, biasSnippet, depthSnippet, compareSnippet, gradSnippet );

builder.addLineFlowCode( `${propertyName} = ${snippet}` );

Expand Down
6 changes: 6 additions & 0 deletions src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@ ${ flowData.code }

}

generateTextureBias( texture, textureProperty, uvSnippet, biasSnippet ) {

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

}

generateTextureGrad( texture, textureProperty, uvSnippet, gradSnippet ) {

return `textureGrad( ${ textureProperty }, ${ uvSnippet }, ${ gradSnippet[ 0 ] }, ${ gradSnippet[ 1 ] } )`;
Expand Down
14 changes: 14 additions & 0 deletions src/renderers/webgpu/nodes/WGSLNodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,20 @@ class WGSLNodeBuilder extends NodeBuilder {

}

generateTextureBias( texture, textureProperty, uvSnippet, biasSnippet, depthSnippet, shaderStage = this.shaderStage ) {

if ( shaderStage === 'fragment' ) {

return `textureSampleBias( ${ textureProperty }, ${ textureProperty }_sampler, ${ uvSnippet }, ${ biasSnippet } )`;

} else {

console.error( `WebGPURenderer: THREE.TextureNode.biasNode does not support ${ shaderStage } shader.` );

}

}

getPropertyName( node, shaderStage = this.shaderStage ) {

if ( node.isNodeVarying === true && node.needsInterpolation === true ) {
Expand Down