浏览代码

Merge pull request #729 from Unity-Technologies/Fix-issue-with-shadow-and-tessellation-

Fix issue with tessellation and shadow
/feature-ReflectionProbeFit
GitHub 7 年前
当前提交
1d141127
共有 4 个文件被更改,包括 27 次插入7 次删除
  1. 17
      ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/GeometricTools.hlsl
  2. 2
      ScriptableRenderPipeline/Core/CoreRP/Shadow/Shadow.cs
  3. 4
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitDataMeshModification.hlsl
  4. 11
      ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Sky/VisualEnvironmentEditor.cs.meta

17
ScriptableRenderPipeline/Core/CoreRP/ShaderLibrary/GeometricTools.hlsl


return edgesOutside;
}
// Returns 'true' if a triangle defined by 3 vertices is back-facing.
// 'epsilon' is the (negative) value of dot(N, V) below which we cull the triangle.
// 'winding' can be used to change the order: pass 1 for (p0 -> p1 -> p2), or -1 for (p0 -> p2 -> p1).
bool CullTriangleBackFace(float3 p0, float3 p1, float3 p2, float epsilon, float3 viewPos, float winding)
bool CullTriangleBackFaceView(float3 p0, float3 p1, float3 p2, float epsilon, float3 V, float winding)
float3 N = cross(edge1, edge2);
float3 V = viewPos - p0;
float3 N = cross(edge1, edge2);
float NdotV = dot(N, V) * winding;
// Optimize:

// NdotV < Epsilon * sqrt(dot(N, N) * dot(V, V))
return NdotV < epsilon * sqrt(dot(N, N) * dot(V, V));
}
// Returns 'true' if a triangle defined by 3 vertices is back-facing.
// 'epsilon' is the (negative) value of dot(N, V) below which we cull the triangle.
// 'winding' can be used to change the order: pass 1 for (p0 -> p1 -> p2), or -1 for (p0 -> p2 -> p1).
bool CullTriangleBackFace(float3 p0, float3 p1, float3 p2, float epsilon, float3 viewPos, float winding)
{
float3 V = viewPos - p0;
return CullTriangleBackFaceView(p0, p1, p2, epsilon, V, winding);
}
#endif // UNITY_GEOMETRICTOOLS_INCLUDED

2
ScriptableRenderPipeline/Core/CoreRP/Shadow/Shadow.cs


}
else
vp = invvp = Matrix4x4.identity; // should never happen, though
if (cameraRelativeRendering)
{
Vector3 camPosWS = camera.transform.position;

m_TmpSplits[key.faceIdx].z -= camPosWS.z;
}
}
// write :(
ce.current.shadowAlgo = shadowAlgo;
m_EntryCache[ceIdx] = ce;

4
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Material/Lit/LitDataMeshModification.hlsl


{
// Handle transform mirroring (like negative scaling)
// Note: We don't need to handle handness of view matrix here as the backface is perform in worldspace
// note2: When we have an orthogonal matrix (cascade shadow map), we need to use the direction of the light.
// Otherwise we use only p0 instead of the mean of P0, p1,p2 to save ALU as with tessellated geomerty it is rarely needed and user can still control _TessellationBackFaceCullEpsilon.
faceCull = CullTriangleBackFace(p0, p1, p2, _TessellationBackFaceCullEpsilon, GetCurrentViewPosition(), winding); // Use shadow view
faceCull = CullTriangleBackFaceView(p0, p1, p2, _TessellationBackFaceCullEpsilon, GetWorldSpaceNormalizeViewDir(p0), winding); // Use shadow view
}
#endif

11
ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Sky/VisualEnvironmentEditor.cs.meta


fileFormatVersion: 2
guid: 42645a46defc138458b68060eda4785a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存