Jump to content

  • Log In with Google      Sign In   
  • Create Account

Calling all IT Pros from Canada and Australia.. we need your help! Support our site by taking a quick sponsored surveyand win a chance at a $50 Amazon gift card. Click here to get started!

Geometry Shader Only Outputs 3 Vertices

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 NeverKnowsBest   Members   -  Reputation: 128


Posted 19 July 2012 - 01:36 AM

I'm having troubles rendering a billboard quad, that's generated from a single vertex in the geometry shader. For some reason I can only emit 3 vertices. Here's my shader:

[source lang="cpp"]struct QuadVertexInput { float4 position_local : POSITION0; float4 color : COLOR0;};struct QuadVertexOutput { float4 position_projection : POSITION0; float4 color : COLOR0;};struct QuadGeometryOut { float4 position_screen : SV_Position; float4 color : COLOR0;}; struct QuadPixelOutput { float4 color : SV_TARGET;};QuadVertexOutput QuadVertexMain(QuadVertexInput input) { QuadVertexOutput output; output.position_projection = mul(input.position_local, world_matrix); output.color = input.color; return output;}[maxvertexcount(4)]void QuadGeometryMain(point QuadVertexOutput input[1], inout TriangleStream<QuadGeometryOut> stream) { QuadGeometryOut output = (QuadGeometryOut)0; float3 y_axis = float3(0.0f, 1.0f, 0.0f); float3 right = cross(y_axis, camera_direction); float3 up = cross(camera_direction, right); float3 center = input[0].position_projection; float4 vertex0 = float4(center + up * 0.5f + right * 0.5f, 1.0f); float4 vertex1 = float4(center - up * 0.5f + right * 0.5f, 1.0f); float4 vertex2 = float4(center - up * 0.5f - right * 0.5f, 1.0f); float4 vertex3 = float4(center + up * 0.5f - right * 0.5f, 1.0f); vertex0 = mul(mul(vertex0, view_matrix), projection_matrix); vertex1 = mul(mul(vertex1, view_matrix), projection_matrix); vertex2 = mul(mul(vertex2, view_matrix), projection_matrix); vertex3 = mul(mul(vertex3, view_matrix), projection_matrix); output.position_screen = vertex0; output.color = float4(1.0f, 0.0f, 0.0f, 1.0f); stream.Append(output); output.position_screen = vertex1; output.color = float4(0.0f, 1.0f, 0.0f, 1.0f); stream.Append(output); output.position_screen = vertex2; output.color = float4(0.0f, 0.0f, 1.0f, 1.0f); stream.Append(output); output.position_screen = vertex3; output.color = float4(1.0f, 1.0f, 0.0f, 1.0f); stream.Append(output);}QuadPixelOutput QuadPixelMain(QuadGeometryOut input) { QuadPixelOutput output; output.color = input.color; return output;}technique10 Quad { pass P0 { SetVertexShader(CompileShader(vs_4_0, QuadVertexMain())); SetGeometryShader(CompileShader(gs_4_0, QuadGeometryMain())); SetPixelShader(CompileShader(ps_4_0, QuadPixelMain())); }}[/source]

Can anyone help me out with what I'm doing wrong?

Here's an image of what it looks like:



#2 streamer   Members   -  Reputation: 415


Posted 20 July 2012 - 12:58 AM

I am not familiar with geometry shaders but here are few thoughts:
- you are using two triangles with unappropriated culling, switch culling off if there is a second triangle shown (easy to debug)
- you are try to render triangles with triangle fan method, and output is expected to be two triangles. Add two more vertices, or render with triangle fan

Anyway 3d APIs usually work with triangles not quads. However, OpenGL have GL_QUADS rendering method, but that is not geometry shader.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.