forked from mrdoob/three.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WebGPURenderer: MorphNode 1/2 and updates (mrdoob#26325)
* Added: instancedBufferAttribute() and instancedDynamicBufferAttribute() * TSL: vertexIndex * Background: Fix color conversion * NodeMaterial: Added flatShading * Added MorphNode * Added `webgpu_morphtargets` example * Update examples/jsm/nodes/accessors/BufferAttributeNode.js Co-authored-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com> --------- Co-authored-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com>
- Loading branch information
Showing
17 changed files
with
402 additions
and
65 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
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import Node, { addNodeClass } from '../core/Node.js'; | ||
import { NodeUpdateType } from '../core/constants.js'; | ||
import { nodeProxy } from '../shadernode/ShaderNode.js'; | ||
import { uniform } from '../core/UniformNode.js'; | ||
import { reference } from './ReferenceNode.js'; | ||
import { bufferAttribute } from './BufferAttributeNode.js'; | ||
import { positionLocal } from './PositionNode.js'; | ||
|
||
class MorphNode extends Node { | ||
|
||
constructor( mesh ) { | ||
|
||
super( 'void' ); | ||
|
||
this.mesh = mesh; | ||
this.morphBaseInfluence = uniform( 1 ); | ||
|
||
this.updateType = NodeUpdateType.OBJECT; | ||
|
||
} | ||
|
||
constructAttribute( builder, name, assignNode = positionLocal ) { | ||
|
||
const mesh = this.mesh; | ||
const attributes = mesh.geometry.morphAttributes[ name ]; | ||
|
||
builder.stack.assign( assignNode, assignNode.mul( this.morphBaseInfluence ) ); | ||
|
||
for ( let i = 0; i < attributes.length; i ++ ) { | ||
|
||
const attribute = attributes[ i ]; | ||
|
||
const bufferAttrib = bufferAttribute( attribute.array, 'vec3' ); | ||
const influence = reference( i, 'float', mesh.morphTargetInfluences ); | ||
|
||
builder.stack.assign( assignNode, assignNode.add( bufferAttrib.mul( influence ) ) ); | ||
|
||
} | ||
|
||
} | ||
|
||
construct( builder ) { | ||
|
||
this.constructAttribute( builder, 'position' ); | ||
|
||
} | ||
|
||
update() { | ||
|
||
const morphBaseInfluence = this.morphBaseInfluence; | ||
|
||
if ( this.mesh.geometry.morphTargetsRelative ) { | ||
|
||
morphBaseInfluence.value = 1; | ||
|
||
} else { | ||
|
||
morphBaseInfluence.value = 1 - this.mesh.morphTargetInfluences.reduce( ( a, b ) => a + b, 0 ); | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
|
||
export default MorphNode; | ||
|
||
export const morph = nodeProxy( MorphNode ); | ||
|
||
addNodeClass( MorphNode ); |
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,66 @@ | ||
import Node, { addNodeClass } from './Node.js'; | ||
import { varying } from './VaryingNode.js'; | ||
import { nodeImmutable } from '../shadernode/ShaderNode.js'; | ||
|
||
class IndexNode extends Node { | ||
|
||
constructor( scope ) { | ||
|
||
super( 'uint' ); | ||
|
||
this.scope = scope; | ||
|
||
this.isInstanceIndexNode = true; | ||
|
||
} | ||
|
||
generate( builder ) { | ||
|
||
const nodeType = this.getNodeType( builder ); | ||
const scope = this.scope; | ||
|
||
let propertyName; | ||
|
||
if ( scope === IndexNode.VERTEX ) { | ||
|
||
propertyName = builder.getVertexIndex(); | ||
|
||
} else if ( scope === IndexNode.INSTANCE ) { | ||
|
||
propertyName = builder.getInstanceIndex(); | ||
|
||
} else { | ||
|
||
throw new Error( 'THREE.IndexNode: Unknown scope: ' + scope ); | ||
|
||
} | ||
|
||
let output; | ||
|
||
if ( builder.shaderStage === 'vertex' || builder.shaderStage === 'compute' ) { | ||
|
||
output = propertyName; | ||
|
||
} else { | ||
|
||
const nodeVarying = varying( this ); | ||
|
||
output = nodeVarying.build( builder, nodeType ); | ||
|
||
} | ||
|
||
return output; | ||
|
||
} | ||
|
||
} | ||
|
||
IndexNode.VERTEX = 'vertex'; | ||
IndexNode.INSTANCE = 'instance'; | ||
|
||
export default IndexNode; | ||
|
||
export const vertexIndex = nodeImmutable( IndexNode, IndexNode.VERTEX ); | ||
export const instanceIndex = nodeImmutable( IndexNode, IndexNode.INSTANCE ); | ||
|
||
addNodeClass( IndexNode ); |
This file was deleted.
Oops, something went wrong.
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
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.