-
-
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
custom defines to default materials #10764
Comments
It's doable: THREE.ShaderLib[ 'phong' ].fragmentShader = THREE.ShaderLib[ 'phong' ].fragmentShader.replace(
"gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
"#ifndef CUSTOM\n\
gl_FragColor = ( gl_FrontFacing ) ? vec4( outgoingLight, diffuseColor.a ) : diffuseColor;\n\
#else\n\
gl_FragColor = ( gl_FrontFacing ) ? vec4( outgoingLight, diffuseColor.a ) : vec4( diffuse, opacity );\n\
#endif"
); Usage: var material = new THREE.MeshPhongMaterial( { color: 0xff0000 } );
material.defines = material.defines || {};
material.defines.CUSTOM = ""; |
ooh nice i didnt know about this, |
I've yet to take it for a spin, but this is super nice. What could be done about shadows though? |
Hmm.. its not entirely flexible, i'm not sure where to put my attributes. I'm trying to append it to common, but it's present in both frag and vert. I see that gamma is always defined for fragment, so maybe look for that? Or use something like color_pars_vertex.glsl? edit piggybacking on color_pars_vertex works like a charm, but i notice its not present in depth_vertex. @WestLangley, could we perhaps globally add Could change this pull to test the geometry for InstancedBufferGeometry? I'm not sure though if it would need all the flags, should instances be drawn while skinned and morphed? |
So, i was able to completely pull of what i had in mind with zero hacking thanks to three undocumented features.
|
Description of the problem
I've got a couple of effects i've tried to implement on top of three.js but in order to get them to work with default materials or shadows, i needed to hack the
WebGLRenderer
. In r78, i could just override a few functions (likeWebGLPrograms
) and inject some GLSL.In 84 this seems impossible, there is no THREE namespacing so
THREE.Vector3
isVector3
,THREE.WebGLPrograms
is undefined etc.See this for more details.
The other use case i'd have is for adding custom TBN information, and unpacking it.
This all got me thinking, shadows aside, could there be a mechanism to inject custom logic into the default materials? Something like:
Then have the program figure out what needs to be done, does it take a chunk from cache, or the provided one, does it inject attributes, or just a define etc.
The shadowmap only needs the position information, no normals, so in case of a custom TBN or transformation it would only care about transformation. Perhaps this could be used with
useSkinning
anduseMorphing
but it would require on settling for a "transformation" flag of sorts to always be included.Just a thought.
Three.js version
Browser
OS
Hardware Requirements (graphics card, VR Device, ...)
The text was updated successfully, but these errors were encountered: