浏览代码

Prelim usage of combined stereo VP for constant generation

Right now, I use the combined view/proj matrices generated from the engine for culling.  I'd like to move the matrix generation up to script, where the HDRP explicitly controls the matrix gen.

As far as shader constants, this affects the usage of:
_ViewProjMatrix (not used the same as UNITY_MATRIX_VP in stereo/shadows)
_ViewParam
_FrustumPlanes

These three are used in GetTessellationFactors.

_InvProjParam (unused for now anyway)
/main
Robert Srinivasiah 6 年前
当前提交
9c3ed431
共有 2 个文件被更改,包括 53 次插入1 次删除
  1. 52
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/HDCamera.cs
  2. 2
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs

52
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Camera/HDCamera.cs


screenSize = new Vector4(screenWidth, screenHeight, 1.0f / screenWidth, 1.0f / screenHeight);
}
public void UpdateStereoDependentState(FrameSettings frameSettings, Camera camera, ref ScriptableCullingParameters cullingParams)
{
if (!frameSettings.enableStereo)
return;
// What constants in UnityPerPass need updating for stereo considerations?
// _ViewProjMatrix - It is used directly for generating tesselation factors. This should be the same
// across both eyes for consistency, and to keep shadow-generation eye-independent
// _ViewParam - Used for isFrontFace determination, should be the same for both eyes. There is the scenario
// where there might be multi-eye sets that are divergent enough where this assumption is not valid,
// but that's a future problem
// _InvProjParam - Intention was for generating linear depths, but not currently used. Will need to be stereo-ized if
// actually needed.
// _FrustumPlanes - Also used for generating tesselation factors. Should be fine to use the combined stereo VP
// to calculate frustum planes.
// TODO: I really should be calculating my own combined view/proj in the Update code
var stereoCombinedViewMatrix = cullingParams.cullStereoView;
var pos = camera.transform.position;
var relPos = pos; // World-origin-relative
if (ShaderConfig.s_CameraRelativeRendering != 0)
{
// Zero out the translation component.
stereoCombinedViewMatrix.SetColumn(3, new Vector4(0, 0, 0, 1));
relPos = Vector3.zero; // Camera-relative
}
viewMatrix = stereoCombinedViewMatrix;
var stereoCombinedProjMatrix = cullingParams.cullStereoProj;
projMatrix = GL.GetGPUProjectionMatrix(stereoCombinedProjMatrix, true);
viewParam = new Vector4(viewMatrix.determinant, 0.0f, 0.0f, 0.0f);
// Warning: near and far planes appear to be broken (or rather far plane seems broken)
GeometryUtility.CalculateFrustumPlanes(viewProjMatrix, frustumPlanes);
for (int i = 0; i < 4; i++)
{
// Left, right, top, bottom.
frustumPlaneEquations[i] = new Vector4(frustumPlanes[i].normal.x, frustumPlanes[i].normal.y, frustumPlanes[i].normal.z, frustumPlanes[i].distance);
}
// Near, far.
Vector4 forward = new Vector4(camera.transform.forward.x, camera.transform.forward.y, camera.transform.forward.z, 0.0f);
// We need to switch forward direction based on handness (Reminder: Regular camera have a negative determinant in Unity and reflection probe follow DX convention and have a positive determinant)
forward = viewParam.x < 0.0f ? forward : -forward;
frustumPlaneEquations[4] = new Vector4(forward.x, forward.y, forward.z, -Vector3.Dot(forward, relPos) - camera.nearClipPlane);
frustumPlaneEquations[5] = new Vector4(-forward.x, -forward.y, -forward.z, Vector3.Dot(forward, relPos) + camera.farClipPlane);
}
void ConfigureStereoMatrices()
{
for (uint eyeIndex = 0; eyeIndex < 2; eyeIndex++)

2
ScriptableRenderPipeline/HDRenderPipeline/HDRP/HDRenderPipeline.cs


ApplyDebugDisplaySettings(hdCamera, cmd);
UpdateShadowSettings();
// TODO: Float HDCamera setup higher in order to pass stereo into GetCullingParameters
ScriptableCullingParameters cullingParams;
if (!CullResults.GetCullingParameters(camera, m_FrameSettings.enableStereo, out cullingParams))
{

m_LightLoop.UpdateCullingParameters(ref cullingParams);
hdCamera.UpdateStereoDependentState(m_FrameSettings, hdCamera.camera, ref cullingParams);
#if UNITY_EDITOR
// emit scene view UI

正在加载...
取消
保存