Material.passCount 材质通道数

var passCount : int

Description描述

How many passes are in this material (Read Only).

在这个材质中有多少pass。(只读)

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 (see SetPass ) and draw a fullscreen quad.

这主要用于使用 GL 类直接绘图代码中 (Unity 专业版)。例如,Image Effects使用材质来实现屏幕后期处理。在材质中的每一个Pass都会激活(见 SetPass)并绘制全屏四边形

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

	// for each pass in the material (one in this case)
	//材质中的每一个pass(这个例子中有一个)

	for (var i = 0; i < mat.passCount; ++i) {
		// activate pass
		//激活pass
		mat.SetPass (i);
		// 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

Page last updated: 2011-1-21