How can I render the whole faces instead of only the vertices? [closed]

I'm doing my master thesis in comparing DX9 LoD with DX11 Tesselation LoD. Therefore I use a ShaderManager that calls either the shader for the DX9 implementation, where the model is exchanged by the appropriate model depending on the camera distance or the Tessellation Shader, which calculates the subdivision of the triangles depending to the camera distance.

Since I implemented the tessellation shader in my project, the regular shader draws only vertices and not the wireframe or the faces. It renders the correct color of the vertices but no faces.

This is what I had before:

How shader looked before tessellation modifications

• I tried to change the fillmode
• I reduced the shader code to a minimum
• I built the shadercode on the 4 stages instead just of the 2 stages
• I went back in revisions, to find some differences

but unluckily nothing helped.

// Globals
cbuffer MatrixBuffer
{
matrix worldMatrix;
matrix viewMatrix;
matrix projectionMatrix;
};

// Typedefs
struct VertexInputType
{
float4 position : POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;
};

struct PixelInputType
{
float4 position : SV_POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;
};

{
PixelInputType output;

// Change the position vector to be 4 units for proper matrix calculations.
input.position.w = 1.0f;

// Calculate the position of the vertex against the world, view, and projection matrices.
output.position = mul(input.position, worldMatrix);
output.position = mul(output.position, viewMatrix);
output.position = mul(output.position, projectionMatrix);

// Store the texture coordinates for the pixel shader.
output.tex = input.tex;

// The normal vector for the vertex is calculated in world space and then normalized before being sent as input into the pixel shader.
// Calculate the normal vector against the world matrix only.
output.normal = mul(input.normal, (float3x3)worldMatrix);

// Normalize the normal vector.
output.normal = normalize(output.normal);

return output;
}


// Globals
SamplerState SampleType; // how pixels are written to the polygon face when shaded.

// LightBuffer holds the diffuse color and the direction of the light.
cbuffer LightBuffer
{
float4 ambientColor;
float4 diffuseColor;
float3 lightDirection;
};

// Typdefs
struct PixelInputType
{
float4 position : SV_POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;
};

{
float4 textureColor1;
float4 textureColor2;
float4 alphaValue;
float4 blendColor;
float3 lightDir;
float lightIntensity;
float4 color;

// Get the pixel color from the first texture.

// Get the pixel color from the second texture.

// Get the alpha value from the alpha map texture.

// Combine the two textures based on the alpha value.
blendColor = (alphaValue * textureColor1) + ((1.0 - alphaValue) * textureColor2);

// Saturate the final color value.
blendColor = saturate(blendColor);

// **** Light **** //
// Set the default output color to the ambient light value for all pixels.
color = ambientColor;

// Lighting equation: light intensity value is calculated as the dot product between the normal vector of triangle and the light direction vector.
// Invert the light direction for calculations.
lightDir = -lightDirection;

// Calculate the amount of light on this pixel.
lightIntensity = saturate(dot(input.normal, lightDir));

// Check if N dot L is greater then 0. If diffuse Color is neg. it will substract away some of the ambient color.
if(lightIntensity > 0.0f)
{
// diffuse value of the light is combined with the texture pixel value to produce the color result.
// Determine the final diffuse color based on the diffuse color and the amount of light intensity.
color += (diffuseColor * lightIntensity);
}

// Saturate the final light color. So it can not be greater than 1.
color = saturate(color);

// Multiply the texture pixel and the final diffuse color to get the final pixel color result.
color = color * blendColor;

//color = float4(1,1,1,1);

return color;
}


// This function is what actually loads the shader files and makes it usable to DirectX and the GPU.
{
HRESULT result;
ID3D10Blob* errorMessage;

D3D11_INPUT_ELEMENT_DESC polygonLayout[3];
unsigned int numElements;
D3D11_BUFFER_DESC matrixBufferDesc;
D3D11_SAMPLER_DESC samplerDesc;

D3D11_BUFFER_DESC lightBufferDesc; // description variable for the light constant buffer.

// Initialize the pointers this function will use to null.
errorMessage = 0;

// Compile the vertex shader code.
result = D3DX11CompileFromFile(vsFilename, NULL, NULL, "LightVertexShader", "vs_5_0",
if(FAILED(result))
{
// If the shader failed to compile it should have writen something to the error message.
if(errorMessage)
{
}
// If there was nothing in the error message then it simply could not find the shader file itself.
else
{
MessageBox(hwnd, vsFilename, L"Missing Shader File", MB_OK);
}

return false;
}

// Compile the pixel shader code.
if(FAILED(result))
{
// If the shader failed to compile it should have writen something to the error message.
if(errorMessage)
{
}
// If there was  nothing in the error message then it simply could not find the file itself.
else
{
MessageBox(hwnd, psFilename, L"Missing Shader File", MB_OK);
}

return false;
}

// Create the vertex shader from the buffer.
if(FAILED(result)){ return false; }

// Create the pixel shader from the buffer.
if(FAILED(result)){ return false; }

// Now setup the layout of the data that goes into the shader.
// This setup needs to match the VertexType stucture in the ModelClass and in the shader.
polygonLayout[0].SemanticName = "POSITION";
polygonLayout[0].SemanticIndex = 0;
polygonLayout[0].Format = DXGI_FORMAT_R32G32B32_FLOAT;
polygonLayout[0].InputSlot = 0;
polygonLayout[0].AlignedByteOffset = 0;
polygonLayout[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
polygonLayout[0].InstanceDataStepRate = 0;
// The first 12 bytes are position and the next 16 bytes will be color
polygonLayout[1].SemanticName = "TEXCOORD";
polygonLayout[1].SemanticIndex = 0;
polygonLayout[1].Format = DXGI_FORMAT_R32G32_FLOAT;
polygonLayout[1].InputSlot = 0;
polygonLayout[1].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
polygonLayout[1].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
polygonLayout[1].InstanceDataStepRate = 0;
// The third element for the normal vector that will be used for lighting.
polygonLayout[2].SemanticName = "NORMAL";
polygonLayout[2].SemanticIndex = 0;
polygonLayout[2].Format = DXGI_FORMAT_R32G32B32_FLOAT;
polygonLayout[2].InputSlot = 0;
polygonLayout[2].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
polygonLayout[2].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
polygonLayout[2].InstanceDataStepRate = 0;

// Get a count of the elements in the layout.
numElements = sizeof(polygonLayout) / sizeof(polygonLayout[0]);

// Create the vertex input layout.
if(FAILED(result)){ return false; }

// Release the vertex shader buffer and pixel shader buffer since they are no longer needed.

// in the vertex shader we currently have just one constant buffer so we only need to setup one here so we can interface with the shader.
// Setup the description of the dynamic matrix constant buffer that is in the vertex shader.
matrixBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
matrixBufferDesc.ByteWidth = sizeof(MatrixBufferType);
matrixBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
matrixBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
matrixBufferDesc.MiscFlags = 0;
matrixBufferDesc.StructureByteStride = 0;

// Create the constant buffer pointer so we can access the vertex shader constant buffer from within this class.
result = device->CreateBuffer(&matrixBufferDesc, NULL, &m_matrixBuffer);
if(FAILED(result)){ return false; }

// Create a texture sampler state description.
samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
samplerDesc.MipLODBias = 0.0f;
samplerDesc.MaxAnisotropy = 1;
samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
samplerDesc.BorderColor[0] = 0;
samplerDesc.BorderColor[1] = 0;
samplerDesc.BorderColor[2] = 0;
samplerDesc.BorderColor[3] = 0;
samplerDesc.MinLOD = 0;
samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;

// Create the texture sampler state.
result = device->CreateSamplerState(&samplerDesc, &m_sampleState);
if(FAILED(result)){ return false; }

// Setup the description of the dynamic matrix constant buffer that is in the vertex shader.
matrixBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
matrixBufferDesc.ByteWidth = sizeof(MatrixBufferType);
matrixBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
matrixBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
matrixBufferDesc.MiscFlags = 0;
matrixBufferDesc.StructureByteStride = 0;

// Create the constant buffer pointer so we can access the vertex shader constant buffer from within this class.
result = device->CreateBuffer(&matrixBufferDesc, NULL, &m_matrixBuffer);
if(FAILED(result)){ return false; }

// Setup the description of the light dynamic constant buffer that is in the pixel shader.
// Note that ByteWidth always needs to be a multiple of 16 if using D3D11_BIND_CONSTANT_BUFFER or CreateBuffer will fail.
lightBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
lightBufferDesc.ByteWidth = sizeof(LightBufferType);
lightBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
lightBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
lightBufferDesc.MiscFlags = 0;
lightBufferDesc.StructureByteStride = 0;

// Create the constant buffer pointer so we can access the vertex shader constant buffer from within this class.
result = device->CreateBuffer(&lightBufferDesc, NULL, &m_lightBuffer);
if(FAILED(result)){ return false; }

return true;
}


• Double check your IASetPrimitiveTopology call? Mar 20, 2013 at 22:06
• @NathanReed awesome! Thx! I had in the mesh class deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_3_CONTROL_POINT_PATCHLIST) for the tessellation and it should have been deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST) for normal rendering! If you could post it as answer I can rate you up :) Mar 21, 2013 at 14:34
If you're rendering points instead of triangles, your IASetPrimitiveTopology call may be at fault.