-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NodeMaterial: CubeTexture WebGPU and WebGL (#23743)
* fix camera ref * add viewMatrix, cameraPosition and cleanup * fi texture parameter * add getCubeTexture() and bias API update * WebGLNodeBuilder: update bias API * fix refresh uniforms of shared materials * add WebGPUNodeSampledCubeTexture * WebGPURenderer: CubeTexture support * TextureNode: update bias API * add CubeTextureNode and ReflectNode * update examples * Revert "WebGPURenderer: CubeTexture support" This reverts commit 6c62b26. * Revert "Revert "WebGPURenderer: CubeTexture support"" This reverts commit 4498f37. * fix default value of baseArrayLayer * CubeTextureNode instanceof of TextureNode
- Loading branch information
Showing
18 changed files
with
347 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,8 @@ class CameraNode extends Object3DNode { | |
|
||
} else { | ||
|
||
this.object3d = camera; | ||
|
||
super.update( frame ); | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import TextureNode from './TextureNode.js'; | ||
import UniformNode from '../core/UniformNode.js'; | ||
import ReflectNode from './ReflectNode.js'; | ||
|
||
class CubeTextureNode extends TextureNode { | ||
|
||
constructor( value, uvNode = new ReflectNode(), biasNode = null ) { | ||
|
||
super( value, uvNode, biasNode ); | ||
|
||
} | ||
|
||
getInputType( /*builder*/ ) { | ||
|
||
return 'cubeTexture'; | ||
|
||
} | ||
|
||
generate( builder, output ) { | ||
|
||
const texture = this.value; | ||
|
||
if ( ! texture || texture.isCubeTexture !== true ) { | ||
|
||
throw new Error( 'CubeTextureNode: Need a three.js cube texture.' ); | ||
|
||
} | ||
|
||
const textureProperty = UniformNode.prototype.generate.call( this, builder, 'cubeTexture' ); | ||
|
||
if ( output === 'samplerCube' || output === 'textureCube' ) { | ||
|
||
return textureProperty; | ||
|
||
} else if ( output === 'sampler' ) { | ||
|
||
return textureProperty + '_sampler'; | ||
|
||
} else { | ||
|
||
const nodeData = builder.getDataFromNode( this ); | ||
|
||
let snippet = nodeData.snippet; | ||
|
||
if ( snippet === undefined ) { | ||
|
||
const uvSnippet = this.uvNode.build( builder, 'vec3' ); | ||
const biasNode = this.biasNode; | ||
|
||
if ( biasNode !== null ) { | ||
|
||
const biasSnippet = biasNode.build( builder, 'float' ); | ||
|
||
snippet = builder.getCubeTextureBias( textureProperty, uvSnippet, biasSnippet ); | ||
|
||
} else { | ||
|
||
snippet = builder.getCubeTexture( textureProperty, uvSnippet ); | ||
|
||
} | ||
|
||
nodeData.snippet = snippet; | ||
|
||
} | ||
|
||
return builder.format( snippet, 'vec4', output ); | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
|
||
CubeTextureNode.prototype.isCubeTextureNode = true; | ||
|
||
export default CubeTextureNode; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import Node from '../core/Node.js'; | ||
import { nodeObject, normalWorld, positionWorld, cameraPosition, sub, normalize, join, negate, reflect } from '../ShaderNode.js'; | ||
|
||
class ReflectNode extends Node { | ||
|
||
static VECTOR = 'vector'; | ||
static CUBE = 'cube'; | ||
|
||
constructor( scope = ReflectNode.CUBE ) { | ||
|
||
super( 'vec3' ); | ||
|
||
this.scope = scope; | ||
|
||
} | ||
|
||
getHash( /*builder*/ ) { | ||
|
||
return `reflect-${this.scope}`; | ||
|
||
} | ||
|
||
generate( builder ) { | ||
|
||
const scope = this.scope; | ||
|
||
if ( scope === ReflectNode.VECTOR ) { | ||
|
||
const cameraToFrag = normalize( sub( positionWorld, cameraPosition ) ); | ||
const reflectVec = reflect( cameraToFrag, normalWorld ); | ||
|
||
return reflectVec.build( builder ); | ||
|
||
} else if ( scope === ReflectNode.CUBE ) { | ||
|
||
const reflectVec = nodeObject( new ReflectNode( ReflectNode.VECTOR ) ); | ||
const cubeUV = join( negate( reflectVec.x ), reflectVec.yz ); | ||
|
||
return cubeUV.build( builder ); | ||
|
||
} | ||
|
||
} | ||
|
||
serialize( data ) { | ||
|
||
super.serialize( data ); | ||
|
||
data.scope = this.scope; | ||
|
||
} | ||
|
||
deserialize( data ) { | ||
|
||
super.deserialize( data ); | ||
|
||
this.scope = data.scope; | ||
|
||
} | ||
|
||
} | ||
|
||
export default ReflectNode; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.