Created
May 16, 2020 17:51
-
-
Save niuage/ed730f36423f25b8e1f452a828c68808 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Tessellation programs based on this article by Catlike Coding: | |
// https://catlikecoding.com/unity/tutorials/advanced-rendering/tessellation/ | |
struct vertexInput | |
{ | |
float4 vertex : POSITION; | |
float3 normal : NORMAL; | |
float4 tangent : TANGENT; | |
}; | |
struct vertexOutput | |
{ | |
float4 vertex : SV_POSITION; | |
float3 normal : NORMAL; | |
float4 tangent : TANGENT; | |
}; | |
struct TessellationFactors | |
{ | |
float edge[3] : SV_TessFactor; | |
float inside : SV_InsideTessFactor; | |
}; | |
vertexInput vert(vertexInput v) | |
{ | |
return v; | |
} | |
vertexOutput tessVert(vertexInput v) | |
{ | |
vertexOutput o; | |
// Note that the vertex is NOT transformed to clip | |
// space here; this is done in the grass geometry shader. | |
o.vertex = v.vertex; | |
o.normal = v.normal; | |
o.tangent = v.tangent; | |
return o; | |
} | |
float _TessellationUniform; | |
TessellationFactors patchConstantFunction (InputPatch<vertexInput, 3> patch) | |
{ | |
TessellationFactors f; | |
f.edge[0] = _TessellationUniform; | |
f.edge[1] = _TessellationUniform; | |
f.edge[2] = _TessellationUniform; | |
f.inside = _TessellationUniform; | |
return f; | |
} | |
[UNITY_domain("tri")] | |
[UNITY_outputcontrolpoints(3)] | |
[UNITY_outputtopology("triangle_cw")] | |
[UNITY_partitioning("integer")] | |
[UNITY_patchconstantfunc("patchConstantFunction")] | |
vertexInput hull (InputPatch<vertexInput, 3> patch, uint id : SV_OutputControlPointID) | |
{ | |
return patch[id]; | |
} | |
[UNITY_domain("tri")] | |
vertexOutput domain(TessellationFactors factors, OutputPatch<vertexInput, 3> patch, float3 barycentricCoordinates : SV_DomainLocation) | |
{ | |
vertexInput v; | |
#define MY_DOMAIN_PROGRAM_INTERPOLATE(fieldName) v.fieldName = \ | |
patch[0].fieldName * barycentricCoordinates.x + \ | |
patch[1].fieldName * barycentricCoordinates.y + \ | |
patch[2].fieldName * barycentricCoordinates.z; | |
MY_DOMAIN_PROGRAM_INTERPOLATE(vertex) | |
MY_DOMAIN_PROGRAM_INTERPOLATE(normal) | |
MY_DOMAIN_PROGRAM_INTERPOLATE(tangent) | |
return tessVert(v); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment