PDA

View Full Version : Geometry Shader: Pixel-size quads (how to)



FrankBoltzmann
12-16-2013, 05:38 AM
I have an SSBO that essentially stores all the world-space positions of each fragment created by the pipeline's rasterization of a scene from a specific fixed viewpoint. In each frame, I draw a number of points equal to the number of stored fragments with gl_PointSize = 1.0, however, I recently added a geometry shader that receives these points and outputs quads, trying to get the same effect as points, but failing. This is what I'm doing in the GS:


#version 430 core

layout(points) in;
layout(triangle_strip, max_vertices = 4) out;

uniform ivec2 screenSize;

void main()
{
if(empty_pixel[0] < 0.5)
{

vec2 inc = vec2(2.0,2.0)/vec2(2*screenSize);

gl_Position = gl_in[0].gl_Position + vec4(inc,0,0);
EmitVertex();

gl_Position = gl_in[0].gl_Position + vec4(-inc.x,inc.y,0,0);
EmitVertex();

gl_Position = gl_in[0].gl_Position + vec4(inc.x,-inc.y,0,0);
EmitVertex();

gl_Position = gl_in[0].gl_Position + vec4(-inc,0,0);
EmitVertex();

EndPrimitive();
}
}

Notice how I am using screenSize (1280x720) to find out the size of a pixel in screen-space coordinates. If my gl_Position is between -1 and 1, both width and height are 2 units, which means each pixel will be 2/width by 2/height in screen-space. So I'm trying to create a quad around each point's gl_Position, but the result looks nothing like a point of 1.0 size. Am I missing something? What could be wrong?