0
\$\begingroup\$

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:

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<HullInputType,3> 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<HullInputType, 3> 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<HullOutputType, 3> 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;
}

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

\$\endgroup\$
  • \$\begingroup\$ BTW, on SE we use Markdown, not BBCode. You can create code blocks by indenting by four spaces or a tab. I fixed the formatting. \$\endgroup\$ – Nathan Reed Oct 23 '13 at 18:06
  • \$\begingroup\$ Thanks for the correction. I have to get use to SE a bit more. \$\endgroup\$ – SICGames2013 Nov 2 '13 at 5:49
1
\$\begingroup\$

Your HullInputType structure doesn't include a binding for SV_Position. It only includes one for POSITION, which isn't a built-in semantic anymore in D3D11. Vertex shaders must write something to SV_Position to tell the system where the vertex is.

BTW, the D3D11 debug layer would have given you a warning message about this. You can activate it by passing the D3D11_CREATE_DEVICE_DEBUG flag when creating your device. Then error and warning messages will come out in the Visual Studio debug window. There's more stuff you can do with the debug layer described in this blog post.

\$\endgroup\$
  • \$\begingroup\$ Thanks for helping out with the solution. I overcame the obstacle only because I switched the WVP to modelWorldView. The whole engine side being looked at and revised. I'll add in the debugging messages. Thanks Nathan. \$\endgroup\$ – SICGames2013 Nov 2 '13 at 5:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.