浏览代码

Further optimize CullTriangleBackFace()

/Yibing-Project-2
Evgenii Golubev 7 年前
当前提交
3ed7cefd
共有 2 个文件被更改,包括 6 次插入7 次删除
  1. 6
      ScriptableRenderPipeline/Core/ShaderLibrary/GeometricTools.hlsl
  2. 7
      ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitDataMeshModification.hlsl

6
ScriptableRenderPipeline/Core/ShaderLibrary/GeometricTools.hlsl


// 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.
bool CullTriangleBackFace(float3 p0, float3 p1, float3 p2, float epsilon, float3 viewPos)
// '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 edge1 = p1 - p0;
float3 edge2 = p2 - p0;

float NdotV = dot(N, V);
float NdotV = dot(N, V) * winding;
// Optimize:
// NdotV / (length(N) * length(V)) < Epsilon

7
ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitDataMeshModification.hlsl


if (_TessellationBackFaceCullEpsilon > -1) // Is backface culling enabled ?
{
// Handle transform mirroring (like negative scaling)
// Caution: don't change p1/p2 directly as it is use later
float3 backfaceP1 = unity_WorldTransformParams.w < 0.0 ? p2 : p1;
float3 backfaceP2 = unity_WorldTransformParams.w < 0.0 ? p1 : p2;
faceCull = CullTriangleBackFace(p0, backfaceP1, backfaceP2, _TessellationBackFaceCullEpsilon, GetCurrentViewPosition()); // Use shadow view
float winding = unity_WorldTransformParams.w;
faceCull = CullTriangleBackFace(p0, p1, p2, _TessellationBackFaceCullEpsilon, GetCurrentViewPosition(), winding); // Use shadow view
}
#endif

正在加载...
取消
保存