GL.SetRevertBackfacing 设置恢复背面

static function SetRevertBackfacing (revertBackFaces : bool) : void

Description描述

Select whether to invert the backface culling (true) or not (false).

是否关闭背面消隐功能。默认情况下,背面消隐功能是打开的。

Unlike most other calls, this is not only related to stuff you draw via GL class. It changes culling of triangles globally. Major use case: rendering reflections for mirrors, water etc. Since virtual camera for rendering the reflection is mirrored, the culling order has to be inverted. You can see that the Water script in Pro Standard Assets does that.

背面消隐功能的打开或关闭,不仅影响到用GL类绘制的东西,也影响到全局的三角形背面消隐。主要用在这种情况下:镜面反射效果和水的效果。在专业版标准资源包水的脚本里有程序实例。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public Material mat;
	public bool swap = false;
	void Update() {
		if (Input.GetKeyDown(KeyCode.Space))
			if (swap)
				swap = false;
			else
				swap = true;

	}
	void OnPostRender() {
		if (!mat) {
			Debug.LogError("Please Assign a material on the inspector");
			return;
		}
		GL.PushMatrix();
		mat.SetPass(0);
		GL.LoadOrtho();
		GL.Color(Color.yellow);
		GL.Begin(GL.TRIANGLES);
		GL.SetRevertBackfacing(swap);
		GL.Vertex3(0, 0, 0);
		GL.Vertex3(1, 1, 0);
		GL.Vertex3(0, 1, 0);
		GL.Vertex3(0, 0, 0);
		GL.Vertex3(1, 1, 0);
		GL.Vertex3(1, 0, 0);
		GL.End();
		GL.PopMatrix();
	}
}
// Draws 2 yellow triangles and makes them appear/dissapear
// depending on the vertex draw order
// Notice that everything on the scene will suffer from the revert
// backfacing as well
//绘制2个黄色三角形并使他们可见/不可见,取决于点的绘制顺序
//注意,场景中所有物体都将受到SetRevertBackfacing的影响
var mat : Material;

var swap : boolean = false;
function Update() {
	if(Input.GetKeyDown(KeyCode.Space)) {
		if(swap) {
			swap = false;
		} else {
			swap = true;
		}
	}
}

function OnPostRender() {
	if (!mat) {
		Debug.LogError("Please Assign a material on the inspector");
		return;
	}
	GL.PushMatrix();
	mat.SetPass(0);
	GL.LoadOrtho();
	GL.Color(Color.yellow);
	GL.Begin(GL.TRIANGLES);
	GL.SetRevertBackfacing(swap);
	GL.Vertex3(0,0,0);
	GL.Vertex3(1,1,0);
	GL.Vertex3(0,1,0);
	GL.Vertex3(0,0,0);
	GL.Vertex3(1,1,0);
	GL.Vertex3(1,0,0);
	GL.End();
	GL.PopMatrix();
}
最后修改:2011年3月22日 Tuesday 14:35

 

本脚本参考基于Unity 3.4.1f5

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