Hello,
I’m trying to create a shader that draws a circle and tessellates its edges. I’m using DX11 tessellation in the isoline domain.
The mesh is a succession of points along the circle (cosA, sinA, 0), and uses MeshTopology.LineStrip. It renders fine using unlit shader, so everything is fine on this side.
Since surface shader do not support isoline tessellation, I had to piece together a complete tessellation shader. As far as i understand, this should work in unity.
Here is what i have so far, Vertex and Fragment seems to be working fine : if i comment #pragma domain, and #pragma hull, and multiply the vertex position in the VS, the circle is correctly drawn.
However when i uncomment the tessellation pragmas, and multiply in the domain, the circle disappears. Could you please tell me what i am doing wrong? I tried to read all the documentation I could find about DX11 tessellation and as far as i understand, this should run fine… but that stuff is pretty violent, so i guess i’m missing something obvious.
I’m just trying to subdivide the lines so far, i’ll displace and smooth them when i manage to actually see them
Any help would be greatly appreciated, thanks!
PS : This is the shader i am basing most of the code on
Shader "Gizmos/ColoredLine"
{
Properties
{
_Color("Color", color) = (1,1,1,1)
_Detail("Detail", Range(1, 10.0)) = 1
_Density("Density", Range(1, 10.0)) = 1
}
SubShader {
Tags{ "RenderType" = "Opaque" }
Pass{
CGPROGRAM
#pragma vertex VS
#pragma fragment PS
#pragma hull HS
#pragma domain DS
#pragma target 5.0
#include "UnityCG.cginc"
#define INTERNAL_DATA
struct IA_OUTPUT
{
float4 cpoint : POSITION;
};
struct VS_OUTPUT
{
float4 cpoint : SV_POSITION;
};
// VERTEX SHADER
VS_OUTPUT VS(IA_OUTPUT input)
{
VS_OUTPUT output;
output.cpoint = input.cpoint;
//output.cpoint = mul(UNITY_MATRIX_MVP, input.cpoint);
return output;
}
// TESSELLATION CONSTANT PATCH
//#ifdef UNITY_CAN_COMPILE_TESSELLATION
struct HS_CONSTANT_OUTPUT
{
float edges[2] : SV_TessFactor;
};
float _Detail, _Density;
HS_CONSTANT_OUTPUT HSConst()
{
HS_CONSTANT_OUTPUT output;
output.edges[0] = _Detail;
output.edges[1] = _Density;
return output;
}
// TESSELLATION HULL SHADER
[domain("isoline")]
[partitioning("integer")]
[outputtopology("line")]
[outputcontrolpoints(4)]
[patchconstantfunc("HSConst")]
VS_OUTPUT HS(InputPatch<VS_OUTPUT, 4> ip, uint id : SV_OutputControlPointID)
{
return ip[id];
}
struct DS_OUTPUT
{
float4 position : SV_POSITION;
};
// tessellation domain shader
[domain("isoline")]
DS_OUTPUT DS(HS_CONSTANT_OUTPUT input, OutputPatch<VS_OUTPUT, 4> op, float2 uv : SV_DomainLocation)
{
DS_OUTPUT output;
float3 pos = lerp(op[0].cpoint.xyz, op[1].cpoint.xyz, uv.x);
output.position = mul(UNITY_MATRIX_MVP, float4(pos,1));
//output.position = float4(pos, 1.0f);
return output;
}
//#endif // UNITY_CAN_COMPILE_TESSELLATION
float4 _Color;
float4 PS(DS_OUTPUT input) : SV_Target0
{
return _Color;
}
ENDCG
}
}
}