GL.LoadPixelMatrix 加载像素矩阵

static function LoadPixelMatrix () : void

Description描述

Setup a matrix for pixel-correct rendering.

设置一个矩阵用于像素矫正渲染。

This sets up modelview and projection matrices so that X, Y coordinates map directly to pixels. The (0,0) is at the bottom left corner of current camera's viewport. The Z coordinate goes from -1 to +100.

这设置模型视图和投影矩阵,为了使坐标X,Y映射为屏幕上的像素点。(0,0)对应视点的左下角。Z坐标值从-1到+100.

This function overrides current camera's parameters, so most often you want to save and restore matrices using GL.PushMatrix and GL.PopMatrix.

改变模型视图矩阵会覆盖当前的camera' 的参数,许多情况下你需要用到GL.PushMatrix 和GL.PopMatrix矩阵函数.来保存和恢复。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public Material mat;
	void OnPostRender() {
		if (!mat) {
			Debug.LogError("Please Assign a material on the inspector");
			return;
		}
		GL.PushMatrix();
		mat.SetPass(0);
		GL.LoadPixelMatrix();
		GL.Color(Color.red);
		GL.Begin(GL.TRIANGLES);
		GL.Vertex3(0, 0, 0);
		GL.Vertex3(0, Screen.height / 2, 0);
		GL.Vertex3(Screen.width / 2, Screen.height / 2, 0);
		GL.End();
		GL.PopMatrix();
	}
}
// Draws a red triangle using pixels as coordinates to paint on.
//绘制一个红三角形,使用像素作为坐标
var mat : Material;

function OnPostRender() {
	if (!mat) {
		Debug.LogError("Please Assign a material on the inspector");
		return;
	}
	GL.PushMatrix();
	mat.SetPass(0);
	GL.LoadPixelMatrix();
	GL.Color(Color.red);
	GL.Begin(GL.TRIANGLES);
	GL.Vertex3(0,0,0);
	GL.Vertex3(0,Screen.height/2,0);
	GL.Vertex3(Screen.width/2,Screen.height/2,0);
	GL.End();
	GL.PopMatrix();
}

• static function LoadPixelMatrix (left : float, right : float, bottom : float, top : float) : void

Description描述

Setup a matrix for pixel-correct rendering.

设置一个矩阵用于像素矫正渲染。

This sets up modelview and projection matrices so that X, Y coordinates map directly to pixels. The (0,0) is at the bottom left corner of current camera's viewport. The Z coordinate goes from -1 to +100.

This sets up modelview and projection matrices so that X, Y coordinates map directly to pixels. The (left,bottom is at the bottom left corner of current camera's viewport; and (top,right) is at the top right corner of current camera's viewport. The Z coordinate goes from -1 to +100.

这设置模型视图和投影矩阵,为了使坐标X,Y映射为屏幕上的像素点。(left,bottom)在当前相机视图的左下角, (top,right)在当前相机视图的右上角,Z坐标值从-1到+100。

This function overrides current camera's parameters, so most often you want to save and restore matrices using GL.PushMatrix and GL.PopMatrix.

改变模型视图矩阵会覆盖当前的camera' 的参数,许多情况下你需要用到GL.PushMatrix 和GL.PopMatrix矩阵函数.来保存和恢复。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public Material mat;
	void OnPostRender() {
		if (!mat) {
			Debug.LogError("Please Assign a material on the inspector");
			return;
		}
		GL.PushMatrix();
		mat.SetPass(0);
		GL.LoadPixelMatrix(10, 20, 10, 20);
		GL.Color(Color.red);
		GL.Begin(GL.TRIANGLES);
		GL.Vertex3(10, 10, 0);
		GL.Vertex3(10, 20, 0);
		GL.Vertex3(20, 20, 0);
		GL.End();
		GL.PopMatrix();
	}
}
var mat : Material;

function OnPostRender() {
	if (!mat) {
		Debug.LogError("Please Assign a material on the inspector");
		return;
	}
	GL.PushMatrix();
	mat.SetPass(0);
	GL.LoadPixelMatrix(10,20,10,20);
	GL.Color(Color.red);
	GL.Begin(GL.TRIANGLES);
	GL.Vertex3(10,10,0);
	GL.Vertex3(10,20,0);
	GL.Vertex3(20,20,0);
	GL.End();
	GL.PopMatrix();
}
最后修改:2011年3月21日 Monday 18:51

本脚本参考基于Unity 3.4.1f5

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