-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
EXT_mesh_gpu_instancing #1691
Merged
Merged
EXT_mesh_gpu_instancing #1691
Changes from 19 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
76587d9
instancing extension
ultrafishotoy de031ed
cleanup
ultrafishotoy 5d2dac5
overview statement
ultrafishotoy ed5f6e6
tweak statements
ultrafishotoy a68dcf6
statement
ultrafishotoy 82b3adb
description
ultrafishotoy 1b4f9c3
typo
ultrafishotoy 956b01d
simple example
ultrafishotoy 62cf80a
syntax fix
ultrafishotoy 2ed4903
teapots galore
ultrafishotoy a833742
oops
ultrafishotoy 8b8e39a
example image
ultrafishotoy 66fa030
fix path
ultrafishotoy 332af44
update attribs to POSITION, ROTATION, and SCALE
ultrafishotoy 133d28d
rename extension
ultrafishotoy 3857fa7
updated POSITION attribute to TRANSLATION
ultrafishotoy d53d9c8
remove 'world space' language
ultrafishotoy b4854e9
new sample files
ultrafishotoy ea4c776
sample updated with rotation as a quaternion
ultrafishotoy c70f30e
latest sample files
ultrafishotoy 615652a
oops
ultrafishotoy 8d8f4a0
KHR_mesh_instancing -> EXT_mesh_gpu_instancing
eef3c13
Merge pull request #1 from donmccurdy/ultrafishotoy-EXT_mesh_gpu_inst…
ultrafishotoy 900ac06
moved to Vendor folder and renamed
ultrafishotoy 5984aa1
Merge branch 'KHR_instancing' of https://github.com/ultrafishotoy/glT…
ultrafishotoy dbd7b63
specify the types of the attributes
ultrafishotoy e0a458b
clean up readme.md
ultrafishotoy 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 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,64 @@ | ||
# KHR\_mesh\_instancing | ||
|
||
## Khronos 3D Formats Working Group | ||
|
||
* John Cooke | ||
* Don McCurdy | ||
* Arseny Kapoulkine | ||
|
||
## Acknowledgments | ||
|
||
* TODO | ||
|
||
## Status | ||
|
||
Experimental | ||
|
||
## Dependencies | ||
|
||
Written against the glTF 2.0 spec. | ||
|
||
## Overview | ||
|
||
This extension is specfically designed to enable GPU instancing which renders many copies of a single mesh at once using a small number of draw calls. It's useful for things | ||
like trees, grass, road signs, etc. The TRANSLATION, ROTATION, and SCALE attributes allows the mesh to be displayed at many different locations with different rotations and scales. | ||
Custom attributes can use the underscore mechanism to achieve other effects (i.e. _ID, _TRANSFORM4x3, etc.). | ||
|
||
## Extending Nodes with per instance attributes | ||
|
||
Instancing is defined by adding the `KHR_mesh_instancing` extension to any glTF node that has a mesh. Instancing only applies to mesh nodes, there is no defined behavior for a node | ||
with this extension that doesn't also have a mesh. Applying to nodes rather than meshes allows the same mesh to be used by several nodes, instanced or otherwise. The attributes | ||
section contains accessor ids for the TRANSLATION, ROTATION, and SCALE attribute buffers, all of which are optional. The attributes specify an object space transform that should be | ||
multipled by the node's world transform in the shader to produce the final world transform for the instance. For example, the following defines some instancing attributes to a node with mesh. | ||
|
||
```json | ||
{ | ||
"nodes": [ | ||
{ | ||
"mesh": 0, | ||
"name": "teapot", | ||
"extensions": { | ||
"KHR_mesh_instancing": { | ||
"attributes": { | ||
"TRANSLATION": 0, | ||
"ROTATION": 1, | ||
"SCALE": 2, | ||
}, | ||
} | ||
} | ||
} | ||
] | ||
} | ||
``` | ||
|
||
## Appendix | ||
|
||
TODO | ||
|
||
## Reference | ||
|
||
TODO | ||
|
||
### Theory, Documentation and Implementations | ||
|
||
TODO |
148 changes: 148 additions & 0 deletions
148
...sions/2.0/Khronos/KHR_mesh_instancing/samples/teapots_galore_T4x3_custom/Gltf2Builder.log
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,148 @@ | ||
Gltf output: C:/otoyla/exports/octane/teapots_galore_T4x3/teapots_galore_T4x3.gltf | ||
Node : Thin lens camera | ||
node setTransforms Thin lens camera 1 | ||
node addNode Thin lens camera | ||
[Camera] converted camera Thin lens camera | ||
Node : Placement | ||
node setTransforms Placement 1 | ||
node addNode Placement | ||
Node : Scatter | ||
node setTransforms Scatter 958 | ||
node addNode Scatter | ||
Node : Placement_1 | ||
node setTransforms Placement_1 1 | ||
node addNode Placement_1 | ||
getMaterialChannelColor specular 1.000000,1.000000,1.000000 | ||
getMaterialChannelColor opacity 1.000000,1.000000,1.000000 | ||
getMaterialChannelColor index 0.000000,0.000000,0.000000 | ||
getMaterialChannelColor roughness 0.063200,0.063200,0.063200 | ||
Raw2Gltf_Material::start cube | ||
material 130 NT_MAT_UNIVERSAL | ||
Raw2Gltf_Material::end cube | ||
Raw2Gltf_Mesh::Release | ||
SetNormals = 12096 | ||
Raw2Gltf_Mesh::SetObjectIndices nil | ||
scale_value 1.000000 | ||
Raw2Gltf_Mesh::Normalize | ||
material 0 = cube | ||
maximum_index = 0 | ||
IN MESH 0 = teapot:cube | ||
OUT MESH teapot | ||
OUT PRIM 0 = (null) | ||
OPTIMIZED mesh teapot 12096 = 0 | ||
verts = 12096 | ||
norms = 12096 | ||
uvws = 0 | ||
mesh material cube | ||
node addNode teapot | ||
Raw2Gltf_Mesh::Release | ||
Node : Scatter_1 | ||
node setTransforms Scatter_1 941 | ||
node addNode Scatter_1 | ||
Node : Placement_2 | ||
node setTransforms Placement_2 1 | ||
node addNode Placement_2 | ||
getMaterialChannelColor specular 1.000000,1.000000,1.000000 | ||
getMaterialChannelColor opacity 1.000000,1.000000,1.000000 | ||
getMaterialChannelColor index 0.000000,0.000000,0.000000 | ||
getMaterialChannelColor roughness 0.063200,0.063200,0.063200 | ||
Raw2Gltf_Material::start cube_1 | ||
material 130 NT_MAT_UNIVERSAL | ||
Raw2Gltf_Material::end cube_1 | ||
Found existing mesh teapot | ||
Node : teapot0 | ||
node setTransforms teapot0 1 | ||
node addNode teapot0 | ||
Node : Placement_3 | ||
node setTransforms Placement_3 1 | ||
node addNode Placement_3 | ||
getMaterialChannelColor diffuse 0.158000,0.107000,0.094000 | ||
getMaterialChannelColor specular 0.115000,0.115000,0.115000 | ||
getMaterialChannelColor opacity 1.000000,1.000000,1.000000 | ||
getMaterialChannelColor index 0.000000,0.000000,0.000000 | ||
getMaterialChannelColor roughness 0.134694,0.134694,0.134694 | ||
Raw2Gltf_Material::start cube_2 | ||
material 16 NT_MAT_GLOSSY | ||
Raw2Gltf_Material::end cube_2 | ||
Raw2Gltf_Mesh::Release | ||
SetUwvs = 4 | ||
Raw2Gltf_Mesh::SetObjectIndices nil | ||
scale_value 1.000000 | ||
Raw2Gltf_Mesh::Normalize | ||
material 0 = cube_2 | ||
maximum_index = 0 | ||
IN MESH 0 = plane:cube_2 | ||
OUT MESH plane | ||
OUT PRIM 0 = (null) | ||
BUILD NORMALS | ||
OPTIMIZED mesh plane 4 = 0 | ||
verts = 4 | ||
norms = 4 | ||
uvws = 4 | ||
mesh material cube_2 | ||
node addNode plane | ||
Raw2Gltf_Mesh::Release | ||
post processing enabled = Off | ||
post bloom power = 0.000000 | ||
post glare power = 0.000000 | ||
post glare ray amount = 0.000000 | ||
post glare angle = 0.000000 | ||
film resolution = 0.000000,0.000000 | ||
sun dir = 0.000000,0.000000,0.000000 | ||
sun power = 0.000000 | ||
sun north offset = 0.000000 | ||
sky model = 0 | ||
sun color = 0.000000,0.000000,0.000000 | ||
sun size = 0.000000 | ||
ground color = 0.000000,0.000000,0.000000 | ||
env radius = 0.000000 | ||
cam fovX = 0.000000 | ||
cam near = 0.000000 | ||
cam far = 0.000000 | ||
cam autofocus = 0 | ||
cam focal depth = 0.000000 | ||
cam aperture = 0.000000 | ||
cam pos = 0.000000,0.000000,0.000000 | ||
cam target = 0.000000,0.000000,0.000000 | ||
cam up = 0.000000,0.000000,0.000000 | ||
imager exposure = 0.000000 | ||
imager highli = 0.000000 | ||
imager response = 0 | ||
imager gamma = 0.000000 | ||
imager whitebalance = 0.000000,0.000000,0.000000 | ||
imager vignetting = 0.000000 | ||
imager saturation = 0.000000 | ||
kernel datapinid = 108 | ||
kernel datapinid = 61 | ||
kernel datapinid = 221 | ||
kernel datapinid = 66 | ||
kernel datapinid = 29 | ||
kernel datapinid = 144 | ||
kernel datapinid = 50 | ||
kernel datapinid = 7 | ||
kernel datapinid = 3 | ||
kernel datapinid = 381 | ||
kernel datapinid = 2 | ||
kernel datapinid = 86 | ||
kernel datapinid = 386 | ||
kernel datapinid = 384 | ||
kernel datapinid = 435 | ||
kernel datapinid = 434 | ||
kernel datapinid = 433 | ||
kernel datapinid = 129 | ||
kernel datapinid = 25 | ||
kernel datapinid = 223 | ||
kernel datapinid = 273 | ||
kernel datapinid = 267 | ||
kernel datapinid = 270 | ||
kernel datapinid = 347 | ||
kernel datapinid = 349 | ||
kernel datapinid = 351 | ||
kernel datapinid = 350 | ||
kernel datapinid = 353 | ||
kernel datapinid = 263 | ||
kernel datapinid = 446 | ||
kernel datapinid = 266 | ||
kernel datapinid = 264 | ||
kernel datapinid = 368 | ||
kernel datapinid = 448 |
Binary file added
BIN
+331 KB
extensions/2.0/Khronos/KHR_mesh_instancing/samples/teapots_galore_T4x3_custom/mesh.bin
Binary file not shown.
Binary file added
BIN
+152 Bytes
extensions/2.0/Khronos/KHR_mesh_instancing/samples/teapots_galore_T4x3_custom/mesh_2.bin
Binary file not shown.
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.
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.
Is there a reason we do not specify the instance count in the extension? I can foresee this causing security vulnerabilities in native loaders due to malformed/mismatched accessor counts for the different attributes.
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.
This follows existing convention from the core spec:
mesh.primitive.attributes
relies onaccessor.count
being the same for all attributes. Having a dedicated property to signal the instance count does not add much value here as implementations would still need to check that it's less than or equal to eachaccessor.count
.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.
Makes sense, it wouldn't be wise to break from the convention here.
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.
A possible counterargument is that with the core
mesh
definition, thePOSITION
attribute is required. Here, none of the attributes are required, and implementations might need even need to look to the custom attributes to find the actual instance count. In the three.js implementation this becomes:That's a little ugly, but not burdensome in our case. But if other implementations think it's useful to know the count more directly I wouldn't be opposed to putting it in the extension.