|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// ---- utility functions |
|
|
|
float UnityCalcDistanceTessFactor(float3 positionOS, float minDist, float maxDist, float tess, float4x4 objectToWorld, float3 cameraPosWS) |
|
|
|
float CalcDistanceTessFactor(float3 positionWS, float minDist, float maxDist, float4x4 objectToWorld, float3 cameraPosWS) |
|
|
|
float3 positionWS = mul(objectToWorld, float4(positionOS, 1.0)).xyz; |
|
|
|
float f = clamp(1.0 - (dist - minDist) / (maxDist - minDist), 0.01, 1.0) * tess; |
|
|
|
float f = clamp(1.0 - (dist - minDist) / (maxDist - minDist), 0.01, 1.0); |
|
|
|
return f; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
// Distance based tessellation: |
|
|
|
// Tessellation level is "tess" before "minDist" from camera, and linearly decreases to 1 |
|
|
|
// up to "maxDist" from camera. |
|
|
|
float4 UnityDistanceBasedTess(float3 positionOS0, float3 positionOS1, float3 positionOS2, float minDist, float maxDist, float tess, float4x4 objectToWorld, float3 cameraPosWS) |
|
|
|
float4 DistanceBasedTess(float3 p0, float3 p1, float3 p2, float minDist, float maxDist, float4x4 objectToWorld, float3 cameraPosWS) |
|
|
|
f.x = UnityCalcDistanceTessFactor(positionOS0, minDist, maxDist, tess, objectToWorld, cameraPosWS); |
|
|
|
f.y = UnityCalcDistanceTessFactor(positionOS1, minDist, maxDist, tess, objectToWorld, cameraPosWS); |
|
|
|
f.z = UnityCalcDistanceTessFactor(positionOS2, minDist, maxDist, tess, objectToWorld, cameraPosWS); |
|
|
|
f.x = CalcDistanceTessFactor(p0, minDist, maxDist, objectToWorld, cameraPosWS); |
|
|
|
f.y = CalcDistanceTessFactor(p1, minDist, maxDist, objectToWorld, cameraPosWS); |
|
|
|
f.z = CalcDistanceTessFactor(p2, minDist, maxDist, objectToWorld, cameraPosWS); |
|
|
|
return UnityCalcTriEdgeTessFactors(f); |
|
|
|
} |
|
|
|
|
|
|
|