# Make a cube in geometry shader

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

## Recommended Posts

I've got a triangle, made with a VertexBuffer. I'm using TRIANGLESTRIP. Here are Vertex Points
	vertices[0].position = D3DXVECTOR3(0.5f,-0.5f,0);
vertices[0].text = D3DXVECTOR2(1,1);
vertices[1].position = D3DXVECTOR3(-0.5f,-0.5f,0);
vertices[1].text = D3DXVECTOR2(0,1);
vertices[2].position = D3DXVECTOR3(0.5,0.5f,0);
vertices[2].text = D3DXVECTOR2(1,0);

Here is my geometry shader:
[maxvertexcount(32)]
void gs_main(triangle GS_INPUT In[3], inout TriangleStream<PS_INPUT> OutStream)
{
PS_INPUT NewVertex;

NewVertex.Pos = mul(mul(mul(float4(-0.5,0.5,0,1),WorldMatrix),ViewMatrix),ProjMatrix);
NewVertex.Tex = float2(0,0);

for (int i = 0; i < 3; i++)
{
OutStream.Append((PS_INPUT)In);
}

OutStream.Append(NewVertex[0]);
OutStream.RestartStrip();
}

Using this code my triangles become correctly a quad. Now my intentions were to make a cube from a triangle. So i've triend this other code
[maxvertexcount(32)]
void gs_main(triangle GS_INPUT In[3], inout TriangleStream<PS_INPUT> OutStream)
{
PS_INPUT NewVertex[5];

NewVertex[0].Pos = mul(mul(mul(float4(-0.5,0.5,0,1),WorldMatrix),ViewMatrix),ProjMatrix);
NewVertex[0].Tex = float2(0,0);

NewVertex[1].Pos = mul(mul(mul(float4(0.5,0.5,0.5,1),WorldMatrix),ViewMatrix),ProjMatrix);
NewVertex[1].Tex = float2(1,0);

NewVertex[2].Pos = mul(mul(mul(float4(0.5,-0.5,0.5,1),WorldMatrix),ViewMatrix),ProjMatrix);
NewVertex[2].Tex = float2(1,1);

for (int i = 0; i < 3; i++)
{
OutStream.Append((PS_INPUT)In);
}

OutStream.Append(NewVertex[0]);
OutStream.RestartStrip();

OutStream.Append((PS_INPUT)In[2]);
OutStream.Append(NewVertex[0]);
OutStream.Append(NewVertex[1]);
OutStream.Append(NewVertex[2]);

OutStream.RestartStrip();
}

But when i run it, i've got the original quad. If i rotate it on Y axes, when it makes a 180 degrees rotation, i can see a triangle... It looks like a quad that on the retro has got a triangle... If i try, on the contrary, In[0] and In[1] i can see a strange figure. My original intention was to see the second cube's quad, the one on the right. Where is my error??

##### Share on other sites
I've resolved by making each vertex from new.

• ### 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.)

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634092
• Total Posts
3015448
×