Hi
I’m trying to make a NodeMaterial that will make a cube completely black or white based on the angle of the camera.
But I can’t get this to work for the whole mesh and groups of mesh.
The View direction block is based on camera position and world position. But I think I need to know the value of the angle (ideally camera beta angle) between the camera and its target.
Can I have some help with this?
Cause at the moment I got like a white circle that is slowly covering a mesh. Ideally will like to have a slowly changing color from white to black based on camera beta angle but not in a circle shape but evenly on the whole mesh. cause now I got this smooth gradient and objects on the edges of the viewport behave differently.
And I can’t put a value to material InputBlock. Will like this to be sorted inside the shader entirely.
Regards
Peter
@Evgeni_Popov is now my NME king so I bet he ll know this on the top of his head
There’s not something like an angle between a camera (view direction) and a target. To define an angle, you need another vector. You can use the normal of the face and use the dot product with the view direction to compute a color, but the result will be per face:
https://playground.babylonjs.com/#Z5XCVV#2
Hi @Evgeni_Popov
Thanks for the quick replay. But this still produces a big circle effect for me. Is there a way to overcome this?
When you add smooth step at the end its still produce a circular gradient instead on fully one color faces.
Regards
Peter
What do you mean by big circle effect?
What I see from my PG:
I think I don’t really get what you want to achieve…
Hi @Evgeni_Popov
I see this:
With a spherical gradient from the center of the view.
I resaved PG as the next version:
https://playground.babylonjs.com/#Z5XCVV#5
Also added a step to see it clearer: It’s like a creepy eye now LOL:
Regards
Peter
Ok, but what do you want to achieve exactly? How each cube should be colored?
I need to know the value of the angle (ideally camera beta angle) between the camera and its target
I don’t understand what can be the angle between the camera and the target: can you elaborate?
Hi @Evgeni_Popov
I want to change the color of a face in one go. So if it’s becoming white, the whole face should become white.
so instead of that circle line moving toward the end of the face, I need to take over the whole face in one go.
Now, this border is ok for cubes in the center of the screen but I got a situation that in front is ok but on the edges, there are still faces partly not done. Top part how it is now, bottom how I will like to have it.
Regards
Peter
Ok, so this one should be better:
https://playground.babylonjs.com/#Z5XCVV#7
It is simply using the dot product between the normal of the face and the camera direction in the view space, which is always (0,0,-1). So, for all faces that have the same normal, you will get the same shading.
1 Like