sebastienlagarde
8 年前
当前提交
589fe428
共有 14 个文件被更改,包括 361 次插入 和 37 次删除
-
4Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.hlsl
-
1Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Lit.shader
-
13Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitData.hlsl
-
29Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTesselation.hlsl
-
7Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.shader
-
3Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitDepthPass.hlsl
-
50Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitDistortionPass.hlsl
-
76Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitSharePass.hlsl
-
62Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitVelocityPass.hlsl
-
10Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Tesselation/TesselationShare.hlsl
-
7Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Unlit/Unlit.shader
-
1Assets/ScriptableRenderLoop/ShaderLibrary/CommonLighting.hlsl
-
17Assets/ScriptableRenderLoop/ShaderLibrary/Packing.hlsl
-
118Assets/ScriptableRenderLoop/ShaderLibrary/Tesselation.hlsl
|
|||
/* |
|||
float _Tess; |
|||
float _TessNear; |
|||
float _TessFar; |
|||
float _UseDisplacementfalloff; |
|||
float _DisplacementfalloffNear; |
|||
float _DisplacementfalloffFar; |
|||
*/ |
|||
float4 TesselationEdge(Attributes input0, Attributes input1, Attributes input2) |
|||
{ |
|||
float minDist = 0; // _TessNear; |
|||
float maxDist = 15; // _TessFar; |
|||
|
|||
return UnityDistanceBasedTess(input0.positionOS, input1.positionOS, input2.positionOS, minDist, maxDist, 0.5 /* _Tess */, unity_ObjectToWorld, _WorldSpaceCameraPos); |
|||
} |
|||
|
|||
void Displacement(inout Attributes v) |
|||
{ |
|||
/* |
|||
float LengthLerp = length(ObjSpaceViewDir(v.vertex)); |
|||
LengthLerp -= _DisplacementfalloffNear; |
|||
LengthLerp /= _DisplacementfalloffFar - _DisplacementfalloffNear; |
|||
LengthLerp = 1 - (saturate(LengthLerp)); |
|||
|
|||
float d = ((tex2Dlod(_DispTex, float4(v.texcoord.xy * _Tiling, 0, 0)).r) - _DisplacementCenter) * (_Displacement * LengthLerp); |
|||
d /= max(0.0001, _Tiling); |
|||
*/ |
|||
v.positionOS.xyz += float3(0.5, 0.5, 0.5); // v.normalOS * 5.0; |
|||
} |
|
|||
#define TESSELATION_INTERPOLATE_BARY(name, bary) ouput.name = input0.name * bary.x + input1.name * bary.y + input2.name * bary.z |
|||
|
|||
// ---- utility functions |
|||
float UnityCalcDistanceTessFactor(float3 positionOS, float minDist, float maxDist, float tess, float4x4 objectToWorld, float3 cameraPosWS) |
|||
{ |
|||
float3 positionWS = mul(objectToWorld, float4(positionOS, 1.0)).xyz; |
|||
float dist = distance(positionWS, cameraPosWS); |
|||
float f = clamp(1.0 - (dist - minDist) / (maxDist - minDist), 0.01, 1.0) * tess; |
|||
return f; |
|||
} |
|||
|
|||
float4 UnityCalcTriEdgeTessFactors(float3 triVertexFactors) |
|||
{ |
|||
float4 tess; |
|||
tess.x = 0.5 * (triVertexFactors.y + triVertexFactors.z); |
|||
tess.y = 0.5 * (triVertexFactors.x + triVertexFactors.z); |
|||
tess.z = 0.5 * (triVertexFactors.x + triVertexFactors.y); |
|||
tess.w = (triVertexFactors.x + triVertexFactors.y + triVertexFactors.z) / 3.0f; |
|||
return tess; |
|||
} |
|||
|
|||
/* |
|||
float UnityCalcEdgeTessFactor(float3 wpos0, float3 wpos1, float edgeLen) |
|||
{ |
|||
// distance to edge center |
|||
float dist = distance(0.5 * (wpos0 + wpos1), _WorldSpaceCameraPos); |
|||
// length of the edge |
|||
float len = distance(wpos0, wpos1); |
|||
// edgeLen is approximate desired size in pixels |
|||
float f = max(len * _ScreenParams.y / (edgeLen * dist), 1.0); |
|||
return f; |
|||
} |
|||
|
|||
float UnityDistanceFromPlane(float3 pos, float4 plane) |
|||
{ |
|||
float d = dot(float4(pos, 1.0f), plane); |
|||
return d; |
|||
} |
|||
|
|||
// Returns true if triangle with given 3 world positions is outside of camera's view frustum. |
|||
// cullEps is distance outside of frustum that is still considered to be inside (i.e. max displacement) |
|||
bool UnityWorldViewFrustumCull(float3 wpos0, float3 wpos1, float3 wpos2, float cullEps) |
|||
{ |
|||
float4 planeTest; |
|||
|
|||
// left |
|||
planeTest.x = ((UnityDistanceFromPlane(wpos0, unity_CameraWorldClipPlanes[0]) > -cullEps) ? 1.0f : 0.0f) + |
|||
((UnityDistanceFromPlane(wpos1, unity_CameraWorldClipPlanes[0]) > -cullEps) ? 1.0f : 0.0f) + |
|||
((UnityDistanceFromPlane(wpos2, unity_CameraWorldClipPlanes[0]) > -cullEps) ? 1.0f : 0.0f); |
|||
// right |
|||
planeTest.y = ((UnityDistanceFromPlane(wpos0, unity_CameraWorldClipPlanes[1]) > -cullEps) ? 1.0f : 0.0f) + |
|||
((UnityDistanceFromPlane(wpos1, unity_CameraWorldClipPlanes[1]) > -cullEps) ? 1.0f : 0.0f) + |
|||
((UnityDistanceFromPlane(wpos2, unity_CameraWorldClipPlanes[1]) > -cullEps) ? 1.0f : 0.0f); |
|||
// top |
|||
planeTest.z = ((UnityDistanceFromPlane(wpos0, unity_CameraWorldClipPlanes[2]) > -cullEps) ? 1.0f : 0.0f) + |
|||
((UnityDistanceFromPlane(wpos1, unity_CameraWorldClipPlanes[2]) > -cullEps) ? 1.0f : 0.0f) + |
|||
((UnityDistanceFromPlane(wpos2, unity_CameraWorldClipPlanes[2]) > -cullEps) ? 1.0f : 0.0f); |
|||
// bottom |
|||
planeTest.w = ((UnityDistanceFromPlane(wpos0, unity_CameraWorldClipPlanes[3]) > -cullEps) ? 1.0f : 0.0f) + |
|||
((UnityDistanceFromPlane(wpos1, unity_CameraWorldClipPlanes[3]) > -cullEps) ? 1.0f : 0.0f) + |
|||
((UnityDistanceFromPlane(wpos2, unity_CameraWorldClipPlanes[3]) > -cullEps) ? 1.0f : 0.0f); |
|||
|
|||
// has to pass all 4 plane tests to be visible |
|||
return !all(planeTest); |
|||
} |
|||
*/ |
|||
|
|||
// ---- functions that compute tessellation factors |
|||
// 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) |
|||
{ |
|||
float3 f; |
|||
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); |
|||
return UnityCalcTriEdgeTessFactors(f); |
|||
} |
|||
|
|||
/* |
|||
// Desired edge length based tessellation: |
|||
// Approximate resulting edge length in pixels is "edgeLength". |
|||
// Does not take viewing FOV into account, just flat out divides factor by distance. |
|||
float4 UnityEdgeLengthBasedTess(float4 v0, float4 v1, float4 v2, float edgeLength) |
|||
{ |
|||
float3 pos0 = mul(unity_ObjectToWorld, v0).xyz; |
|||
float3 pos1 = mul(unity_ObjectToWorld, v1).xyz; |
|||
float3 pos2 = mul(unity_ObjectToWorld, v2).xyz; |
|||
float4 tess; |
|||
tess.x = UnityCalcEdgeTessFactor(pos1, pos2, edgeLength); |
|||
tess.y = UnityCalcEdgeTessFactor(pos2, pos0, edgeLength); |
|||
tess.z = UnityCalcEdgeTessFactor(pos0, pos1, edgeLength); |
|||
tess.w = (tess.x + tess.y + tess.z) / 3.0f; |
|||
return tess; |
|||
} |
|||
|
|||
// Same as UnityEdgeLengthBasedTess, but also does patch frustum culling: |
|||
// patches outside of camera's view are culled before GPU tessellation. Saves some wasted work. |
|||
float4 UnityEdgeLengthBasedTessCull(float4 v0, float4 v1, float4 v2, float edgeLength, float maxDisplacement) |
|||
{ |
|||
float3 pos0 = mul(unity_ObjectToWorld, v0).xyz; |
|||
float3 pos1 = mul(unity_ObjectToWorld, v1).xyz; |
|||
float3 pos2 = mul(unity_ObjectToWorld, v2).xyz; |
|||
float4 tess; |
|||
if (UnityWorldViewFrustumCull(pos0, pos1, pos2, maxDisplacement)) |
|||
{ |
|||
tess = 0.0f; |
|||
} |
|||
else |
|||
{ |
|||
tess.x = UnityCalcEdgeTessFactor(pos1, pos2, edgeLength); |
|||
tess.y = UnityCalcEdgeTessFactor(pos2, pos0, edgeLength); |
|||
tess.z = UnityCalcEdgeTessFactor(pos0, pos1, edgeLength); |
|||
tess.w = (tess.x + tess.y + tess.z) / 3.0f; |
|||
} |
|||
return tess; |
|||
} |
|||
*/ |
撰写
预览
正在加载...
取消
保存
Reference in new issue