An issue with tessellation a model with DirectX11

Posted by Paul Ske on Game Development See other posts from Game Development or by Paul Ske
Published on 2013-10-23T13:44:20Z Indexed on 2013/10/23 16:11 UTC
Read the original article Hit count: 503

Filed under:

I took the hardware tessellation tutorial from Rastertek and implemended texturing instead of color. This is great, so I wanted to implemended the same techique to a model inside my game editor and I noticed it doesn't draw anything. I compared the detailed tessellation from DirectX SDK sample. Inside the shader file - if I replace the HullInputType with PixelInputType it draws. So, I think because when I compiled the shaders inside the program it compiles VertexShader, PixelShader, HullShader then DomainShader. Isn't it suppose to be VertexShader, HullSHader, DomainShader then PixelShader or does it really not matter?

I am just curious why wouldn't the model even be drawn when HullInputType but renders fine with PixelInputType.

Shader Code:

[code] cbuffer ConstantBuffer { float4x4 WVP; float4x4 World; // the rotation matrix float3 lightvec; // the light's vector float4 lightcol; // the light's color float4 ambientcol; // the ambient light's color bool isSelected; }

cbuffer cameraBuffer { float3 cameraDirection; float padding; }

cbuffer TessellationBuffer { float tessellationAmount; float3 padding2;

}

struct ConstantOutputType {

float edges[3] : SV_TessFactor; float inside : SV_InsideTessFactor;

};

Texture2D Texture; Texture2D NormalTexture;

SamplerState ss { MinLOD = 5.0f; MipLODBias = 0.0f; };

struct HullOutputType { float3 position : POSITION; float2 texcoord : TEXCOORD0; float3 normal : NORMAL; float3 tangent : TANGENT;

};

struct HullInputType { float4 position : POSITION; float2 texcoord : TEXCOORD0; float3 normal : NORMAL; float3 tangent : TANGENT;

}; struct VertexInputType {

float4 position : POSITION; float2 texcoord : TEXCOORD; float3 normal : NORMAL; float3 tangent : TANGENT; uint uVertexID : SV_VERTEXID; };

struct PixelInputType {

float4 position : SV_POSITION;
float2 texcoord : TEXCOORD0;    // texture coordinates
float3 normal : NORMAL;
float3 tangent : TANGENT;
float4 color : COLOR;
float3 viewDirection : TEXCOORD1;
float4 depthBuffer : TEXTURE0;

};

HullInputType VShader(VertexInputType input) { HullInputType output;

output.position.w = 1.0f;

output.position = mul(input.position,WVP);
output.texcoord = input.texcoord;
output.normal = input.normal;
output.tangent = input.tangent;

//output.normal = mul(normal,World);
//output.tangent = mul(tangent,World);

//output.color = output.color;
//output.texcoord = texcoord;    // set the texture coordinates, unmodified

return output;

}

ConstantOutputType TexturePatchConstantFunction(InputPatch inputPatch,uint patchID : SV_PrimitiveID) {

ConstantOutputType output;

output.edges[0] = tessellationAmount; output.edges[1] = tessellationAmount; output.edges[2] = tessellationAmount;

output.inside = tessellationAmount;

return output; }

[domain("tri")] [partitioning("integer")] [outputtopology("triangle_cw")] [outputcontrolpoints(3)] [patchconstantfunc("TexturePatchConstantFunction")]

HullOutputType HShader(InputPatch patch, uint pointId : SV_OutputControlPointID, uint patchId : SV_PrimitiveID) { HullOutputType output;

// Set the position for this control point as the output position.
output.position = patch[pointId].position;

// Set the input color as the output color.
output.texcoord = patch[pointId].texcoord;

output.normal = patch[pointId].normal;
output.tangent = patch[pointId].tangent;

return output;

}

[domain("tri")]

PixelInputType DShader(ConstantOutputType input, float3 uvwCoord : SV_DomainLocation, const OutputPatch patch) { float3 vertexPosition; float2 uvPosition; float4 worldposition; PixelInputType output;

// Interpolate world space position with barycentric coordinates float3 vWorldPos = uvwCoord.x * patch[0].position + uvwCoord.y * patch[1].position + uvwCoord.z * patch[2].position;

// Determine the position of the new vertex.

vertexPosition = vWorldPos;

// Calculate the position of the new vertex against the world, view, and projection matrices.

output.position = mul(float4(vertexPosition, 1.0f),WVP);

// Send the input color into the pixel shader.

 output.texcoord = uvwCoord.x * patch[0].position + 
                uvwCoord.y * patch[1].position + 
                 uvwCoord.z * patch[2].position;

output.normal = uvwCoord.x * patch[0].position + 
                uvwCoord.y * patch[1].position + 
                uvwCoord.z * patch[2].position;

output.tangent = uvwCoord.x * patch[0].position +
                uvwCoord.y * patch[1].position +
                uvwCoord.z * patch[2].position;

//output.depthBuffer = output.position;
//output.depthBuffer.w = 1.0f;

//worldposition = mul(output.position,WVP);
//output.viewDirection = cameraDirection.xyz - worldposition.xyz;
//output.viewDirection = normalize(output.viewDirection);

return output;

}

[/code]

Somethings are commented out but will be in place when fixed. I'm probably not connecting something correctly.

© Game Development or respective owner

Related posts about directx11