View Full Version : Specular effects

02-12-2001, 08:51 AM
How can you achieve good specular effects in OpenGL? I've seen some people use spheremapping and multitexturing but that seems a bit slow.

02-12-2001, 11:17 AM
Either increase the resolution of your objects and let OpenGL's own lighting engine do the work, or use spheremapping/multitexturing, as you mentioned. Multitexturing is not that expensive, nor is spheremapping. Not even on a few years old hardware.

Both ways will have some performance hits, but what else can you expect when you want a good result? Always when you want to improve something, you have to offer something else. Most of the time you have to offer speed. Nothing is for free, not even a specular effect.

02-12-2001, 11:37 AM
Okay, I was afraid of that... so exactly what is needed to set things up properly? you need to set up a good value for glShininess right? And then ofcourse your specular lighting components (RGB)... am I leaving anything out?

02-12-2001, 07:33 PM
Dont forget to subdivide objects on great amounts of polies. That helps. Or use NURBS.

Kilam Malik
02-12-2001, 07:58 PM
As there is less performance hit using a texture than doubling the poly's, I would recommend using sphere map/multitexturing to achieve the shininess. You will have to use a lot of poly's to get the same effect without textures.

02-12-2001, 10:20 PM
Multitexturing isn't too slow: if you apply 2 textures, it's just like you draw the object twice.
If you mean sphere environment mapping, I did it yesterday!
You only have to draw the object as usual, then set the depth buffer masked (readonly) and the func less or equal.
Then enable sphere coordinates generation, enable blending (glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)) and set up an alpha factor for the current color or material from 0.0 (no reflection) to 1.0 (total environment refl) and redraw the object with the environment texture.
I think this isn't the only way to do it, but it works very well and it lets you to set how reflective is your object simply changing alpha value.
Hope this helps you!

02-12-2001, 11:35 PM
According to my own findings, sphere mapping generally halves performance. (Well it did on a 83,000 poly gremlin I experiemnted with)

That was on a Geforce 256.

Isn't there an extenion on geforces called Seperate Specular Color or something too?

I downloaded something somewhere that used this, and had an excellent specular effect.
I think it was that Delphi Environment mapping demo posted up on the news board a week or two back.

- Nutty

02-13-2001, 01:53 AM
Originally posted by Nutty:
Isn't there an extenion on geforces called Seperate Specular Color or something too?

Yes, there is GL_EXT_separate_specular_color but its sole purpose it to have specular highlighting while texturing (using core OpenGL, you have to do it in two passes).

So you still have the problem of tesselating the objet quite a lot for having a proper effect !

I must say, it seems to me that using texturing is a much better solution than using more detailed objects... The problem with this technique is to have the proper textures.........

Well, up to you !



[This message has been edited by Eric (edited 02-13-2001).]

02-13-2001, 04:01 AM
So how does that work then?
Just get a texture which is black, with a white highlight in the centre, and just blend that onto the geometry in a second pass with sphere mapping?

02-13-2001, 11:17 PM
ahem... my last post was a question you know. Or has no-one actually done this?

- Nutty http://www.opengl.org/discussion_boards/ubb/smile.gif

02-13-2001, 11:25 PM

If you just want to use a lightmap, why would you use sphere mapping ?

I mean, say you have your original texture and your lightmap (the black&white thing but could be with colors as well !). You just have to first render the original one and then the second one with GL_MODULATE. No need for sphere mapping here...

Or perhaps I did not get your question right ?



02-13-2001, 11:35 PM
Hmmm... why was someone mentioning sphere mapping used in conjunction with multi-texturing above, when the discussion is about specular effects?

Would what I described not give a specular effect?

I'll have to have a fiddle about sometime. Might stick a demo up on me site if I get it working nicely. Wonder if I could work that into a vertex program.. http://www.opengl.org/discussion_boards/ubb/smile.gif

02-14-2001, 12:11 AM
Oops my fault...

I guess what I describe would do like diffuse lighting.... Usually, with specular effects, you want the "shiny bit" to move when you change your view angle ! That's probably why Punchey mentioned sphere mapping...

I should wake up now... http://www.opengl.org/discussion_boards/ubb/smile.gif



02-14-2001, 12:59 AM
I've got a kind of specular effect going now.
Doing 2 passes.

First pass I use GL_DECAL with the main texture, then on the second pass I use GL_MODULATE with a black texture with a white highlight in the middle of it, with sphere mapping.

But it doesn't work very well. I have to disable depth testing for the 2nd pass to render, and then I dont see any of the original textured object at all. It's very strange. Maybe I'm doing something completly wrong.

Do I have to enable blending when using MODULATE?

02-14-2001, 01:22 AM
Enable the depth test, set glDepthFunc to GL_EQUAL (or GL_LEQUAL should work too, if your test was GL_LESS before).
To add some specular highlight with multiple passes you'll have to do some blending on the frame buffer. WIth a black and white texture for the highlight glBlendFunc GL_DST_COLOR, GL_ZERO); should work.

02-14-2001, 01:23 AM
If you are doing two passes with only one texture per pass, why not use multitexturing?

The first textureunit is the base texture set to GL_REPLACE or something, or GL_MODULATE if you want to use the triangle's basecolor aswell. This will be the diffuse color of the object.

