Sign in to follow this  
Basiror

Rasterization:Render into fragment centers

Recommended Posts

Basiror    241
Hi, I have a question regarding rasterization of pixels. I have a FBO with lets say 512*512 pixels. now my aim is to render exactly into these pixels, so I set up a orthographic projection and a vertex array with lots of tiny quads sized 1x1. The questions is, in order to render into the lower-left fragment, do I use (0,0)-(1,1) as the coordinates for the quad or something like (0.25,0.25)-(0.75,0.75), just offsetting the coordinates a little to the center? glDrawPixels is not an option here, since I use the quads as input data for complex shader operations to do sorting on the GPU or update particle system data, where each fragment corresponds to a particle Here an excerpt from the redbook about the framebuffer. Chapter 10 The Framebuffer thx in advance

Share this post


Link to post
Share on other sites
WilyCoder    100
"now my aim is to render exactly into these pixels, so I set up a orthographic projection and a vertex array with lots of tiny quads sized 1x1."

Seems to be overkill.

Look at the the orthographic projection definitions to see how to write to individual pixels.

hint, use gluortho2d to create the matrix (or write your own version of gluortho2d)...

"glDrawPixels is not an option here, since I use the quads as input data for complex shader operations to do sorting on the GPU or update particle system data, where each fragment corresponds to a particle"

Why not just do a texel lookup from the computed texture of the FBO? Are you using geometry shaders?

Share this post


Link to post
Share on other sites
Basiror    241
Quote:
Original post by WilyCoder
"now my aim is to render exactly into these pixels, so I set up a orthographic projection and a vertex array with lots of tiny quads sized 1x1."

Seems to be overkill.

Look at the the orthographic projection definitions to see how to write to individual pixels.

hint, use gluortho2d to create the matrix (or write your own version of gluortho2d)...

I have a camera system that takes care of this.
Quote:
gluOrtho2D sets up a two-dimensional orthographic viewing region. This is equivalent to calling glOrtho with near=-1 and far=1.



Quote:
Original post by WilyCoder

"glDrawPixels is not an option here, since I use the quads as input data for complex shader operations to do sorting on the GPU or update particle system data, where each fragment corresponds to a particle"

Why not just do a texel lookup from the computed texture of the FBO? Are you using geometry shaders?


No I am not using geometry shaders, it must be compatible with GF6800 cards.
I don t do a lookup since I have to initialize it at first and I need to perform some initializations with fragment shaders to do all the computations required on the GPU.

We work on a parallel processed particle system on the GPU.

[Edited by - Basiror on July 10, 2007 3:04:23 AM]

Share this post


Link to post
Share on other sites
WilyCoder    100
I probably need more details of the implementation.

"The questions is, in order to render into the lower-left fragment, do I use
(0,0)-(1,1) as the coordinates for the quad"

If you are in orthographic mode, you can render to the bottom left pixel by

glBegin(GL_POINTS);
glVertex2i(0,0);
glEnd();

I know that is a very simple solution, and you probably want something else. That's why more details of your implementation are needed.

Share this post


Link to post
Share on other sites
pieslice    194
Here's a trick for pixel perfect 2d-rasterization.

Let width and height be the proportions in pixels.


glMatrixMode( GL_PROJECTION );
glLoadIdentity();

gluOrtho2D( 0, width, 0, height );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef( 0.375, 0.375, 0.0 );


Then just draw stuff with glVertex or equivalent.

Share this post


Link to post
Share on other sites
Basiror    241
Quote:
Original post by WilyCoder
I probably need more details of the implementation.

"The questions is, in order to render into the lower-left fragment, do I use
(0,0)-(1,1) as the coordinates for the quad"

If you are in orthographic mode, you can render to the bottom left pixel by

glBegin(GL_POINTS);
glVertex2i(0,0);
glEnd();

I know that is a very simple solution, and you probably want something else. That's why more details of your implementation are needed.


Thats exactly the point I wonder about, assuming the scanline rasterizer does a nearest neightbour to find the best fragment center to render to

in your example what would happen to glVertex2i(width,height)



@pieslice:

thats what I thought about as well, does anyone have experience with ATI boards?
I can only test it on gf6 boards at the moment.

thx

Share this post


Link to post
Share on other sites
pieslice    194
Quote:
Original post by Basiror
@pieslice:

thats what I thought about as well, does anyone have experience with ATI boards?
I can only test it on gf6 boards at the moment.

thx


The trick I introduced in this thread is considered as general OpenGL trick. It works regardless of hardware used.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this