I’m trying to draw a circle around a character if it is selected. I have got a ground mesh, some character, trees, rocks, etc. The circle should be drawn over the ground, but under everything else. Currently the circle object is a plane with a transparent circle texture, and it is works great with a flat ground. But if the ground isn’t flat, sometimes near a rise half of the circle is covered by it, like on the first screenshot.
What I have tried so far:
Draw the circle with projector, it works, but i don’t want it to follow the ground’s geometry.
Multiple cameras with layers and culling masks set up: first layer is for the ground, the second is for the circle, and the third is for everything else. This way the circle was rendered correctly, but ground could not receive shadows because it was rendered by a different camera than the shadow casters.
Custom shader (I don’t know anything about shader programming btw) to the ground with “Queue” = “Geometry-10” tag. It did nont changed anything, the result was zhe same as on the first screenshot.
Most common way is to just raise the circle up a little.
A more complex way is to use stencils. You’ll need a customized material for your character (or anything you want to render above) that writes to the stencil, and your ground circle needs to use a shader that reads the stencil and won’t render there.
A slightly less complex way is similar to what you were doing with the queues, but you can actually do this without as many custom shaders. You’ll want to set the custom queue on the characters’ materials to be geometry+2 (or 2002). Then your circle needs to have “Queue”=“Geometry+1” and ZTest Always. This will cause it to render after the terrain / other ground geometry and always render. Then then the characters and anything else will render after that. You can set custom queues on materials using the debug inspector; right click on the inspector tab and select debug.
I tried raise the circle up a little already, but sometimes it get covered there too.
Now i’m trying to solve the problem with the custom render queue method you suggested. Changed it in the inspector to 2001 to the circle and 2002 to the character. The problem is transparency and ZTest always does not work together well.
The result with no alpha & no ZTest always
No alpha but ZTest always (this is what i want, but with transparency)
Alpha & ZTest always
As you can see, when i enable alpha in the shader, it looks like the custom render queue value is not used.
That’s because setting “alpha” in the #pragma line does some extra stuff. Try using “keepalpha” and add “Blend SrcAlpha OneMinusSrcAlpha” just below tags, or don’t use a surface shader.
It’s working now, looks like it’s wrong in the scene view, but ok in the game. My final settings: render queue is set to 1990 for ground’s material (still from the inspector), 1995 to to circle, everything else is at default. The shader: