NodeMaterial: Instancing API
See original GitHub issueI believe NodeMaterial could support an expressive instancing API, without requiring users to modify builtin shaders. The instancing • lambert example shows the simplest pre-existing approach, and is still complex enough that users will find it challenging to instance a 3D model created in a DCC tool.
Proposal:
import * as THREE from 'three';
import {
StandardNodeMaterial,
InstanceTransformNode,
AttributeNode,
FloatNode,
OperatorNode,
TextureNode
} from 'three/js/nodes/THREE.Nodes';
var material = new StandardNodeMaterial();
// Configure shared material properties as usual.
material.metalness = new FloatNode( 0 );
// Configure material.instanceTransform to reference 1-3 InstancedBufferAttribute nodes.
material.instanceTransform = THREE.InstanceTransformNode(
new AttributeNode( 'instancePosition', 'vec3' ),
new AttributeNode( 'instanceQuaternion', 'vec4' ),
new AttributeNode( 'instanceScale', 'vec3' )
);
// Configure per-instance material properties using node expressions and InstancedBufferAttribute.
material.roughness = new AttributeNode( 'instanceRoughness' );
material.color = new OperatorNode(
new TextureNode( baseColorTexture ),
new AttributeNode( 'instanceColor' ),
OperatorNode.MUL
);
With this API, and as loaders enable the NodeMaterial system, instancing models created in DCC tools becomes much easier:
var treePositions = new Float32Array( [
0, 0, 0,
10, 0, 0,
20, 0, 0
] );
var loader = new THREE.GLTFLoader();
loader
.setUseNodes( true )
.load( 'tree.glb', ( gltf ) => {
var model = gltf.scene.children[ 0 ];
model.geometry = new THREE.InstancedBufferGeometry().fromBufferGeometry( model.geometry );
model.geometry.addAttribute( 'instancePosition', new THREE.InstancedBufferAttribute( treePositions, 3 );
model.material.instanceTransfom = new THREE.InstanceTransformNode( THREE.AttributeNode( 'instancePosition' ) );
scene.add( model );
} );
This idea is based loosely on noticing recently that Unity plans to add instancing support to its Shader Graph master nodes.
/cc @sunag
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:5
Top Results From Across the Web
NodeMaterial - Babylon.js Documentation
Class used to create a node based material built by assembling shader blocks [API]
Read more >Custom Nodes in the Node Material Editor: Part 1 - YouTube
In this video, Jason walks us through solving a common workflow problem in the Node Material Editor, while giving us a look at...
Read more >Nodes API : Cinema 4D C++ SDK
The Nodes API consists of multiple frameworks that includes the public declarations of interfaces and other usable classes, structures and ...
Read more >Geometry Nodes: Set Different Material on Each Instance
I'm trying to set a different existing material on 5 Instances made with Instance on Points. Trying both 3.0.1 and 3.1 to no...
Read more >Help | Node Material | Autodesk - Autodesk Knowledge Network
The reference shader allows you to include another material, either a Node Material or an old Arnold Material within the graph. For instance,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I can make an example as soon as possible.
This is working quite nicely now that #15666 is fixed. Doesn’t seem like a new
InstanceTransformNode
API is necessary. 😎