Why DX 11 Geometry Shader isn't rendering anything out?

This topic is 1735 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I'm trying to understand the geometry shader more. I'm trying to get a point to be drawn into a quad however, nothing is being rendered out. The skybox, the grid, the font system is all being rendered out correctly. I made sure I reset the geometry shader to null pointer. There is no resulting errors in the DX Debug status nor in the program. I made sure i catch anything if a constant buffer, or the vertex buffer or anything failed on me. I don't have it instanced yet but once I get a basic quad rendered using the geometry shader then I will focus getting the instanced part working on.

What I've made was one vertex point in 3D Space. I set up the vertex buffer with default usage, the constant buffer with default usage and so on and so on.

I'm totally stumped at this probably because I'm trying to understand the geometry shader more. The rendering code is like this:

	UINT stride, offset;
stride = sizeof(VertexType);
offset = 0;

device->devcon->IASetVertexBuffers(0, 1, &particleVertexBuffer, &stride, &offset);
device->devcon->IASetInputLayout(particle_InputLayout);

cbPerFrame.WVP = world * view  * projection;
cbPerFrame.View = view;
cbPerFrame.Projection = projection;

device->devcon->UpdateSubresource(particleConstantBuffer, 0, 0, &cbPerFrame, 0, 0);
device->devcon->VSSetConstantBuffers(0, 1, &particleConstantBuffer);
device->devcon->GSSetConstantBuffers(0, 1, &particleConstantBuffer);
device->devcon->PSSetConstantBuffers(0, 1, &particleConstantBuffer);

device->devcon->PSSetSamplers(0, 1, &device->defaultTextureSamplerState);

device->devcon->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
device->devcon->Draw(1, 0);

device->devcon->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);


Would there be any other reason why the geometry shader wouldn't be outputting a simple quad?

Share on other sites

I can haz shader-source? Seriously though, there most likely is something wrong with your shader itself, it would be helpful if you showed it.

Share on other sites

I was starting to think that too but was unsure.

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

};

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

};
cbuffer MatrixBuffer
{
float4x4 WorldViewProjMatrix;
float4x4 worldMatrix;
float4x4 viewMatrix;
float4x4 projMatrix;
};

SamplerState SampleType;

{
PixelInputType output;
// Change the position vector to be 4 units for proper matrix calculations.
// Calculate the position of the vertex against the world, view, and projection matrices.
output.position = mul(input.position, WorldViewProjMatrix);
output.worldPos = mul(input.position, worldMatrix);
output.tex = input.tex;
output.normal = input.normal;

return output;
}

float4 PShader(PixelInputType input) : SV_TARGET
{
float4 textureColor;
float4 finalColor;

// Sample the pixel color from the texture using the sampler at this texture coordinate location.
textureColor = shaderTexture.Sample(SampleType, input.tex);
finalColor = float4(1.0f,0.0f,0.0f,1.0f);

return finalColor;
}
[maxvertexcount(4)]
void GShader(point PixelInputType input[1], inout TriangleStream<PixelInputType> OutputStream)
{

// Create the billboards quad
float3 vert[4];

// We get the points by using the billboards right vector and the billboards height
vert[0] = input[0].worldPos.xyz - float3(-1.0f,-1.0f,0.0f); // Get bottom left vertex
vert[1] = input[0].worldPos.xyz + float3(1.0f,-1.0f,0.0f); // Get bottom right vertex
vert[2] = input[0].worldPos.xyz - float3(-1.0f,1.0f,0.0f);  // Get top left vertex
vert[3] = input[0].worldPos.xyz + float3(1.0f,1.0f,0.0f); // Get top right vertex

// Get billboards texture coordinates
float2 texCoord[4];
texCoord[0] = float2(0, 1);
texCoord[1] = float2(1, 1);
texCoord[2] = float2(0, 0);
texCoord[3] = float2(1, 0);

// Now we "append" or add the vertices to the outgoing stream list
PixelInputType outputVert;

for(int i = 0; i < 4; i++)
{
outputVert.position = mul(float4(vert[i],1.0f), WorldViewProjMatrix);
outputVert.worldPos = float4(vert[i],0.0f);
outputVert.tex = texCoord[i];

// These will not be used for billboards
outputVert.normal = float3(0,0,0);
OutputStream.Append(outputVert);

}

}


Share on other sites

Okay, now I can scream and bang my head against the wall. Thank you again Julien, you were right on the money! It was the issue with input.worldpos + float3() section. I gave you thumbs up and I wish I can give again but thanks!

Share on other sites

Some things I noticed right away:

