Version: 2017.3

GL.LoadPixelMatrix

切换到手册
public static void LoadPixelMatrix ();

描述

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

这会设置 modelview 和投影矩阵,以便使 X、Y 坐标直接 映射到像素。(0,0) 位于当前摄像机视口的 左下角。Z 坐标从 -1 变为 +1。

此函数会重写当前摄像机的参数,因此,绝大多数情况下,您希望 使用 GL.PushMatrixGL.PopMatrix 保存和恢复矩阵。

using UnityEngine;
using System.Collections;

public class ExampleClass : 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(); } }

public static void LoadPixelMatrix (float left, float right, float bottom, float top);

描述

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

这会设置 modelview 和投影矩阵,以便使 X、Y 坐标直接 映射到像素。(left,bottom) 位于当前摄像机视口的 左下角;(top,right) 位于当前摄像机视口的右上角。 Z 坐标从 -1 变为 +1。

此函数会重写当前摄像机的参数,因此,绝大多数情况下,您希望 使用 GL.PushMatrix 和 GL.PopMatrix 保存和恢复矩阵。

using UnityEngine;
using System.Collections;

public class ExampleClass : 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(); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961