Hello,
I’ve followed several threads to try and get a quad tessellation shader working in Unity 2019.2.15f1, but I am getting some strange tessellations. The problem is simplest on a Quad and I’ve uploaded a picture of a quad with a uniform tessellation factor of 2.
Here’s my tessellation programs:
TessellationFactors PatchConstant(InputPatch<TessellationControlPoint, 4> patch) {
float3 p0 = mul(unity_ObjectToWorld, patch[0].vertex).xyz;
float3 p1 = mul(unity_ObjectToWorld, patch[1].vertex).xyz;
float3 p2 = mul(unity_ObjectToWorld, patch[2].vertex).xyz;
float3 p3 = mul(unity_ObjectToWorld, patch[3].vertex).xyz;
TessellationFactors f;
f.edge[0] = TessellationEdgeFactor(p0, p1);
f.edge[1] = TessellationEdgeFactor(p1, p2);
f.edge[2] = TessellationEdgeFactor(p2, p3);
f.edge[3] = TessellationEdgeFactor(p3, p0);
f.inside[0] = (TessellationEdgeFactor(p1, p2) +
TessellationEdgeFactor(p2, p3) +
TessellationEdgeFactor(p3, p0) +
TessellationEdgeFactor(p0, p1)) * (1 / 4.0);
f.inside[1] = f.inside[0];
return f;
}
[UNITY_domain("quad")]
[UNITY_outputcontrolpoints(4)]
[UNITY_outputtopology("triangle_cw")]
[UNITY_partitioning("fractional_odd")]
[UNITY_patchconstantfunc("PatchConstant")]
TessellationControlPoint Hull(InputPatch<TessellationControlPoint, 4> patch, uint id : SV_OutputControlPointID)
{
return patch[id];
}
[UNITY_domain("quad")]
v2fVertex Domain(TessellationFactors factors, OutputPatch<TessellationControlPoint, 4> patch, float2 UV : SV_DomainLocation)
{
VertexData data;
#define DOMAIN_INTERPOLATE(fieldName) data.fieldName = lerp(lerp(patch[0].fieldName, patch[1].fieldName, UV.x), lerp(patch[2].fieldName, patch[3].fieldName, UV.x), UV.y);
DOMAIN_INTERPOLATE(vertex)
DOMAIN_INTERPOLATE(normal)
DOMAIN_INTERPOLATE(tangent)
DOMAIN_INTERPOLATE(uv)
DOMAIN_INTERPOLATE(uv1)
DOMAIN_INTERPOLATE(uv2)
return Vertex(data);
}
Let me know if I should post more. I’ve messed around quite a bit with the permutation of control points in the domain program. I got through about 12 before realizing that all the permutations give me a variation of the mess that is the mesh.
I’m not sure what else to try. If any of you have suggestions or solutions, I’m open to them.