Material.SetPass 设置材质通道

function SetPass (pass : int) : bool

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 (Unity Pro only). 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.

如果SetPass 返回 false你就不能渲染任何东西。

Here is an example of a full image effect that inverts the colors. Add this script to the camera and see it in play mode.

这里是全屏图像效果的反色例子。将此脚本添加到相机可以在播放模式中看到它。

private var mat : Material;

function Start () {
	mat = new Material (
	"Shader \"Hidden/Invert\" {" +
	"SubShader {" +
	" Pass {" +
	" ZTest Always Cull Off ZWrite Off" +
	" SetTexture [_RenderTex] { combine one-texture }" +
	" }" +
	"}" +
	"}"
	);
}

function OnRenderImage (source : RenderTexture, dest : RenderTexture) {
	RenderTexture.active = dest;
	source.SetGlobalShaderProperty ("_RenderTex");

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

	// activate the first pass (in this case we know it is the only pass)
	//激活第一个pass(这里我们知道它是仅有的pass
	mat.SetPass (0);
	// draw a quad
	//绘制四边形
	GL.Begin (GL.QUADS);
	GL.TexCoord2 (0, 0); GL.Vertex3 (0, 0, 0.1);
	GL.TexCoord2 (1, 0); GL.Vertex3 (1, 0, 0.1);
	GL.TexCoord2 (1, 1); GL.Vertex3 (1, 1, 0.1);
	GL.TexCoord2 (0, 1); GL.Vertex3 (0, 1, 0.1);
	GL.End ();

	GL.PopMatrix ();
}

参考: passCount 属性, GL

最后修改:2011年1月22日 Saturday 21:53

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。