- You don't have to output a correctly transformed SV_POSITION from the vertex shader in case of using a GS. In fact, since you have a point, you don't even need to transform the input-position with a world-matrix, an float3-offset-vector does just as well. Might not be connected to the issue iself, but saves you a ton of ALU.

- Those lines:

	vert[0] = input[0].worldPos.xyz - float3(-1.0f,-1.0f,0.0f); // Get bottom left vertex
vert[1] = input[0].worldPos.xyz + float3(1.0f,-1.0f,0.0f); // Get bottom right vertex
vert[2] = input[0].worldPos.xyz - float3(-1.0f,1.0f,0.0f);  // Get top left vertex
vert[3] = input[0].worldPos.xyz + float3(1.0f,1.0f,0.0f); // Get top right vertex


look wrong to me. I mean, aside from that they are pretty hard to read (e.g due to the first line of substracting a vector of negative values ;)), but if you resolve those it looks they are wrong:

	vert[0] = input[0].worldPos.xyz + float3(1.0f,1.0f,0.0f); // Get bottom left vertex
vert[1] = input[0].worldPos.xyz + float3(1.0f,-1.0f,0.0f); // Get bottom right vertex
vert[2] = input[0].worldPos.xyz + float3(1.0f,-1.0f,0.0f);  // Get top left vertex
vert[3] = input[0].worldPos.xyz + float3(1.0f,1.0f,0.0f); // Get top right vertex


See? You have two duplicate points, I suspect you screwed those lines up copying from somewhere or such, fix those and you should get some output. I quess the solution is to put all "+" before the float3 and leave those values intact, I just wanted to show you whats going on here. Note though that, in case this works, the quad is still aligned to the world and not the screen, so that might be a reason you won't see the quad from certain camera angles too.

EDIT:

Glad to see you figured it out yourself in the meanwhile ;)

Edited by Juliean

Share on other sites

What the issue was the calculation inside the worldPos. I was looking at BrayzerSoft tutorial bill boarding tutorial. The worldpos calculation was tripping because of instance:

input[0].worldpos - float3(-1.0f,0.0f,0.0f); // would result in 1.0f,0.0f,0.0f.

So, the way it was poorly calculated or in my case I followed the example from the tutorial from the site.

Just like if I was going to render a vertex quad normally, it would have to have proper coordinants to be able to render a good looking quad.

Share on other sites

Some things I noticed right away:

- You don't have to output a correctly transformed SV_POSITION from the vertex shader in case of using a GS. In fact, since you have a point, you don't even need to transform the input-position with a world-matrix, an float3-offset-vector does just as well. Might not be connected to the issue iself, but saves you a ton of ALU.

- Those lines:

	vert[0] = input[0].worldPos.xyz - float3(-1.0f,-1.0f,0.0f); // Get bottom left vertex
vert[1] = input[0].worldPos.xyz + float3(1.0f,-1.0f,0.0f); // Get bottom right vertex
vert[2] = input[0].worldPos.xyz - float3(-1.0f,1.0f,0.0f);  // Get top left vertex
vert[3] = input[0].worldPos.xyz + float3(1.0f,1.0f,0.0f); // Get top right vertex


look wrong to me. I mean, aside from that they are pretty hard to read (e.g due to the first line of substracting a vector of negative values ;)), but if you resolve those it looks they are wrong:

	vert[0] = input[0].worldPos.xyz + float3(1.0f,1.0f,0.0f); // Get bottom left vertex
vert[1] = input[0].worldPos.xyz + float3(1.0f,-1.0f,0.0f); // Get bottom right vertex
vert[2] = input[0].worldPos.xyz + float3(1.0f,-1.0f,0.0f);  // Get top left vertex
vert[3] = input[0].worldPos.xyz + float3(1.0f,1.0f,0.0f); // Get top right vertex


See? You have two duplicate points, I suspect you screwed those lines up copying from somewhere or such, fix those and you should get some output. I quess the solution is to put all "+" before the float3 and leave those values intact, I just wanted to show you whats going on here. Note though that, in case this works, the quad is still aligned to the world and not the screen, so that might be a reason you won't see the quad from certain camera angles too.

EDIT:

Glad to see you figured it out yourself in the meanwhile ;)

You're a mind reader or possibly a psychic! :D Thanks bud for helping poor chap out! I never saw your post until I reloaded page. I also fixed the math out too as well. Like how you posted before I read your post. Maybe I'm psychic.... :suprise:

Thanks again for helping. Geometry shader is a breeze now that I figured out what in the world I was doing or copying wrong lol!

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 29
• 16
• 10
• 10
• 11
• Forum Statistics

• Total Topics
634112
• Total Posts
3015581
×