# SetPass(int)

> Activate the given pass for rendering.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.7/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule

```csharp
public bool SetPass(int pass)
```

### Parameters

**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Shader pass number to setup.

### Returns

| Type                                                          | Description                                        |
| ------------------------------------------------------------- | -------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | If false is returned, no rendering should be done. |

### Remarks

Pass indices start from zero and go up to (but not including) [Material.passCount](/engine/6000.7/script-reference/unityengine/material/passcount.md).

This is mostly used in direct drawing code. For example, drawing 3D primitives with [GL.Begin](/engine/6000.7/script-reference/unityengine/gl/begin.md), [GL.End](/engine/6000.7/script-reference/unityengine/gl/end.md), and also drawing meshes using [Graphics.DrawMeshNow](/engine/6000.7/script-reference/unityengine/graphics/drawmeshnow.md).

If SetPass returns false, you should not render anything. This is typically the case for special pass types that aren't meant for rendering, like [GrabPass](/engine/6000.7/manual/materials-and-shaders/shaders/reference/sl-reference/sl-sub-shader-object/sl-grab-pass.md).

```csharp
using UnityEngine;

// A script that when attached to the camera, makes the resulting
// colors inverted. See its effect in play mode.
public class ExampleClass : MonoBehaviour
{
    private Material mat;

    // Will be called from camera after regular rendering is done.
    public void OnPostRender()
    {
        if (!mat)
        {
            // Unity has a built-in shader that is useful for drawing
            // simple colored things. In this case, we just want to use
            // a blend mode that inverts destination colors.
            Shader shader = Shader.Find("Hidden/Internal-Colored");
            mat = new Material(shader);
            mat.hideFlags = HideFlags.HideAndDontSave;
            // Set blend mode to invert destination colors.
            mat.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusDstColor);
            mat.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
            // Turn off backface culling, depth writes, depth test.
            mat.SetInt("_Cull", (int)UnityEngine.Rendering.CullMode.Off);
            mat.SetInt("_ZWrite", 0);
            mat.SetInt("_ZTest", (int)UnityEngine.Rendering.CompareFunction.Always);
        }

        GL.PushMatrix();
        GL.LoadOrtho();

        // activate the first shader pass (in this case we know it is the only pass)
        mat.SetPass(0);
        // draw a quad over whole screen
        GL.Begin(GL.QUADS);
        GL.Vertex3(0, 0, 0);
        GL.Vertex3(1, 0, 0);
        GL.Vertex3(1, 1, 0);
        GL.Vertex3(0, 1, 0);
        GL.End();

        GL.PopMatrix();
    }
}
```

Additional Resources: [Material.passCount](/engine/6000.7/script-reference/unityengine/material/passcount.md) property, [GL](/engine/6000.7/script-reference/unityengine/gl.md) class, [ShaderLab documentation](/engine/6000.7/script-reference/unityengine/shaders.md).
