question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NodeMaterial: Instancing API

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:5

github_iconTop GitHub Comments

2reactions
sunagcommented, Sep 16, 2018

I can make an example as soon as possible.

0reactions
donmccurdycommented, Feb 23, 2019

This is working quite nicely now that #15666 is fixed. Doesn’t seem like a new InstanceTransformNode API is necessary. 😎

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found