浏览代码

Remove OptimizeAffineMatrix()

Reason for removal: the function does not affect performance.
The last row of the matrix is only used to compute the W component of the vector resulting from the matrix-vector multiplication.
However, since we don't actually use the W component (we shouldn't...), the compiler doesn't use the last row during the multiplication.
/Yibing-Project-2
Evgenii Golubev 7 年前
当前提交
77d9e596
共有 3 个文件被更改,包括 8 次插入21 次删除
  1. 13
      ScriptableRenderPipeline/HDRenderPipeline/ShaderVariables.hlsl
  2. 8
      ScriptableRenderPipeline/HDRenderPipeline/ShaderVariablesMatrixDefsHDCamera.hlsl
  3. 8
      ScriptableRenderPipeline/HDRenderPipeline/ShaderVariablesMatrixDefsLegacyUnity.hlsl

13
ScriptableRenderPipeline/HDRenderPipeline/ShaderVariables.hlsl


float4 _FrustumPlanes[6]; // {(a, b, c) = N, d = -dot(N, P)} [L, R, T, B, N, F]
CBUFFER_END
float4x4 OptimizeAffineMatrix(float4x4 M)
{
// Matrix format (x = non-constant value).
// | x x x x |
// | x x x x |
// | x x x x |
// | 0 0 0 1 |
// Notice that the last row is constant.
// We can avoid loading and doing math with constants.
M[3] = float4(0, 0, 0, 1);
return M;
}
float4x4 OptimizeProjectionMatrix(float4x4 M)
{
// Matrix format (x = non-constant value).

8
ScriptableRenderPipeline/HDRenderPipeline/ShaderVariablesMatrixDefsHDCamera.hlsl


#ifndef UNITY_SHADER_VARIABLES_MATRIX_DEFS_HDCAMERA_INCLUDED
#define UNITY_SHADER_VARIABLES_MATRIX_DEFS_HDCAMERA_INCLUDED
#define UNITY_MATRIX_M OptimizeAffineMatrix(unity_ObjectToWorld)
#define UNITY_MATRIX_I_M OptimizeAffineMatrix(unity_WorldToObject)
#define UNITY_MATRIX_V OptimizeAffineMatrix(_ViewMatrix)
#define UNITY_MATRIX_I_V OptimizeAffineMatrix(_InvViewMatrix)
#define UNITY_MATRIX_M unity_ObjectToWorld
#define UNITY_MATRIX_I_M unity_WorldToObject
#define UNITY_MATRIX_V _ViewMatrix
#define UNITY_MATRIX_I_V _InvViewMatrix
#define UNITY_MATRIX_P OptimizeProjectionMatrix(_ProjMatrix)
#define UNITY_MATRIX_I_P _InvProjMatrix
#define UNITY_MATRIX_VP _ViewProjMatrix

8
ScriptableRenderPipeline/HDRenderPipeline/ShaderVariablesMatrixDefsLegacyUnity.hlsl


#ifndef UNITY_SHADER_VARIABLES_MATRIX_DEFS_LEGACY_UNITY_INCLUDED
#define UNITY_SHADER_VARIABLES_MATRIX_DEFS_LEGACY_UNITY_INCLUDED
#define UNITY_MATRIX_M OptimizeAffineMatrix(unity_ObjectToWorld)
#define UNITY_MATRIX_I_M OptimizeAffineMatrix(unity_WorldToObject)
#define UNITY_MATRIX_V OptimizeAffineMatrix(unity_MatrixV)
#define UNITY_MATRIX_I_V OptimizeAffineMatrix(unity_MatrixInvV)
#define UNITY_MATRIX_M unity_ObjectToWorld
#define UNITY_MATRIX_I_M unity_WorldToObject
#define UNITY_MATRIX_V unity_MatrixV
#define UNITY_MATRIX_I_V unity_MatrixInvV
#define UNITY_MATRIX_P OptimizeProjectionMatrix(glstate_matrix_projection)
#define UNITY_MATRIX_I_P inverse_glstate_matrix_projection_is_not_defined
#define UNITY_MATRIX_VP unity_MatrixVP

正在加载...
取消
保存