-
-
Notifications
You must be signed in to change notification settings - Fork 35.6k
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
[WIP] tiny api and example how to combine material extensions #14206
Conversation
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 |
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
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
,WebGLProgram
andWebGLPrograms
.)onBeforeCompile
API 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
instanceOffset
andinstanceScale
, 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 extensioninstanceScale
and use my ownaIndex
. If this logic is hidden inonBeforeCompile
my hands are tied, but if this were in its ownparseGlobalsVertex
chunk then i'd have the "compiled" (parsed/unrolled) string, and i could replace this. Anyway this takes theinstanced_lambert
example 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.