[WIP] tiny api and example how to combine material extensions#14206
Closed
pailhead wants to merge 27 commits intomrdoob:devfrom
Closed
[WIP] tiny api and example how to combine material extensions#14206pailhead wants to merge 27 commits intomrdoob:devfrom
pailhead wants to merge 27 commits intomrdoob:devfrom
Conversation
Contributor
Author
|
If someone feels really strongly that http://dusanbosnjak.com/test/webGL/three-material-includes/webgl_loader_gltf_extensions.html if(sceneInfo.name === 'BoomBox (PBR)'){
// only one line
decorateMaterialWithSimpleInstancing(object.children[0].material)
// geometry stuff
const size = 64
const size_inv = 1/size
const instances = size * size
const scale = 1
const instancePositionArray = new Float32Array( instances * 3 )
const instanceScaleArray = new Float32Array( instances * 3 )
for ( var i = 0, ii = 0 ; i < instances ; i++ ){
instanceScaleArray[ii] = 1
instancePositionArray[ii++] = ((i % size) * size_inv-0.5) * scale
instanceScaleArray[ii] = 1
instancePositionArray[ii++] = 0
instanceScaleArray[ii] = 1
instancePositionArray[ii++] = (Math.floor(i*size_inv) * size_inv-0.5) * scale
}
object.children[0].geometry = new THREE.InstancedBufferGeometry().copy(object.children[0].geometry)
object.children[0].geometry.addAttribute( 'instanceOffset', new THREE.InstancedBufferAttribute(instancePositionArray, 3))
object.children[0].geometry.addAttribute( 'instanceScale', new THREE.InstancedBufferAttribute(instanceScaleArray, 1))
object.children[0].geometry.maxInstancedCount = instances
object.children[0].frustumCulled = false
}^btw don't know how heavy the boombox is but it seems somewhat high poly, my air is chugging, my 1080 blazed through it |
Closed
Contributor
Author
This was referenced Jun 7, 2018
refactor modified refactor GLTFLoader
add env map and deferedd update?
it looks up .a which the map didnt have, specular is more illustrative
say that the three features are provided from an npm module or something, an example how to further "inline" extend it
3dfd832 to
1d7ee68
Compare
Owner
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
I made a simple example that consolidates a few features that have been discussed over the years, with a bit of help from some core changes. (around 30 lines of core added/changed to
WebGLRenderer,WebGLProgramandWebGLPrograms.)onBeforeCompileAPI but still using the "shader injection" approach.http://dusanbosnjak.com/test/webGL/three-material-includes/
The example js file contains all three of these extensions, but they could be in their own files.
The code required to extend the first 2 is:
These then become immediately available:
actually has a conflict with the chunk names, and has a couple of lines to solve that, but it works. If the templates could be restructured a bit to give a bit more separation, these would come up in fewer places i think
is just illustrative, it's a simple example and the contract between the extension and geometry is
instanceOffsetandinstanceScale, the code just turns the geometry and adds these attributes. I'm not entirely sure why Instanced mesh #10750 was shelved, but this kind of an api would make a 3rd party package like this https://www.npmjs.com/package/three-instanced-mesh much more flexible and powerful.is an "inline" example on how to extend the stuff thats already extended and illustrates a drawback of
onBeforeCompile. I wanted to remove an attribute from an extensioninstanceScaleand use my ownaIndex. If this logic is hidden inonBeforeCompilemy hands are tied, but if this were in its ownparseGlobalsVertexchunk then i'd have the "compiled" (parsed/unrolled) string, and i could replace this. Anyway this takes theinstanced_lambertexample and combines it with spec/gloss, multi uvs, and further modifies it on top of it (materials_modified).A huge upside of this approach is that i can spend all my time in a text editor, without having to zoom and pan and click through a visual editor.