浏览代码

HDRenderPipeline: Make distance based edge factor (WIP, lot of thing to change)

/main
Sebastien Lagarde 8 年前
当前提交
b60287f0
共有 5 个文件被更改,包括 11 次插入15 次删除
  1. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader
  2. 8
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.hlsl
  3. 2
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.shader
  4. 1
      Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Tessellation/TessellationShare.hlsl
  5. 13
      Assets/ScriptableRenderLoop/ShaderLibrary/Tessellation.hlsl

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader


// Tesselation specific
[Enum(Phong, 0, Displacement, 1, DisplacementPhong, 2)] _TessellationMode("Tessellation mode", Float) = 1
_TessellationFactorFixed("Tessellation Factor", Float) = -1.0 // if != -1.0 force fixed factor
_TessellationFactorFixed("Tessellation Factor", Float) = 4.0 // if != -1.0 force fixed factor
_TessellationFactorMaxDistance("Tessellation max distance factor", Float) = 12.0
_TessellationFactorTriangleSize("Tessellation triangle size", Float) = 20.0
_TessellationShapeFactor("Tessellation shape factor", Range(0.0, 1.0)) = 0.75 // Only use with Phong

8
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.hlsl


float4 TessellationEdge(float3 p0, float3 p1, float3 p2, float3 n0, float3 n1, float3 n2)
{
if (_TessellationFactorFixed >= 0.0f)
// if (_TessellationFactorFixed >= 0.0f)
return _TessellationFactorFixed.xxxx;
// return _TessellationFactorFixed.xxxx;
return _TessellationFactorFixed.xxxx;
// return UnityDistanceBasedTess(input0.positionOS, input1.positionOS, input2.positionOS, minDist, maxDist, 0.5 /* _Tess */, unity_ObjectToWorld, _WorldSpaceCameraPos);
return DistanceBasedTess(p0, p1, p2, 0.0, _TessellationFactorMaxDistance, unity_ObjectToWorld, _WorldSpaceCameraPos) * _TessellationFactorFixed.xxxx;
}
void Displacement(inout Attributes v)

2
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.shader


// Tessellation specific
[Enum(Phong, 0, Displacement, 1, DisplacementPhong, 2)] _TessellationMode("Tessellation mode", Float) = 0
_TessellationFactorFixed("Tessellation Factor", Float) = -1.0 // if != -1.0 force fixed factor
_TessellationFactorFixed("Tessellation Factor", Float) = 4.0 // if != -1.0 force fixed factor
_TessellationFactorMaxDistance("Tessellation max distance factor", Float) = 12.0
_TessellationFactorTriangleSize("Tessellation triangle size", Float) = 20.0
_TessellationShapeFactor("Tessellation shape factor", Range(0.0, 1.0)) = 0.75 // Only use with Phong

1
Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Tessellation/TessellationShare.hlsl


float3 p2 = TransformObjectToWorld(input[2].positionOS);
float3 n2 = TransformObjectToWorldNormal(input[2].normalOS);
float4 tf = TessellationEdge(p0, p1, p2, n0, n1, n2);
#else
float4 tf = float4(0.0, 0.0, 0.0, 0.0);

13
Assets/ScriptableRenderLoop/ShaderLibrary/Tessellation.hlsl


}
// ---- 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);
}

正在加载...
取消
保存