- Home /
Drawing outlines on terrain; how?
I have a simple terrain (just a flat plane I generate). My game is grid based, and I would like to draw lines on the terrain to separate sections of the grid (the player would actually). I want an effect like this:
Pretend the image is the terrain. I want to be able to project the red lines on the terrain without the thickness of the lines being affected by changes in the size of the terrain, or underlying texture (very similar to how GridProjector works). Essentially, I want the player to be able to outline areas of the terrain, persistently (not just on a mouse drag and it goes away).
I want to avoid using projectors (unless it is a single one) due to the overhead (there could be hundreds of these on a map). I thought about using a splat map, but I fear that would be too resolution dependent.
What are some ways to go about this?
Answer by tanoshimi · Jun 03, 2015 at 06:06 AM
I wrote a grid shader a couple of years back... rummages through the Internet... yes, here it is: http://forum.unity3d.com/threads/wireframe-grid-shader.60071/
Don't know if it will work out-of-the-box for terrain, but it certainly shouldn't be too hard to adapt, and that should give you the best performing method as it's done purely in a single shader.
While this doe snot directly answer the question, it is ENOR$$anonymous$$OUSLY helpful. It actually help solve an entirely different issue I was having that I put on the backburner. haha. particularly this little snippet:
frac(IN.worldPos.x/1)
I had been racking my brain trying to figure out how to get the information this statement provies. Thank you for that!!!!
I think I could leverage this to solve this particular issue as well, but I am going to hold off on marking this answered; see what other ideas may crop up.
This helped me get to where I had to be. It is not perfect yet, but that is for another post.
Here is a portion of the shader:
// handle lot display
fixed4 lot = tex2D (_Lot$$anonymous$$ap, IN.uv_Road$$anonymous$$ap / (_Road$$anonymous$$ap_TexelSize.xy * (_Road$$anonymous$$ap_TexelSize.zw - 1)));
fixed4 lotLEFT = tex2D (_Lot$$anonymous$$ap, (IN.uv_Road$$anonymous$$ap - float2(uvAdjX ,0)) / (_Road$$anonymous$$ap_TexelSize.xy * (_Road$$anonymous$$ap_TexelSize.zw - 1)));
fixed4 lotRIGHT = tex2D (_Lot$$anonymous$$ap, (IN.uv_Road$$anonymous$$ap + float2(uvAdjX, 0)) / (_Road$$anonymous$$ap_TexelSize.xy * (_Road$$anonymous$$ap_TexelSize.zw - 1)));
fixed4 lotTOP = tex2D (_Lot$$anonymous$$ap, (IN.uv_Road$$anonymous$$ap + float2(0, uvAdjY)) / (_Road$$anonymous$$ap_TexelSize.xy * (_Road$$anonymous$$ap_TexelSize.zw - 1)));
fixed4 lotBOTTO$$anonymous$$ = tex2D (_Lot$$anonymous$$ap, (IN.uv_Road$$anonymous$$ap - float2(0, uvAdjY)) / (_Road$$anonymous$$ap_TexelSize.xy * (_Road$$anonymous$$ap_TexelSize.zw - 1)));
// this outlines the lots. Specifcially, it outlines any area where the neighboring sample is of a different color
if((fracX <= _RoadBlend && !float4comp(lotLEFT, lot)) ||
(fracX >= 1 - _RoadBlend && !float4comp(lotRIGHT, lot)) ||
(fracZ >= 1 - _RoadBlend && !float4comp(lotTOP, lot)) ||
(fracZ <= _RoadBlend && !float4comp(lotBOTTO$$anonymous$$, lot))) {
o.Albedo = fixed4(1, 0.75, 0.15, 1);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613200554im_/https://answers.unity.com/themes/thub/images/avi.jpg)