• Advertisement
Sign in to follow this  

Make a cube in geometry shader

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

If you intended to correct an error in the post then please contact us.

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);
		
	
	//Quadrato frontale
	 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);
	
	
	
	//Quadrato frontale
	 for (int i = 0; i < 3; i++)
	{
		OutStream.Append((PS_INPUT)In);
	}
	
	OutStream.Append(NewVertex[0]);
	OutStream.RestartStrip();
	
	//Secondo quadrato
	
		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 this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement