But where do I actually find the passes code if I want to change it?
And another thing I didn’t find was the output z-index (for z-ordering). I thought it was supposed to be in the vert program, but I don’t see it in the function output and not sure how I can add / affect it.
When an object is rendered, it uses the first subshader it is able to use in the shader. A subshader will (by default) use every pass in the subshader. Any code that is in a subshader, but outside the pass will apply to every pass in the shader. Therefore, any code you can put in a pass may be put in the subshader instead. Without any defined “pass”, the subshader is treated as a single pass.
Put your pass code right inside the subshader.
There is none. Sprites will render on top or behind each other based on their draw order. Unity treats sprites like transparent objects, and Unity draws transparent objects from back to front.
The line “ZWrite Off” tells you that this subshader does not write to the depth buffer, so no “z information” is stored.
Any questions? I can help you get the effect you’re going for with more info.
Thanks, that explains why there are no passes. But it still looks like not enough, I mean, this shader support lighting, I would expect multiple passes for that (at least 1 “base” pass with ambient and then additive pass that will be rendered per light). Am I right? If so, where are those passes?
That does look like it from the code, however, I experimented with sprites and 3d meshes and sprites appear to act just like a quad (or billboard). they do have z-index beyond just rendering order. I even removed this line:
Unity sorts transparent objects so farther away objects are rendered first, and closer objects are rendered over them. This may appear like depth sorting using the z-axis, but it’s really just painters algorithm. The sprite probably samples depth so that it appears behind 3D objects using depth, but the shader has the line “ZWrite Off” which means it will not write depth information, and nothing drawn after it can appear behind it because of depth.
Anyway, I actually saw that forum post the other day. I’m afraid I don’t know how to get that effect because you need to sort/cull the objects differently based on their relative position to each other.
I do have an idea, but it’s a bit experimental. Basically you want the knight to sort above surfaces that face the opposite direction as the camera. If you remove the y component of the camera forward, normalize that vector and dot it with the surface normal of the block’s pixel in the pixel shader, the product will be negative if the wall is facing the opposite direction of the camera. Any wall pixel that is facing the opposite direction as the camera should be rendered below the player.
Surface shaders are short hand versions of shaders with much of the complexity hidden behind a shader generator. You can see the “real” shader by selecting the shader and clicking on “show generated shader”. Now you’ll see all those passes you’re expecting and you can copy that code into a shader file and modify it if you need something special. Most of the time it’s possible to do what you want with out.
Thanks, I’ve read a lot about shaders and material in Unity and your answers helped a lot.
I understand what I need now Got myself a good-enough shader working.