PDA

View Full Version : glow effect with textures



David Doria
11-24-2008, 08:08 AM
I can get a decent "glow" effect by drawing slightly larger, slightly more translucent copies of an object at the same position as the actual object.

glScalef(1,1,1);
glColor4f(1.0f, 0.0f, 0.0f, 1);
DrawSphere();
glScalef(1.1, 1.1, 1.1);
glColor4f(1.0f, 0.0f, 0.0f, .5);
DrawSphere();
glScalef(1.2, 1.2, 1.2);
glColor4f(1.0f, 0.0f, 0.0f, .2);
DrawSphere();

where DrawSphere() is
GLUquadricObj *quadratic;
quadratic = gluNewQuadric();
gluQuadricNormals(quadratic, GLU_SMOOTH);
gluSphere(quadratic, 1.0f, 32, 32);

However, if I want to do this with a textured object

glBindTexture(GL_TEXTURE_2D, ColorId_);
glEnable(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

gluQuadricTexture(quadratic, GL_TRUE);

Then where can I set the alpha parameter??

Thanks,

Dave

_NK47
11-24-2008, 09:34 AM
do you enable alpha blending?

David Doria
11-24-2008, 09:43 AM
I do enable alpha blending with

glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

but the question is how do I specify the alpha of a textured object?

zeoverlord
11-24-2008, 12:11 PM
it's the same just use glColor4f(1.0f, 1.0f, 1.0f, 0.2f);
Though you may have to enable GL_COLOR_MATERIAL first

David Doria
11-24-2008, 12:19 PM
ok so then the next thing drawn will just use that alpha value but not the color (since the colors are determined by the texture instead)?

ZbuffeR
11-24-2008, 12:34 PM
by default (GL_MODULATE) it is color * texture.
So a white color is like 1 * texture == texture.

David Doria
11-24-2008, 12:38 PM
Ok, well that seems to work as far as enabling the transparency, however it looks just like a blur instead of a glow. Is there a way to make it "brighter" as well as transparent?

ZbuffeR
11-24-2008, 01:07 PM
glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

David Doria
11-25-2008, 09:45 AM
Since the texture is drawn in a different position (ie. a larger object) you can see the shifted textures.

http://rpi.edu/~doriad/sun.png
http://rpi.edu/~doriad/sunglow.png

See how the sun spot appears multiple times?

Is there a way to get the glow without seeing multiple textures?

Thanks,

Dave

ZbuffeR
11-25-2008, 10:20 AM
The idea is to blur the added image.
Typically :
1) render the scene,
2) then copy it to texture,
3a) then blur the texture,
3b) then draw a fullscreen quad with this texture.

Depending on your opengl knowledge, there are multiple ways to do this. For example steps 3 a and a can be done at the same time through a proper shader.

dletozeun
11-25-2008, 12:03 PM
I addition to what Zbuffer said, you can blur your picture more, copying the scene rendering in a texture twice smaller, blurring it with a gaussian filter for example and then blending it with the original scene rendering. This way you benefit from the hardware bilinear filtering that cheaply blur your texture before blending.

zeoverlord
11-26-2008, 06:10 PM
The idea is to blur the added image.
Typically :
1) render the scene,
2) then copy it to texture,
3a) then blur the texture,
3b) then draw a fullscreen quad with this texture.

Depending on your opengl knowledge, there are multiple ways to do this. For example steps 3 a and a can be done at the same time through a proper shader.



In addition you could also put steps 1 and 2 in the same step by using FBOs.