The second textureunit should be the specular map, with the textureunit set to additive blending, i.e. add the two textures together. If you use GL_MODULATE, it will multiply the exisiting color with the incomming color. When the texture is black, the resulting color will be black. If the texture is white, the color will be unchanged. There is no way you can get the highlight effect with GL_MODULATE.

02-14-2001, 03:41 AM
I changed the depth function, and all is well!

GL_DST_COLOR, GL_ZERO dont give the right results, the entire object is darkened, and only normal color at the highlight.

I'm using GL_SRC_ALPHA, GL_ONE, to give a nice additive white out specular.

Might put it on me website tonight.

- Nutty

02-14-2001, 03:46 AM
>>GL_DST_COLOR, GL_ZERO dont give the right results<<

Well, was just a first approximation without coding. http://www.opengl.org/discussion_boards/ubb/smile.gif
Fine that you got it right.

02-14-2001, 04:35 AM
Nutty, what's the URL for your site?

Also, if modulate makes only the highlight the normal color, I suppose then that you could use that characteristic to do some cool kind of spot lighting or something using textures. Like maybe a star-shaped (or whatever) spot light.

02-14-2001, 04:57 AM
Originally posted by Punchey:
Nutty, what's the URL for your site?

www.nutty.org (http://www.nutty.org)



02-14-2001, 07:34 AM
Cheers Eric.

I'm currently experimenting using a vertex program on the 2nd pass, to do the specular. Means I can very easily specify the light direction, to have correctly facing speculars.

Yeah, I suppose the other blending mode, would make a good spotlight kind of effect!

I have this vertex program specular thing working fine now, but my faces keep interfering for some reason.

- Nutty

02-14-2001, 07:59 AM
It seems I've found a bug in using both normal T&L pipeline, and vertex programs in dual pass rendering. Though thats not surprising, cosidering they're leaked drivers, but I thought I'd comment about it anyway.

Doing a normal 2 stage pass (both passes on normal T&L) works fine. i.e. no interference of poly's provided you use 2 different depth functions. i.e. GL_LEQUAL, and GL_EQUAL.

However, enabling a vertex program for the 2nd pass, results in much polygon interference, unless vertex programs are used for both passes.

Very odd indeed.

I'll try and get a multi-texturing vertex program version up and running soon.

- Nutty http://www.opengl.org/discussion_boards/ubb/smile.gif

02-14-2001, 11:26 PM
just do normal multitexturing use texenv mode GL_ADD on the spec texture. no blending required

02-15-2001, 12:02 AM
Actually I just realised, it's not a bug as such, just the result of mixing hardware and software rendering passes. The maths is not identical, thus giving this problem.

Which means it wont occur when it's done in hardware proper.

I feel a bit dumb now.. http://www.opengl.org/discussion_boards/ubb/smile.gif

02-16-2001, 07:42 AM
I've just uploaded a specular demo to my website.
www.nutty.org (http://www.nutty.org)

Uses multi-texturing with sphere mapping to create the effect. No vertex program stuff, so it should run on all dual texture unit graphics cards.

As always full commented source is included. http://www.opengl.org/discussion_boards/ubb/smile.gif

Might do a few other specular methods..


- Nutty http://www.opengl.org/discussion_boards/ubb/smile.gif

02-16-2001, 11:24 AM
Nice work Nutty. Works fine on Rage 128. http://www.opengl.org/discussion_boards/ubb/smile.gif

BTW, is that a babylon5 ship? I miss that show. http://www.opengl.org/discussion_boards/ubb/frown.gif

02-19-2001, 12:07 AM

I dont know, ask Nvidia. Thats the model they stuck in with their DX effects browser thingy.

- Nutty.

Kilam Malik
02-19-2001, 04:42 AM
Yes, Elixer. It's a White Star.

02-20-2001, 08:09 AM
I've done another specular demo.. and it looks awesome!

Uses vertex programs too.

Heres the gist.

I have a point light source moving around the space ship. I dot the normal, and light vector to apply lighting to the material color, I then multiply on a cube map, calculated in the vertex program also, then with the 2nd texture unit, I add on a specular highlight.

The vertex program is huge!! 38 instructions, might be able to squeeze it down a bit, haven't tried yet.

Will upload it to my website tonight! (edit: Upload complete!!)
It'll be in the vertex program section.

Requires dual texture units, 7.17 drivers, and cube mapping. Can't wait for this to get released officially.


- Nutty http://www.opengl.org/discussion_boards/ubb/smile.gif

[This message has been edited by Nutty (edited 02-20-2001).]

02-20-2001, 06:20 PM
How exactly does one go about writing these vertex programs? What sort of thing is this? I'd sure like to know how to get started on stuff like this. BTW, great work, Nutty!

02-20-2001, 11:19 PM
Download the basic vert prog from my site. Click the link to nvidia's vertex program documents, download them, and read them.

Then you should understand what the vertex program does, and be able to write your own.

I honestly can't wait for this feature to appear properly in hardware, the things you can do by writing your own pipeline are incredible!!

- Nutty http://www.opengl.org/discussion_boards/ubb/smile.gif

02-22-2001, 04:57 AM
Great! I can't wait to check it out.