I’m reading the docs here, and it mentioned a “shader pass”.
Is it some countable object that I’m not aware of in shader linguistic? Or is 1 pass meaning “1 action of applying the material attributes for a texture onto the surface face of the game object’s mesh”?
I’m just trying to understand what it means in shader jargon.
To understand that you need to understand what a shader is. In Unity what they call a shader can actually have multiple shaders in it. When something is rendered the basic path is vertex information (aka a mesh) is processed by a vertex function (aka vertex shader) to calculate their positions in screen space and to calculate any additional data needed for rastorization. That data is passed to the fragment function (aka fragment shader or pixel shader) which runs once for each pixel on the screen each polygon covers and which ultimately returns data for each pixel, usually a color, one at a time to be stored and usually eventually displayed.
That is one pass. It’s the combination of the mesh, vertex, and pixel shader resulting in pixel data being written.
A shader file in Unity may have one of these, or many as multiple passes. Surface shaders appear to be one shader but actually get expanded out to many different shader passes, not all of which run at the same time.
So, if I specify to use pass index #0 in Material.SetPass(int), I am basically checking to see if I’m allowed to start drawing after the very first pass out of potentially multiple passes in the material, is this correct?
SetPass is a fairly low level command, you’re literally telling the rendering system “the next thing you draw should be using this shader pass”. It’s rare you’re going to need to use that unless you want very precise manually control over rendering. Usually you just want to slap an object in the scene with a material and let the internal rendering systems work out the when and how. It’s most commonly used for rendering full screen camera effects and don’t want to use the existing Blit system.
If it’s a low-level command, that suggests I don’t actually need to use it?
It’s interesting to know that tutorials showing you how to make a box selection would say you need to put “SetPass(0)” in the code. Maybe box selection actually needs to render the full screen camera effects…
Another interesting thing is that I haven’t encountered tutorials that would use SetPass(0) or SetPass(non-zero) elsewhere.
It’s a common usage, but not the only one. Like I said it’s just a way to say “the next thing you render use this shader pass”. The next thing you do is say “render this vertex data” and it goes ahead and renders it using that pass you just set, which would be one of several other low level function. For camera effects it’s often just a fullscreen quad, but it could be used to render anything, especially things you don’t need information about things like lighting or occlusion for. A selection box is a good example of something like that. There’s a ton of work that happens when something like a simple game object is placed in the scene to even get to the point of it being rendered. Using SetPass and DrawMesh (or one of many other Draw commands) circumvents all of that. If you’re trying to render a selection box, or some other gizmo for UI purposes it can be more efficient to use the low level graphics functions.