Hi! I've been working has a few days to achieve a look like shown below in the 3rd pic, where: i - Easy - ok) Cubes are visible, drown where not behind Cylinders; ii - Medium) Balls are drown always on top of Cylinders; iii - Difficult) Only the parts of Cubes that are not behind Cylinders get drown in front of Balls. I managed to code the basics for the CUBE, where I split in 2 passes and ZTest twice, but cannot hide the Cube part behind Cylinder. Code (CSharp): Shader "CUBE" { Properties { _Color1 ("Color 1", Color) = (1,1,1) _Color2 ("Color 2", Color) = (1,1,1) } SubShader { Pass { Tags { "Queue"="Geometry" } ZTest GEqual Color [_Color1] } Pass { Tags { "Queue"="Geometry-2" } ZTest Less Color [_Color2] } } } And for Ball and Cylinder I'm using most basic color shader: Code (CSharp): Shader "BALL and CYLINDER" { Properties { _Color1 ("Color 1", Color) = (1,1,1) } SubShader { Pass { Tags { "Queue"="Geometry" } ZTest LEqual Color [_Color1] } } } As I'm noob at programming, I could just raise a few possible directions to go here, but I'm lost: - Is it related to RenderType, Queue, or just ZTests? - Do I need a per-pixel shader to achieve that effect? -Do I need a specific shader also for the Ball and Cylinder? Every help is appreciated !
ZTests are not enough in this case. But the Stencil buffer can help out. Is there any interaction with other geometry through the Z-buffer? If there isn't, things become a lot easier and ZTest and ZWrite can just be disabled. Then simply draw in the order cylinder, ball, cube. The cylinder should mark the Stencil buffer and the cube should be skipped if the Stencil buffer is marked. Mark (in cylinder): Code (csharp): Stencil { WriteMask 1 } Skip (in cube): Code (csharp): Stencil { Ref 1 ReadMask 1 Comp NotEqual } And remember, no ZTest in all three.