浏览代码
Merge pull request #93 from Unity-Technologies/Improve-tessellation
Merge pull request #93 from Unity-Technologies/Improve-tessellation
HDRenderPipeline: Add Phong tesselation/main
GitHub
8 年前
当前提交
52f8c9ce
共有 24 个文件被更改,包括 367 次插入 和 178 次删除
-
11Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/Editor/LayeredLitUI.cs
-
15Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader
-
133Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/BaseLitUI.cs
-
14Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/Editor/LitUI.cs
-
8Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitData.hlsl
-
11Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitProperties.hlsl
-
51Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.shader
-
28Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitDepthPass.hlsl
-
24Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitDistortionPass.hlsl
-
32Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitSharePass.hlsl
-
26Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/ShaderPass/LitVelocityPass.hlsl
-
33Assets/ScriptableRenderLoop/ShaderLibrary/Tessellation.hlsl
-
41Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.hlsl
-
77Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Tessellation/TessellationShare.hlsl
-
41Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTesselation.hlsl
-
0/Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader.meta
-
0/Assets/ScriptableRenderLoop/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader
-
0/Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Lit/LitTessellation.hlsl.meta
-
0/Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Tessellation.meta
-
0/Assets/ScriptableRenderLoop/ShaderLibrary/Tessellation.hlsl.meta
-
0/Assets/ScriptableRenderLoop/ShaderLibrary/Tessellation.hlsl
-
0/Assets/ScriptableRenderLoop/HDRenderPipeline/Material/Tessellation/TessellationShare.hlsl.meta
|
|||
/* |
|||
float _Tess; |
|||
float _TessNear; |
|||
float _TessFar; |
|||
float _UseDisplacementfalloff; |
|||
float _DisplacementfalloffNear; |
|||
float _DisplacementfalloffFar; |
|||
*/ |
|||
|
|||
float4 TessellationEdge(float3 p0, float3 p1, float3 p2, float3 n0, float3 n1, float3 n2) |
|||
{ |
|||
// if (_TessellationFactorFixed >= 0.0f) |
|||
{ |
|||
// return _TessellationFactorFixed.xxxx; |
|||
} |
|||
|
|||
return DistanceBasedTess(p0, p1, p2, 0.0, _TessellationFactorMaxDistance, unity_ObjectToWorld, _WorldSpaceCameraPos) * _TessellationFactorFixed.xxxx; |
|||
} |
|||
|
|||
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); |
|||
*/ |
|||
|
|||
#ifdef _HEIGHTMAP |
|||
float height = (SAMPLE_TEXTURE2D_LOD(ADD_ZERO_IDX(_HeightMap), ADD_ZERO_IDX(sampler_HeightMap), v.uv0, 0).r - ADD_ZERO_IDX(_HeightCenter)) * ADD_IDX(_HeightAmplitude); |
|||
#else |
|||
float height = 0.0; |
|||
#endif |
|||
|
|||
#if (SHADERPASS != SHADERPASS_VELOCITY) && (SHADERPASS != SHADERPASS_DISTORTION) |
|||
v.positionOS.xyz += height * v.normalOS; |
|||
#endif |
|||
} |
|
|||
AttributesTessellation VertTessellation(Attributes input) |
|||
{ |
|||
return AttributesToAttributesTessellation(input); |
|||
} |
|||
|
|||
struct TessellationFactors |
|||
{ |
|||
float edge[3] : SV_TessFactor; |
|||
float inside : SV_InsideTessFactor; |
|||
}; |
|||
|
|||
TessellationFactors HullConstant(InputPatch<AttributesTessellation, 3> input) |
|||
{ |
|||
Attributes params[3]; |
|||
params[0] = AttributesTessellationToAttributes(input[0]); |
|||
params[1] = AttributesTessellationToAttributes(input[1]); |
|||
params[2] = AttributesTessellationToAttributes(input[2]); |
|||
|
|||
#if (SHADERPASS != SHADERPASS_VELOCITY) && (SHADERPASS != SHADERPASS_DISTORTION) |
|||
|
|||
// TEMP: We will provide world position but for now convert to world position here |
|||
float3 p0 = TransformObjectToWorld(input[0].positionOS); |
|||
float3 n0 = TransformObjectToWorldNormal(input[0].normalOS); |
|||
|
|||
float3 p1 = TransformObjectToWorld(input[1].positionOS); |
|||
float3 n1 = TransformObjectToWorldNormal(input[1].normalOS); |
|||
|
|||
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); |
|||
#endif |
|||
|
|||
TessellationFactors ouput; |
|||
ouput.edge[0] = tf.x; |
|||
ouput.edge[1] = tf.y; |
|||
ouput.edge[2] = tf.z; |
|||
ouput.inside = tf.w; |
|||
|
|||
return ouput; |
|||
} |
|||
|
|||
[maxtessfactor(15.0)] // AMD recommand this value for GCN http://amd-dev.wpengine.netdna-cdn.com/wordpress/media/2013/05/GCNPerformanceTweets.pdf |
|||
[domain("tri")] |
|||
[partitioning("fractional_odd")] |
|||
[outputtopology("triangle_cw")] |
|||
[patchconstantfunc("HullConstant")] |
|||
[outputcontrolpoints(3)] |
|||
AttributesTessellation Hull(InputPatch<AttributesTessellation, 3> input, uint id : SV_OutputControlPointID) |
|||
{ |
|||
return input[id]; |
|||
} |
|||
|
|||
[domain("tri")] |
|||
PackedVaryings Domain(TessellationFactors tessFactors, const OutputPatch<AttributesTessellation, 3> input, float3 baryCoords : SV_DomainLocation) |
|||
{ |
|||
Attributes params = InterpolateWithBaryCoords(input[0], input[1], input[2], baryCoords); |
|||
|
|||
#ifndef _TESSELLATION_DISPLACEMENT // We have Phong tessellation in all case where we don't have only displacement |
|||
#if (SHADERPASS != SHADERPASS_VELOCITY) && (SHADERPASS != SHADERPASS_DISTORTION) |
|||
params.positionOS = PhongTessellation( params.positionOS, |
|||
input[0].positionOS, input[1].positionOS, input[2].positionOS, |
|||
input[0].normalOS, input[1].normalOS, input[2].normalOS, |
|||
baryCoords, _TessellationShapeFactor); |
|||
#endif |
|||
#endif |
|||
|
|||
// perform displacement |
|||
Displacement(params); |
|||
|
|||
// Evaluate regular vertex shader |
|||
PackedVaryings outout = Vert(params); |
|||
|
|||
return outout; |
|||
} |
|
|||
/* |
|||
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); |
|||
|
|||
return float4(_TesselationFactor, _TesselationFactor, _TesselationFactor, _TesselationFactor); |
|||
} |
|||
|
|||
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); |
|||
*/ |
|||
|
|||
#ifdef _HEIGHTMAP |
|||
float height = (SAMPLE_TEXTURE2D_LOD(ADD_ZERO_IDX(_HeightMap), ADD_ZERO_IDX(sampler_HeightMap), v.uv0, 0).r - ADD_ZERO_IDX(_HeightCenter)) * ADD_IDX(_HeightAmplitude); |
|||
#else |
|||
float height = 0.0; |
|||
#endif |
|||
|
|||
#if (SHADERPASS != SHADERPASS_VELOCITY) && (SHADERPASS != SHADERPASS_DISTORTION) |
|||
v.positionOS.xyz += height * v.normalOS; |
|||
#endif |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue