Forum

Whats wrong with my tessellation shader?


#1

hey guys,
I try to write a simple tessellation shader. It compiles but I dont see anything on the screen. Can somebody tell me whats wrong?

Because I am not allowed to upload files here is my code:

SamplerState linearSampler : IMMUTABLE
{
    Filter = MIN_MAG_MIP_LINEAR;
    AddressU = Clamp;
    AddressV = Clamp;
};

cbuffer cbPerDraw : register( b0 )
{
    float4x4 tVP : LAYERVIEWPROJECTION;	
};

cbuffer cbPerObj : register( b1 )
{
	float4x4 tW : WORLD;
	float4 cAmb <bool color=true;String uiname="Color";> = { 1.0f,1.0f,1.0f,1.0f };
	float TessFactor <String uiname="tessellationAmount";> = 1.0f;
};

struct VS_INPUT
{
	float4 ObjectPosition : POSITION;
};

struct VS_OUTPUT
{
	float4 ObjectPosition : POSITION;
};

struct HS_CONSTANT_OUTPUT
{
	float EdgeFactors[3] : SV_TessFactor;
	float InsideFactor : SV_InsideTessFactor;
};

struct HS_OUTPUT
{
	float4 ObjectPosition : POSITION;
};

struct DS_OUTPUT
{
	float4 Position : SV_Position;
};

///VERTEX SHADER
VS_OUTPUT vertex_shader(VS_INPUT input)
{
	VS_OUTPUT output = (VS_OUTPUT)0;
	output.ObjectPosition = input.ObjectPosition;
	return output;
}

///HULL SHADER
HS_CONSTANT_OUTPUT constant_hull_shader(InputPatch<VS_OUTPUT, 3> patch)
{
	HS_CONSTANT_OUTPUT output = (HS_CONSTANT_OUTPUT)0;
	output.EdgeFactors[0] = TessFactor;
	output.EdgeFactors[1] = TessFactor;
	output.EdgeFactors[2] = TessFactor;
	output.InsideFactor = TessFactor;
	return output;
}


[domain("tri")]
[partitioning("fractional_odd")]
[outputtopology("triangle_cw")]
[outputcontrolpoints(3)]
[patchconstantfunc("constant_hull_shader")]
HS_OUTPUT hull_shader(InputPatch<VS_OUTPUT,3> patch, uint controlPointID:SV_OutputControlPointID)
{
	HS_OUTPUT output = (HS_OUTPUT)0;
	output.ObjectPosition = patch[controlPointID].ObjectPosition;
	return output;
}


///DOMAIN SHADER
[domain("tri")]
DS_OUTPUT domain_shader(HS_CONSTANT_OUTPUT input, float3 uvw:SV_DomainLocation, const OutputPatch<HS_OUTPUT,3> patch)
{
	DS_OUTPUT output = (DS_OUTPUT)0;
	float3 objectPosition = uvw.x*patch[0].ObjectPosition.xyz + uvw.y*patch[1].ObjectPosition.xyz + uvw.z*patch[2].ObjectPosition.xyz;
	output.Position = mul(float4(objectPosition,1.0f),mul(tW,tVP));
	return output;
}

///PIXEL SHADER
float4 pixel_shader(DS_OUTPUT input) : SV_Target
{
	return cAmb;
}

///TECHNIQUES

technique11 Tessellation
{
	pass P0
	{
		SetVertexShader(CompileShader(vs_5_0, vertex_shader()));
		SetHullShader(CompileShader(hs_5_0, hull_shader()));
		SetDomainShader(CompileShader(ds_5_0, domain_shader()));
		SetPixelShader(CompileShader(ps_5_0, pixel_shader()));
	}
}

thank you


#2

Make sure you have a Topology node before the geometry set to afair Patch[N]ControlPoints or something similar where [N] is the number of control points in your primitives (3 for triangles obviously)


#3

ah! Thank you very much! now it works fine!