浏览代码

Fixing winding and VFACE order issue + Remove _DetViewMatrix

/main
Sebastien Lagarde 6 年前
当前提交
2b3f449e
共有 5 个文件被更改,包括 0 次插入16 次删除
  1. 8
      com.unity.render-pipelines.high-definition/HDRP/Camera/HDCamera.cs
  2. 3
      com.unity.render-pipelines.high-definition/HDRP/Editor/ShaderGraph/SharedCode.template.hlsl
  3. 1
      com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDStringConstants.cs
  4. 3
      com.unity.render-pipelines.high-definition/HDRP/ShaderPass/VaryingMesh.hlsl
  5. 1
      com.unity.render-pipelines.high-definition/HDRP/ShaderVariables.hlsl

8
com.unity.render-pipelines.high-definition/HDRP/Camera/HDCamera.cs


public Matrix4x4 projMatrix;
public Matrix4x4 nonJitteredProjMatrix;
public Vector4 worldSpaceCameraPos;
public float detViewMatrix;
public Vector4 screenSize;
public Frustum frustum;
public Vector4[] frustumPlaneEquations;

projMatrix = gpuProj;
nonJitteredProjMatrix = gpuNonJitteredProj;
cameraPos = pos;
detViewMatrix = viewMatrix.determinant;
if (ShaderConfig.s_CameraRelativeRendering != 0)
{

// 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
// _DetViewMatrix - 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

viewMatrix = stereoCombinedViewMatrix;
var stereoCombinedProjMatrix = cullingParams.cullStereoProj;
projMatrix = GL.GetGPUProjectionMatrix(stereoCombinedProjMatrix, true);
detViewMatrix = viewMatrix.determinant;
frustum = Frustum.Create(viewProjMatrix, true, true);

cmd.SetGlobalMatrix(HDShaderIDs._NonJitteredViewProjMatrix, nonJitteredViewProjMatrix);
cmd.SetGlobalMatrix(HDShaderIDs._PrevViewProjMatrix, prevViewProjMatrix);
cmd.SetGlobalVector(HDShaderIDs._WorldSpaceCameraPos, worldSpaceCameraPos);
cmd.SetGlobalFloat(HDShaderIDs._DetViewMatrix, detViewMatrix);
cmd.SetGlobalVector(HDShaderIDs._ScreenSize, screenSize);
cmd.SetGlobalVector(HDShaderIDs._ScreenToTargetScale, doubleBufferedViewportScale);
cmd.SetGlobalVector(HDShaderIDs._ZBufferParams, zBufferParams);

3
com.unity.render-pipelines.high-definition/HDRP/Editor/ShaderGraph/SharedCode.template.hlsl


$FragInputs.color: output.color = input.color;
#if SHADER_STAGE_FRAGMENT
$FragInputs.isFrontFace: output.isFrontFace = IS_FRONT_VFACE(input.cullFace, true, false); // TODO: SHADER_STAGE_FRAGMENT only
$FragInputs.isFrontFace: // Handle handness of the view matrix (In Unity view matrix default to a determinant of -1)
$FragInputs.isFrontFace: // when we render a cubemap the view matrix handness is flipped (due to convention used for cubemap) we have a determinant of +1
$FragInputs.isFrontFace: output.isFrontFace = _DetViewMatrix < 0.0 ? output.isFrontFace : !output.isFrontFace;
#endif // SHADER_STAGE_FRAGMENT
return output;

1
com.unity.render-pipelines.high-definition/HDRP/RenderPipeline/HDStringConstants.cs


public static readonly int _NonJitteredViewProjMatrix = Shader.PropertyToID("_NonJitteredViewProjMatrix");
public static readonly int _ViewProjMatrix = Shader.PropertyToID("_ViewProjMatrix");
public static readonly int _InvViewProjMatrix = Shader.PropertyToID("_InvViewProjMatrix");
public static readonly int _DetViewMatrix = Shader.PropertyToID("_DetViewMatrix");
public static readonly int _ZBufferParams = Shader.PropertyToID("_ZBufferParams");
public static readonly int _ProjectionParams = Shader.PropertyToID("_ProjectionParams");
public static readonly int unity_OrthoParams = Shader.PropertyToID("unity_OrthoParams");

3
com.unity.render-pipelines.high-definition/HDRP/ShaderPass/VaryingMesh.hlsl


#if defined(VARYINGS_NEED_CULLFACE) && SHADER_STAGE_FRAGMENT
output.isFrontFace = IS_FRONT_VFACE(input.cullFace, true, false);
// Handle handness of the view matrix (In Unity view matrix default to a determinant of -1)
// when we render a cubemap the view matrix handness is flipped (due to convention used for cubemap) we have a determinant of +1
output.isFrontFace = _DetViewMatrix < 0.0 ? output.isFrontFace : !output.isFrontFace;
#endif
return output;

1
com.unity.render-pipelines.high-definition/HDRP/ShaderVariables.hlsl


#else
float3 _WorldSpaceCameraPos;
#endif
float _DetViewMatrix; // determinant(_ViewMatrix)
float4 _ScreenSize; // { w, h, 1 / w, 1 / h }
float4 _ScreenToTargetScale; // { w / RTHandle.maxWidth, h / RTHandle.maxHeight } : xy = currFrame, zw = prevFrame

正在加载...
取消
保存