Version: 2017.1
public bool SetPass (int pass);

参数

pass 要设置的着色器通道编号。

返回

bool 如果返回 false,则不应进行任何渲染。

描述

激活给定的 pass 以进行渲染。

通道索引从零开始并递增到(但是不包含)passCount

This is mostly used in direct drawing code using GL class. For example, Image Effects use materials for implementing screen post-processing. For each pass in the material they activate the pass and draw a fullscreen quad.

如果 SetPass 返回 false,则不应渲染任何内容。对于不打算用于 渲染的特殊通道类型(如 GrabPass),通常是这种情况。

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 (); } }

另请参阅:passCount 属性、GL 类、ShaderLab documentation

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961