Hi,
I am reffering to this method stackoverflow to easily let clipped objects appear capped by changing the fragmentShader before it compiles.
(I changed to this method rather than making stencils because I have multiple Objects with different capping-Colors, where I have got lost with all the stencilBuffers and renderOrders.)
It works well with:
material.onBeforeCompile = function( shader ) {
shader.fragmentShader = shader.fragmentShader.replace(
'#include <output_fragment>',
`
vec3 backfaceColor = vec3( 0.4, 0.4, 0.4 );
gl_FragColor = ( gl_FrontFacing ) ? vec4( outgoingLight, diffuseColor.a ) : vec4( backfaceColor, opacity );
`
)
};
However, I need to be able to modify the capping Color dynamically, because I will have multiple objects with different Colors, like so: (In my opinion, dead simple)
const color = new THREE.Color("#ff0000");
material.onBeforeCompile = function( shader ) {
shader.fragmentShader = shader.fragmentShader.replace(
'#include <output_fragment>',
`
vec3 backfaceColor = vec3( ` + parseFloat(color.r).toFixed(2) + `, ` + parseFloat(color.g).toFixed(2) + `, ` + parseFloat(color.b).toFixed(2) + `);
gl_FragColor = ( gl_FrontFacing ) ? vec4( outgoingLight, diffuseColor.a ) : vec4( backfaceColor , opacity );
`
)
};
The second approach was to set up some uniforms in the beginning.
Unfortunately neither method did not work - I guess my GLSL-Shaderskills are too poor!
Thanks for your help in advance.
Amlis