-
-
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
Consider refactoring some of the code. #14031
Conversation
mrdoob#10750 Allows for adding stuff to commons chunk for example.
This reverts commit e73c718.
(Optional read)GoalConvenient, concise, declarative and robust interface to tweaking the GLSL code in the built-in materials (MeshPhongMaterial, MeshStandardMaterial etc.). With the broader goal to open doors for developers to write robust 3rd party modules for three.js. import makeFancyMaterial from 'make-fancy-material'
const myMaterial = makeFancyMaterial( new THREE.MeshStandardMatarial() )
Current state of the world.Monkey patchingThis basically comes down to mutating the Pros Cons onBeforeCompile callbackThis is a simple extension with the power to transform any shader in any way possible by providing the raw shader string before being parsed by three, and before being compiled by WebGL. Pros
Cons
const myMaterial = new AnyMaterial({foo:'foo'})
myMaterial.foo //'foo'
myMaterial.color // THREE.Color
const shaderMaterial = new ShaderMaterial(params)
shaderMaterial.uniforms.uFoo.value // THREE.Vector4
Copying templatesAnother common approach present in some examples and possibly on Stack Overflow, is to just copy the underlying shader template of a desired built-in material, and recreate the whole thing as a An example can be seen in the Also in the lambert instancing example: Pros
Cons
ProposalAchieve built-in material shader enhancements extensions by:
Pros
Cons
AskSince it doesn't conflict with anything, could it be available for a little while before Myself, i'd prefer more modularity, maybe in the (near?) future when Even as a rough example, the net gain is 224 lines removed from just a couple of examples. I believe there could be much more. |
cleanup add uniform stage destination
Here's an example of using a generic It's just a simple example, but the interesting thing i think is that it can be written with no knowledge of how the GLTFLoader works. The effect (simple halo) is agnostic of how PBR chooses to do it's lighting, and can apply to both. With the material includes prosal, both callbacks would be free when used with http://dusanbosnjak.com/test/webGL/gltf-without-onbeforerender/index.html With this one, using this approach can help draw the lines easily. |
As discussed last week, this PR has too many changes at once 😕 |
Hi, i propose an api that could help refactor and remove a lot of code from some of the examples and loaders and such. It's similar to
onBeforeCompile
, completely opt in and doesn't conflict with any existing functionality.@donmccurdy ?