Hi, I’m trying to write a shader for my terrane with quad tesselation. But I have a problem. In what may be the reason, any suggestions? With tri-tessellation mode there is no problem.
Shader "Quad tesselation" {
SubShader {
Pass { Tags {"LightMode" = "Vertex"}
CGPROGRAM
#pragma vertex vert
#pragma hull hull
#pragma domain domain
#pragma fragment frag
#include "UnityCG.cginc"
//=================================================================================================================================
// Shader structures
//=================================================================================================================================
struct VS_INPUT
{
float3 position : POSITION;
};
struct VS_OUTPUT
{
float4 position : POSITION;
};
struct HS_CONSTANT_DATA_OUTPUT
{
float Edges[4] : SV_TessFactor;
float Inside[2] : SV_InsideTessFactor;
};
struct HS_OUTPUT
{
float3 position : POS;
};
struct DS_OUTPUT
{
float4 position : SV_Position;
};
//=================================================================================================================================
// Vertex shader
//=================================================================================================================================
VS_OUTPUT vert(VS_INPUT v)
{
VS_OUTPUT output;
output.position = mul(UNITY_MATRIX_MV, float4(v.position, 1.0));
return output;
}
//=================================================================================================================================
// Hull shader
//=================================================================================================================================
HS_CONSTANT_DATA_OUTPUT constantsHS(InputPatch<VS_OUTPUT, 4> patch)
{
HS_CONSTANT_DATA_OUTPUT output = (HS_CONSTANT_DATA_OUTPUT)0;
output.Edges[0] = output.Edges[1] = output.Edges[2] = output.Edges[3] = 2;
output.Inside[0] = output.Inside[1] = 2;
return output;
}
[domain("quad")]
[partitioning("fractional_odd")]
[outputtopology("triangle_cw")]
[outputcontrolpoints(4)]
[patchconstantfunc("constantsHS")]
HS_OUTPUT hull(InputPatch<VS_OUTPUT, 4> patch, uint uCPID: SV_OutputControlPointID)
{
HS_OUTPUT output = (HS_OUTPUT)0;
output.position = patch[uCPID].position.xyz;
return output;
}
//=================================================================================================================================
// Domain shader
//=================================================================================================================================
[domain("quad")]
DS_OUTPUT domain(HS_CONSTANT_DATA_OUTPUT input, const OutputPatch<HS_OUTPUT, 4> patch, float2 UV : SV_DomainLocation)
{
DS_OUTPUT output = (DS_OUTPUT)0;
float3 topMidpoint = lerp(patch[0].position, patch[1].position, UV.x);
float3 bottomMidpoint = lerp(patch[3].position, patch[2].position, UV.x);
float3 pos = lerp(topMidpoint, bottomMidpoint, UV.y);
output.position = mul(UNITY_MATRIX_P, float4(pos, 1.0));
return output;
}
//=================================================================================================================================
// Fragment shader
//=================================================================================================================================
float4 frag(DS_OUTPUT f) : COLOR
{
float4 c;
c.b = 0.5;
return c;
}
ENDCG
}
}
}