How to make the face of the model facing down to use another color?

node.material.onBeforeCompile=(shader)=>{


shader.vertexShader=shader.vertexShader.replace(
"void main() {",
`varying float green;
void main() {`
)


shader.vertexShader=shader.vertexShader.replace(
"}",
`if(normal.y<0.0 && position.y<-0.2){ green=1.0; }
}`
)


shader.fragmentShader=shader.fragmentShader.replace(
"void main() {",
`varying float green;
void main() {`
)
shader.fragmentShader=shader.fragmentShader.replace(
"#include <dithering_fragment>",
`#include <dithering_fragment>
if(green==1.0){ gl_FragColor.rgb=vec3(0.0,1.0,0.0); }
`
)

};


image

1 Like

Maybe you can add custom lightmap and paint it

Thank you for your answer, I found that it is all written in onBeforeCompile now. If the model has transformation, should it be using shaderMaterial?

custom lightmap, will it still be affected by the shadow of the light?

That example not reacting to transformations - scale, rotation, moving.
For affecting we can add green in map texture in shader.
For not affecting - adding green at the end of all like in example.

node.material..onBeforeCompile=(shader)=>{

shader.vertexShader=shader.vertexShader.replace(
"void main() {",
`varying float green;
void main() {`
)


shader.vertexShader=shader.vertexShader.replace(
"}",
`if(normal.y<0.0 && position.y<-0.2){ green=1.0; }
}`
)


shader.fragmentShader=shader.fragmentShader.replace(
"void main() {",
`varying float green;
void main() {`
)
shader.fragmentShader=shader.fragmentShader.replace(
"#include <map_fragment>",
`#include <map_fragment>
if(green==1.0){ diffuseColor.rgb=vec3(0.0,1.0,0.0); }
`
)

};

Didnt undertood.
Do you want to modify the material of the model?

Yes modify

This demo is a model I use casually. In my project, the model has no material.

Projects, models can use any material

Updated online demo, it can be ShaderMaterial
https://codesandbox.io/s/goofy-sky-fsmr5h?file=/src/App.vue

@a627247084
What benefits of the using of ShaderMaterial?
And why .onBeforeCompile on any default material is not an option?

It should be possible to do reacting to transformations - scale, rotation, moving.
Can shadermaterial do it?

@a627247084 To be honest, I still don’t understand what behaviour you want to achieve.
Does the green color have always highlight lower part, no matter what transform the model has?
Or does it have to follow transformations (rotation, for example)?

Here: How to make the face of the model facing down to use another color? - #18 by prisoner849, there are two options, that demonstrate behaviour for both cases.

And here you’ve been provided with a good solution: How to make the face of the model facing down to use another color? - #22 by Chaser_Code And the fact, that the model is coloured vertically, means that it’s already rotated.

thanks a lot for your answer.
The green color have always highlight lower part, no matter what transform the model has.
But in the process, the transformation controller will be used to change the model, here the green still has to highlight the lower part

I think, the thread starter is thinking of the model’s footprint, however that may be orientated in space.

His initial illustration resembles a lower jaw casting having a flat bottom-plane surface.