- Home /
Conditional shader??
Now I know this one is a toughie, but any lead or idea will be helpful. Situation; -We have two meshes, one terrain and a large polygon. Polygon has no mesh renderer. Question; Is it possible for terrain mesh to use different material (or color) on just the place where both collides? I tried checking every vertices for collision on editor and creating a submesh, but because meshes are not that dense in vertices like textures, results are looking ugly. I believe the shaders are logical answer but so far i am stuck. Any method (shader, in editor, in runtime) is fine. EDIT: Here is a visualization.
Answer by tanoshimi · Jun 24, 2017 at 10:21 PM
Sounds like this could be done pretty easily using the stencil buffer. Add a renderer to the polygon that writes a value to the buffer. Then test the buffer value in the terrain shader and write different coloured outputs accordingly.
https://alastaira.wordpress.com/2014/12/27/using-the-stencil-buffer-in-unity-free/
I will definetly try this and return with results. many thanks
If it was set to ZWrite Off, this is working much better. Thank you for your answer. And I really should try things more before making an update. It is my bad :P
Answer by ihsan07 · Jun 25, 2017 at 07:17 PM
Just a quick question. I went through some examples and it seems that using this method will change color of terrain where it is behind of polygon from perspective of cam. This is not wanted. I just want colliding parts to change color which will not change wherever the camera. Is this doable using stencil buffers? EDIT: I found a solution; http://answers.unity3d.com/questions/23544/projecting-a-square-or-another-shape-onto-terrain.html EDIT2: If I set ZWrite off using stencil buffer, colored part doesn't change based on camera's location and angle.
Your answer
Follow this Question
Related Questions
Unlit Transparent With Color Support 1 Answer
create a texture with shader code? ( without using a texture ) 1 Answer
How to add Emission to my custom shader? 2 Answers
The Best Way To Make Stylised Grass in Unity? 0 Answers
How to get the value of a pixel of a noise node if it's greater than some threshold? 0 Answers