-
-
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
Direct support for Decal textures like bump and color texture #12977
Comments
You can monkey-patch decal support using a pattern like the following: THREE.ShaderChunk.map_fragment = THREE.ShaderChunk.map_fragment.replace(
`diffuseColor *= texelColor;`,
`
#ifndef DECAL
diffuseColor *= texelColor;
#else
diffuseColor = vec4( mix( diffuse, texelColor.rgb, texelColor.a ), opacity );
#endif
`
); Usage: var material = new THREE.MeshPhongMaterial( { // or Basic, Lambert, Standard, Physical
color: 0xff0000,
map: texture
} );
material.defines = material.defines || {};
material.defines.DECAL = ""; // set as needed If there is interest, we can support this feature via either a |
Hello Team, Thank you very much.. This solution worked for us. Also, it would be really great if something like material.decalMap existed, so that we could apply both color texture and decal texture on the same face. Thanks. |
You can use the approach explained in this post to do that. |
Any chance you could give some thoughts on why you're suggesting this:
Rather than using Why would you monkey patch this and override it globally?
Three doesn't have that specific map with that specific name, but it has #11475 which allows you to add any map to any existing shader. However, i think the API is slightly different than what's suggested above. Rather than somehow constructing a chunk, and have three just use it, you have to know a bit non-GLSL syntax like //step 1
const myModifiedChunk = THREE.ShaderChunk.some_chunk.replace('some glsl', 'my glsl')
//step 2
myModifiedMaterial.onBeforeCompile = shader=>{ shader.vertexShader.replace('#include <some_chunk>', myModifiedChunk) } |
Because it was easy.
The built-in materials still work as they did prior to the monkey patch, and the new decal feature works with multiple built-in materials. |
Easy for this specific example, or easy overall? Would you do this instead of the |
I did not give it that much thought. |
Closing. Using Material.onBeforeCompile seems the best way to extend built-in materials with such small enhancements. The introduction of a separate Alternatively, |
Hello team,
This is a feature request:
I was wondering if there is a possible way in three.js to implement decal textures directly like bump and color texture.
Let's say I have a JSON file containing a cube with 6 faces, one of its face has a decal texture (a .png image with part of image transparent) and a color (red),
Once load it into three.js scene, we can see both decal texture and color behind it.
Thanks.
The text was updated successfully, but these errors were encountered: