返回介绍

Material.SetPass 设置通道

发布于 2019-12-18 15:37:58 字数 4932 浏览 1247 评论 0 收藏 0

JavaScript => public function SetPass(pass: int): bool;
C# => public bool SetPass(int pass);

Parameters 参数

passShader pass number to setup.
设置材质的通道数。

Returns 返回值

bool If false is returned, no rendering should be done.

返回布尔值,如果为false,将不渲染。

Description 描述

Activate the given pass for rendering.

为渲染激活给定的pass。

Pass indices start from zero and go up to (but not including) passCount.

传递从0开始最大到(但不包括)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.

这主要用于使用 GL 类直接绘图代码中 (Unity 专业版)。比如图像效果使用执行屏幕后处理的材质。在材质中的每一个Pass都会激活(见 SetPass)并绘制全屏四边形

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.

如果SetPass 返回 false,不会渲染任何东西。在这种情况下指定的通道类型意味着不渲染,像GrabPass。

JavaScript:

#pragma strict
// A script that when attached to the camera, makes the resulting
// colors inverted. See its effect in play mode.
private var mat: Material;
// Will be called from camera after regular rendering is done.
public function OnPostRender() {
	if (!mat) {
		// a blend mode that inverts destination colors.			
		var shader: var = Shader.Find("Hidden/Internal-Colored");
		mat = new Material(shader);
		mat.hideFlags = HideFlags.HideAndDontSave;
		// Set blend mode to invert destination colors.
		mat.SetInt("_SrcBlend", intUnityEngine.Rendering.BlendMode.OneMinusDstColor);
		mat.SetInt("_DstBlend", intUnityEngine.Rendering.BlendMode.Zero);
		// Turn off backface culling, depth writes, depth test.
		mat.SetInt("_Cull", intUnityEngine.Rendering.CullMode.Off);
		mat.SetInt("_ZWrite", 0);
		mat.SetInt("_ZTest", intUnityEngine.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();
}

C#:

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

Material

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文