浏览代码

Save a bit of ALU on projection matrices

/Yibing-Project-2
Evgenii Golubev 7 年前
当前提交
43a667f7
共有 4 个文件被更改,包括 40 次插入14 次删除
  1. 29
      ScriptableRenderPipeline/HDRenderPipeline/ShaderVariables.hlsl
  2. 5
      ScriptableRenderPipeline/HDRenderPipeline/ShaderVariablesFunctions.hlsl
  3. 10
      ScriptableRenderPipeline/HDRenderPipeline/ShaderVariablesMatrixDefsHDCamera.hlsl
  4. 10
      ScriptableRenderPipeline/HDRenderPipeline/ShaderVariablesMatrixDefsLegacyUnity.hlsl

29
ScriptableRenderPipeline/HDRenderPipeline/ShaderVariables.hlsl


// ----------------------------------------------------------------------------
// TODO: all affine matrices should be 3x4.
CBUFFER_START(UnityPerPass)
float4x4 _PrevViewProjMatrix;
float4x4 _ViewProjMatrix;

float4 _ScreenSize; // {w, h, 1/w, 1/h}
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).
// Orthographic Perspective Combined(OR)
// | x 0 0 x | | x 0 x 0 | | x 0 x x |
// | 0 x 0 x | | 0 x x 0 | | 0 x x x |
// | 0 0 x x | | 0 0 x x | | 0 0 x x |
// | 0 0 0 1 | | 0 0 x 0 | | 0 0 x x |
// Notice that some values are always 0.
// We can avoid loading and doing math with constants.
M._21_31_41 = 0;
M._12_32_42 = 0;
return M;
}
#ifdef USE_LEGACY_UNITY_MATRIX_VARIABLES
#include "ShaderVariablesMatrixDefsLegacyUnity.hlsl"

5
ScriptableRenderPipeline/HDRenderPipeline/ShaderVariablesFunctions.hlsl


return (unity_OrthoParams.w == 0);
#else
// TODO: set 'unity_OrthoParams' during the shadow pass.
return (GetWorldToHClipMatrix()[3].x != 0 ||
GetWorldToHClipMatrix()[3].y != 0 ||
GetWorldToHClipMatrix()[3].z != 0 ||
GetWorldToHClipMatrix()[3].w != 1);
return UNITY_MATRIX_P[3][3] == 0;
#endif
}

10
ScriptableRenderPipeline/HDRenderPipeline/ShaderVariablesMatrixDefsHDCamera.hlsl


#ifndef UNITY_SHADER_VARIABLES_MATRIX_DEFS_HDCAMERA_INCLUDED
#define UNITY_SHADER_VARIABLES_MATRIX_DEFS_HDCAMERA_INCLUDED
#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 _ProjMatrix
#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_P OptimizeProjectionMatrix(_ProjMatrix)
#define UNITY_MATRIX_I_P _InvProjMatrix
#define UNITY_MATRIX_VP _ViewProjMatrix
#define UNITY_MATRIX_MVP mul(UNITY_MATRIX_VP, UNITY_MATRIX_M)

10
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 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 glstate_matrix_projection
#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_P OptimizeProjectionMatrix(glstate_matrix_projection)
#define UNITY_MATRIX_I_P inverse_glstate_matrix_projection_is_not_defined
#define UNITY_MATRIX_VP unity_MatrixVP
#define UNITY_MATRIX_MVP mul(UNITY_MATRIX_VP, UNITY_MATRIX_M)

正在加载...
取消
保存