用户工具

站点工具


侧边栏

script:unityengine:classes:gl:gl.getgpuprojectionmatrix

GL.GetGPUProjectionMatrix 获取GPU投影矩阵

JavaScript ⇒ public static function GetGPUProjectionMatrix(proj: Matrix4x4, renderIntoTexture: bool): Matrix4x4;
C# ⇒ public static Matrix4x4 GetGPUProjectionMatrix(Matrix4x4 proj, bool renderIntoTexture);

Description 描述

Compute GPU projection matrix from camera's projection matrix.

从相机的GPU投影矩阵计算GPU投影矩阵。

In Unity, projection matrices follow OpenGL convention. However on some platforms they have to be transformed a bit to match the native API requirements. Use this function to calculate how the final projection matrix will be like. The value will match what comes as UNITY_MATRIX_P matrix in a shader.

在Unity,投影矩阵遵循OpenGL公约,然而某些平台它们需要变换位来匹配本地API需要。使用此功能来计算最终的投影矩阵。这个值匹配shader里的UNITY_MATRIX_P matrix

The renderIntoTexture value should be set to true if you intend to render into a RenderTexture with this projection matrix. On some platforms it affects how the final matrix will look like.

如果你打算这个投影矩阵渲染到渲染纹理,renderIntoTexture值应该设置为true。在某些平台它影响到最终的矩阵的样子。

C#:

	public GameObject debugObject;
	// Use this for initialization
	void Start () {
		Matrix4x4 P = GL.GetGPUProjectionMatrix(Camera.main.projectionMatrix, false);
		Matrix4x4 V = Camera.main.worldToCameraMatrix;
		Matrix4x4 M = debugObject.GetComponent<Renderer>().localToWorldMatrix;
		Matrix4x4 MVP = P * V * M;
		debugObject.GetComponent<Renderer>().material.SetMatrix("_MATRIX_MVP", MVP);
 
	}

把debugObject对象给个材质用这个shader

Shader "Custom/Test" {
    Properties {
        _MainTex("Texture", 2D) = "white" { }  
    }
 
    SubShader{ 
 
    Pass{
                                    
script/unityengine/classes/gl/gl.getgpuprojectionmatrix.txt · 最后更改: 2016/08/02 05:24 (外部编辑)