-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
Add Instancing with built-in material example #16161
Conversation
'attribute vec4 instanceMatrixColumn1;', | ||
'attribute vec4 instanceMatrixColumn2;', | ||
'attribute vec4 instanceMatrixColumn3;' | ||
].join( '\n' ) + '\n'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can rewrite to attribute mat4 instanceMatrix;
if we merge #16141
shader.fragmentShader = shader.fragmentShader | ||
.replace( '#include <common>\n', '#include <common>' + fragmentParsChunk ) | ||
.replace( 'vec4 diffuseColor = vec4( diffuse, opacity );\n', colorChunk ) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: As you know code injection may be fragile because if we update built-in material it can fail. Node-based system can do more safely.
No one is interested in? Does it sound hacky? |
TBH, I think the existing examples ( |
What do you think of replacing them with this? I think this example shows easier and more practical way of using instancing with built-in material, dynamic objects, and Shadow. For example, this example doesn't require |
I think there's quite a bit going on in this example to replace the
This was already done here #14098. (It only shows how to use the
These two were addressed here #10750. They're focused only on instancing, not the
There are also add on libraries in the wild that do all this already along with articles and tutorials on both instancing and material extensions using Note, these two cents of mine are specifically re: replacing the examples. I'd keep them around. |
Closing in favor of #17505. |
@takahirox Awesome demo though! I just want to get away from the |
Thanks! I'm happy to know that somehow I helped to get InstancedMesh into core! Yeah, Mesh level API should be much simpler. |
Demo: https://raw.githack.com/takahirox/three.js/InstancingStandard/examples/#webgl_buffergeometry_instancing_standard
This example shows
InstancedBufferGeometry
from regularBufferGeometry
.material.onBeforeCompile()
to built-inMeshStandardMaterial
andMeshDepthMaterial
shaders.InstancedMesh
class controlling instance transform withObject3D.position/rotation(quaternion)/scale
API.webgl_buffergeometry_instancing_lambert
andwebgl_buffergeometry_instancing_dynamic
examples may be for similar purpose. I think this example shows easier and more practical to use.I don't do in this example, but I locally accomplished instanced
SkinnedMesh
with similar way.https://twitter.com/superhoge/status/1112314633543737344
About code injection, if we introduce Node-based material system, I think that will be easier and safer.
I hope this example can be a good start to discuss mesh-level instancing API. I think it'll be easier for users to use instancing on Three.js if we have.