-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
NodeMaterial: CubeTexture WebGPU and WebGL #23743
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
Merged
Merged
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
cd07d3d
fix camera ref
sunag 120fbf6
add viewMatrix, cameraPosition and cleanup
sunag 2365686
fi texture parameter
sunag 898ebe3
add getCubeTexture() and bias API update
sunag 44b9840
WebGLNodeBuilder: update bias API
sunag c762a5f
fix refresh uniforms of shared materials
sunag 4ea828b
add WebGPUNodeSampledCubeTexture
sunag 6c62b26
WebGPURenderer: CubeTexture support
sunag 3ccbca1
TextureNode: update bias API
sunag 056a6af
add CubeTextureNode and ReflectNode
sunag cefd269
update examples
sunag 4498f37
Revert "WebGPURenderer: CubeTexture support"
sunag facf793
Revert "Revert "WebGPURenderer: CubeTexture support""
sunag e2872eb
Merge branch 'dev' into dev-cubemap
sunag 1b548c6
fix default value of baseArrayLayer
sunag a231d53
CubeTextureNode instanceof of TextureNode
sunag File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,100 @@ | ||
| import UniformNode from '../core/UniformNode.js'; | ||
| import ReflectNode from './ReflectNode.js'; | ||
|
|
||
| class CubeTextureNode extends UniformNode { | ||
|
|
||
| constructor( value, uvNode = new ReflectNode(), biasNode = null ) { | ||
|
|
||
| super( value, 'vec4' ); | ||
|
|
||
| this.uvNode = uvNode; | ||
| this.biasNode = biasNode; | ||
|
|
||
| } | ||
|
|
||
| getUniformHash( /*builder*/ ) { | ||
|
|
||
| return this.value.uuid; | ||
|
|
||
| } | ||
|
|
||
| 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 = super.generate( 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 ); | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| serialize( data ) { | ||
|
|
||
| super.serialize( data ); | ||
|
|
||
| data.value = this.value.toJSON( data.meta ).uuid; | ||
|
|
||
| } | ||
|
|
||
| deserialize( data ) { | ||
|
|
||
| super.deserialize( data ); | ||
|
|
||
| this.value = data.meta.textures[ data.value ]; | ||
|
|
||
| } | ||
|
|
||
| } | ||
|
|
||
| CubeTextureNode.prototype.isCubeTextureNode = true; | ||
|
|
||
| export default CubeTextureNode; | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.