PDA

View Full Version : VBO/Point sprites/alpha



M//Hax
12-02-2010, 02:17 PM
Hi,

Huge thanks for your help in my other threads guys. I have another question, this time i'm trying to put some alpha values on the color of the point sprites the code is generating with a VBO. Here the code for the VBO:



glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vboId);

glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);

glNormalPointer(GL_FLOAT, 0, (void*)sizeof(vertices));
glColorPointer(3, GL_FLOAT, 0, (void*)(sizeof(vertices)+sizeof(normals)));
glVertexPointer(3, GL_FLOAT, 0, 0);
float quadratic[] = {1.0f, 0.0f, 0.01f};
glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATIO N_ARB, quadratic );
float maxSize = 0.0f;
glGetFloatv(GL_POINT_SIZE_MAX_ARB, &maxSize );
if(maxSize > 100.0f)
maxSize = 100.0f;
glPointSize(maxSize);

glPointParameterfARB(GL_POINT_FADE_THRESHOLD_SIZE_ ARB, 60.0f);
glPointParameterfARB(GL_POINT_SIZE_MIN_ARB, 1.0f);
glPointParameterfARB(GL_POINT_SIZE_MAX_ARB, maxSize);

glEnable(GL_POINT_SPRITE_ARB);
glDrawArrays(GL_POINTS, 0, numPoints);
glDisable(GL_POINT_SPRITE_ARB);

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
glDisable(GL_BLEND);

I tried using the GL_BLEND function, and it worked. But the alpha is not working correctly in all direction. I would like to know if it is the right way of doing it or should i load the alpha from a shader?

aqnuep
12-02-2010, 04:10 PM
According to your blending settings the final color will evaluate as follows:

FramebufferColor = PointSpriteAlpha * PointSpriteColor + 1 * FramebufferColor

If this is what you intended to use then its okay.
What I don't know from this source listing is whether you have added a texture to the point sprite that has an alpha channel and with the proper values in it.

What is actually the problem? Can you attach some screenshot of what is rendered and explain what you would like to get?

M//Hax
12-03-2010, 07:55 AM
there is no texture added to the point sprites. For now i'm just using a color array with 3 elements (RGB). I'll try posting some screenshots.

aqnuep
12-03-2010, 08:51 AM
As a single point sprite can have a single color specified, you will simply get trasparent/translucent point sprites, nothing more. Also, point sprites make sense only if you apply a texture to them as otherwise if you just want some colored points then you don't need the point sprite extension at all as they are only for applying a texture on top of a point primitive.

Note: Okay, that's not 100% true as if you use the point sprite texture coorindates in your fragment shader to do some nifty tricks (what I suppose you'll want to do to make them look like illuminated spheres) then they make sense even without textures.

M//Hax
12-09-2010, 01:00 PM
Ok, my project is working great. For now i'm able to draw the point sprites from a .txt file, and to move in the 3D space in spectator mode. The .txt file is containing 128x128x128 coordinates. So that makes 2097152 point sprites beiing rendered. The fps is still really good, between 70 to 120 fps. What i want to do now, is to be able to apply a fragment shader to make them appear as a sphere (right now they are just 2D square). Any ideas?

ZbuffeR
12-09-2010, 02:52 PM
Texture the point sprite with a RGBA texture : A contains alpha, so that it draws a circular shape, and RGB contains XYZ compoents of normals.
In the fragment shader, discard if alpha <0.5 and compute lighting according to RGB normal.

M//Hax
12-10-2010, 12:39 PM
Ok i was able to apply a RGBA texture to all point sprites. They are now small circle with alpha. I'm still trying to find how to apply a .vert and .frag to the point sprites. Going back to google...
Any ideas?