Glowing Objects?

Started by elias4444, March 08, 2005, 17:25:28

Previous topic - Next topic

elias4444

So, how do you make an object glow? I know how to set a light source on the object, which makes it emmit light like any other light source, but how do you give something a "glow effect?"

I tried GL_EMISSION light, but couldn't see any difference, and when I was only doing 2D, I could make a simple image to make it look like something had a glow, but now in true 3D mode, that doesn't work (does it?).

Any ideas? An example of what I'm looking for is like the fire on a torch - it has a glow right around it.
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

Orangy Tang

From simplest to hardest:
- Emissive colour only adds to the brightness of a particular material (basically ramping up the ambient colour on just one object). It's next to useless for most things.

- You can still use an image to overlay as a glow even in 3d. You just need to load your image as before and billboard it so that it always faces the camera. Flipcode has a good article on the maths needed for billboarding. Remember you need to distinguish between glows that happen 'in the world' (and so need to be hidden behind other geometry) and those that appear 'in the eye' (in which case you need to draw them on top of everything else, easily done by drawing last without depth testing).

- If you want something that looks really fancy, try the glow/bloom filter on the whole screen (like Tron does it). Gamasutra has a good article on this, and you can see the results in Quix: http://www.orangytang.net/Quix/play.php

elias4444

I tried the billboarding, but couldn't get it to look right. I'd really like to do the glow/bloom filter, but the samples say to use Nvidia's functions, which I don't think are available in lwjgl.

How did you implement it in your game? Did you glReadPixel the whole screen? If so, how do you apply the blur effect to the captured texture?
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

Orangy Tang

Which nVidia functions? If you mean nVidia-only OpenGL extensions then they're avalible, but obviously won't work on ATi or other cards.

I do a really simple version that blurs the image on the graphics card (no glReadPixels needed):
- Render glow to framebuffer
- Copy to texture
- Clear framebuffer
- Repeatedly re-render texture to framebuffer to create blur*
- Copy blured to texture.

Then the resulting blured texture can be rendered after your full-detail scene is done normally.

*This is the tricky bit. If you use fancy extensions you can make it more efficient, but I just use up to two texture units and regular ARB multitexturing. I'm thinking of doing a GLSL version that uses the full amount of texture units, but I think that'll be somewhat underused by the majority of people.

You can also blur by using automatic mipmap generation and rendering all the mipmaps at once, but the quality is pretty bad.

elias4444

Hmmm.... so, you're blurring the texture before mapping it to the object? If that's the case, I'm not sure that'll work in a full 3D game (as the edges of objects won'tappear translucent like they do in a 2D game).

Here's a picture of one of my games (no laughing please :roll:):
http://www.tommytwisters.com/twisters/gamepic.jpg

I'm trying to make the little "bugs" glow. The problem is, they're real 3D, not just 2D sprites. Any ideas? Am I stuck with billboarding?
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

Orangy Tang

Quote from: "elias4444"Hmmm.... so, you're blurring the texture before mapping it to the object?
Not mapping to an object, to the *entire* screen as an overlay. You're basically doing a blur filter over the whole screen, except instead of just using the normal image as input, you render special "glow geometry" (in your case, the bugs) then blur and superimpose that.

The screen-space blur means that your glow geometry bleeds outwards around existing geometry (yet gets obscured by near geometry). Its all covered in the Tron article on Gamasutra....

elias4444

What function(s) are you using to grab the current screen and then to generate the "glow overlay?"

I read the gamasutra article, and while I appreciate the theory, I have no idea how to actually implement it in lwjgl.
=-=-=-=-=-======-=-=-=-=-=-
http://www.tommytwisters.com

Orangy Tang

If I remember right, glCopyTexSubImage should copy a portion of the framebuffer into the currently bound texture.

Theres some fancy stuff you could do with pBuffers to do render-to-texture (and avoid the copy) but frankly thats just too much hassle.