|
|
|
|
|
|
public Vector4[] frustumPlaneEquations; |
|
|
|
public Camera camera; |
|
|
|
public uint taaFrameIndex; |
|
|
|
public Vector4 viewParam; |
|
|
|
public PostProcessRenderContext postprocessRenderContext; |
|
|
|
|
|
|
|
public Matrix4x4 viewProjMatrix |
|
|
|
|
|
|
isFirstFrame = false; |
|
|
|
|
|
|
|
const uint taaFrameCount = 8; |
|
|
|
taaFrameIndex = taaEnabled ? (uint)Time.renderedFrameCount % taaFrameCount : 0; |
|
|
|
taaFrameIndex = taaEnabled ? (uint)Time.renderedFrameCount % taaFrameCount : 0; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
|
|
|
nonJitteredProjMatrix = gpuNonJitteredProj; |
|
|
|
cameraPos = pos; |
|
|
|
screenSize = new Vector4(camera.pixelWidth, camera.pixelHeight, 1.0f / camera.pixelWidth, 1.0f / camera.pixelHeight); |
|
|
|
viewParam = new Vector4(viewMatrix.determinant, 0.0f, 0.0f, 0.0f); |
|
|
|
|
|
|
|
if (ShaderConfig.s_CameraRelativeRendering != 0) |
|
|
|
{ |
|
|
|
|
|
|
cmd.SetGlobalMatrix(HDShaderIDs._NonJitteredViewProjMatrix, nonJitteredViewProjMatrix); |
|
|
|
cmd.SetGlobalMatrix(HDShaderIDs._ViewProjMatrix, viewProjMatrix); |
|
|
|
cmd.SetGlobalMatrix(HDShaderIDs._InvViewProjMatrix, viewProjMatrix.inverse); |
|
|
|
cmd.SetGlobalVector(HDShaderIDs._ViewParam, viewParam); |
|
|
|
cmd.SetGlobalVector(HDShaderIDs._InvProjParam, invProjParam); |
|
|
|
cmd.SetGlobalVector(HDShaderIDs._ScreenSize, screenSize); |
|
|
|
cmd.SetGlobalMatrix(HDShaderIDs._PrevViewProjMatrix, prevViewProjMatrix); |
|
|
|
|
|
|
|
|
|
|
// Does not modify global settings. Used for shadows, low res. rendering, etc.
|
|
|
|
public void OverrideGlobalParams(Material material) |
|
|
|
{ |
|
|
|
material.SetMatrix(HDShaderIDs._ViewMatrix, viewMatrix); |
|
|
|
material.SetMatrix(HDShaderIDs._InvViewMatrix, viewMatrix.inverse); |
|
|
|
material.SetMatrix(HDShaderIDs._ProjMatrix, projMatrix); |
|
|
|
material.SetMatrix(HDShaderIDs._InvProjMatrix, projMatrix.inverse); |
|
|
|
material.SetMatrix(HDShaderIDs._NonJitteredViewProjMatrix, nonJitteredViewProjMatrix); |
|
|
|
material.SetMatrix(HDShaderIDs._ViewProjMatrix, viewProjMatrix); |
|
|
|
material.SetMatrix(HDShaderIDs._InvViewProjMatrix, viewProjMatrix.inverse); |
|
|
|
material.SetVector(HDShaderIDs._InvProjParam, invProjParam); |
|
|
|
material.SetVector(HDShaderIDs._ScreenSize, screenSize); |
|
|
|
material.SetMatrix(HDShaderIDs._PrevViewProjMatrix, prevViewProjMatrix); |
|
|
|
material.SetVectorArray(HDShaderIDs._FrustumPlanes, frustumPlaneEquations); |
|
|
|
material.SetInt(HDShaderIDs._TaaFrameIndex, (int)taaFrameIndex); |
|
|
|
} |
|
|
|
|
|
|
|
// TODO: We should set all the value below globally and not let it under the control of Unity,
|
|
|
|
// Need to test that because we are not sure in which order these value are setup, but we need to have control on them, or rename them in our shader.
|
|
|
|
// For now, apply it for all our compute shader to make it work
|
|
|
|
|
|
|
cmd.SetComputeVectorParam(cs, HDShaderIDs.unity_OrthoParams, Shader.GetGlobalVector(HDShaderIDs.unity_OrthoParams)); |
|
|
|
cmd.SetComputeVectorParam(cs, HDShaderIDs._ProjectionParams, Shader.GetGlobalVector(HDShaderIDs._ProjectionParams)); |
|
|
|
cmd.SetComputeVectorParam(cs, HDShaderIDs._ViewParam, Shader.GetGlobalVector(HDShaderIDs._ViewParam)); |
|
|
|
cmd.SetComputeVectorParam(cs, HDShaderIDs._ScreenParams, Shader.GetGlobalVector(HDShaderIDs._ScreenParams)); |
|
|
|
cmd.SetComputeVectorParam(cs, HDShaderIDs._ZBufferParams, Shader.GetGlobalVector(HDShaderIDs._ZBufferParams)); |
|
|
|
cmd.SetComputeVectorParam(cs, HDShaderIDs._WorldSpaceCameraPos, Shader.GetGlobalVector(HDShaderIDs._WorldSpaceCameraPos)); |
|
|
|