PDA

View Full Version : Bright Lights



halo
12-18-2003, 12:07 PM
The brightest GL lights seem to make my objects is only as bright as the original texture. I want to actually make my lights so damn bright that they turn a textured object white, if they are close enough. How do I make the lights additive, rather than just multiplicative?

Thanks.

halo
12-18-2003, 12:29 PM
I tried this, and got error 1280 (invalid enum):
glLightModelf GL_LIGHT_MODEL_COLOR_CONTROL_EXT,GL_SEPARATE_SPECU LAR_COLOR_EXT

I am not familiar with using OpenGL extensions. Is this something I just call, and if the card supports it, it works, or do I have to initialize the extension or something?

Here are the values for the constants:
GL_LIGHT_MODEL_COLOR_CONTROL_EXT 0x81F8
GL_SINGLE_COLOR_EXT 0x81F9
GL_SEPARATE_SPECULAR_COLOR_EXT 0x81FA

In plain English, this translates to 248, 249, and 250, right? Is this all I have to do, or do I not understand something?

glLightModelf 248,250

Thanks.

[This message has been edited by halo (edited 12-18-2003).]

12-18-2003, 12:42 PM
You may add (before sending to the card) a small value to each rgb channel of the texture. So even if your texture is pure black, it will be able to shine even modulated.

Have you used very strong lights ? I remind that when my lights had inverse square attenuation and a very strong power(say 40.0f for each component), the result was indeed very bright. Color float values are clamped to [0,1] by opengl after the fixed path lighting it seems.

You can check the GL_EXT_separate_specular_color with GL_EXT_secondary_color, it will ADD the specular part instead of modulating it with the texture.

If all this does not help much, you may try multipass rendering, first pass polygon lighting only, second pass additive blend with textures. Or multitexture, but it does not seem to allow additive blend.

Do you have any screenshot around there ? I would really like to see the evolution.

I hope it helps.

12-18-2003, 12:53 PM
Yeah, I'm a bit slow... http://www.opengl.org/discussion_boards/ubb/smile.gif

For extensions, see : http://www.opengl.org/discussion_boards/ubb/Forum2/HTML/014848.html

In your case, there are only new tokens, so they will be defined in the updated .h and you will not need function pointers.

Good luck.

halo
12-18-2003, 01:12 PM
GL_EXT_separate_specular_color is supported on my card.

Could you please explain what you mean here:

You can check the GL_EXT_separate_specular_color with GL_EXT_secondary_color, it will ADD the specular part instead of modulating it with the texture.

I also tried glTexEnvf GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_ADD but then the MINIMUM color was the regular texture color!

Here's what it looks like now. I have lightmaps calculated for the large surfaces, but aren't displaying them right now. The furniture is already vertex-lit, so it is already darkened. I just want the lights to light the furniture up MORE than the full brightness of the textures. I know I could brighten the textures halfway, but then you get grayish-looking drab textures:

http://www.leadwerks.com/gl.jpg

[This message has been edited by halo (edited 12-18-2003).]

12-18-2003, 02:37 PM
GL_EXT_separate_specular_color is supported on my card.
I wanted to say something like "go and see the doc of". http://oss.sgi.com/projects/ogl-sample/registry/EXT/separate_specular_color.txt
and : http://oss.sgi.com/projects/ogl-sample/registry/EXT/secondary_color.txt

As I have time to loose, I will try to explain it a bit (untested) :

glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_D IFFUSE); // just to be sure
glColor3f(1.0,1.0,1.0); // color1
glLightModelf ( GL_LIGHT_MODEL_COLOR_CONTROL_EXT,GL_SEPARATE_SPECU LAR_COLOR_EXT);
glSecondaryColor3fEXT(1.0,1.0,1.0); // color2 : for this function call to work, you will have to ask for it

That will enable the separate specular, and set it to normal white.
So the final pixel color will be (if there is no attenuation) :
diffuseLight*color1*textureColor + specularLight*color2

It will add the specular on top of the texture, but only the specular.


I know I could brighten the textures halfway, but then you get grayish-looking drab textures
I know, maybe just add a very small value(ie 2 or 3 out of 255), to prevent zero modulation. To keep the color saturation, multiply instead just adding. Providing no single color channel go way above 255, it will work. Maybe more a sort of gamma correction. Do your textures values belong to the range 0-255 ?

Have you tried to really boost your light intensity ?? Something like :

GLfloat bright[] = {50.0,50.0,50.0,1.0};
glLightfv ( GL_LIGHT0, GL_DIFFUSE, bright);

What programming language do you use ? Python maybe ?
Well, I hope it will get clearer (well brighter maybe ? http://www.opengl.org/discussion_boards/ubb/wink.gif ).

12-18-2003, 02:45 PM
See also the section called "Poor Tessellation Hurts Lighting", it looks a bit like your problem : http://opengl.org/resources/features/KilgardTechniques/oglpitfall/

dorbie
12-18-2003, 02:47 PM
The separate specular will add specular post texture and this will be added to the result giving diffuse * texture + specular instead of (diffuse+specular) * texture. However there is no simple way to make diffuse go brighter than one without getting fancier than basic OpenGL and post texture specular doesn't seem like it is everything you need. It is a fundamental part of 'basic' OpenGL that colors are clamped between 0-1 prior to texturing.

Now, you can rig vertex shaders or combiners to multiply results up a bit to cause this 'overexposure' to exceed clamped values, and newer extensions make supporting extended range & precision easier. Typically extending range by whatever trick will cost you a bit of arithmetic precision and start to introduce banding.

This is a pretty interesting and active area of real-time rendering right now and if you want to plunge into how do do this kind of thing well you should search for extended range & precision rendering and high dynamic range rendering HDR.

This may be a bit advanced but check this out for starters:
http://www.debevec.org/Research/HDRTM/egwr-01-cohen.pdf

halo
12-18-2003, 03:10 PM
What DLL is "glSecondaryColor3fEXT" found in? I am using BlitzPlus, so I have to write a functions declaration file. The command doesn't appear to exist in "opengl32.dll".

Thanks for holding my hand through this. I have never worked with extensions before, so I am doing several new things at once right now.

Regarding tesselation, I will only be using vertex lighting on static meshes (the furniture). I have lightmaps calculated for the large surfaces, but haven't implemented them in the engine yet. I'll actually be using "decal" lighting for dynamic lights on the walls, where a circular gradient texture is mapped onto the wall and rendered in a second pass. Here is the same scene, rendered in the editor (that I wrote):
http://www.leadwerks.com/gl2.jpg

[This message has been edited by halo (edited 12-18-2003).]

12-18-2003, 03:58 PM
All about the Gl extensions :
http://opengl.org/resources/features/OGLextensions/

On this particular case I would write in C under windows :
PFNGLSECONDARYCOLOR3FEXTPROC MYglSecondaryColor3fEXT; // type declaration

MYglSecondaryColor3fEXT= (PFNGLSECONDARYCOLOR3FEXTPROC) glGetProcAddress("glSecondaryColor3fEXT"); // gets the runtime pointer to the function.

Then call MYglSecondaryColor3fEXT () as any other gl function. The MY is something I have been told to do, because without it there could be problems (but I never stumbled into one).

No idea though how exaclty you have to do it with BlitzPlus ? If you can use wglGetProcAddress it is ok, else I don't know...

Maybe try a lib made to simplify extension loading ? I think about GLFW, but there are many others.

True that the second screenshot looks much better... How did you wrote the editor then, without openGL ?

12-18-2003, 04:13 PM
There seems to be at least 3 lights in the second screenshot, and only one on the first ? Have enabled all the gl lights you need ? Only light 0 is active by default.

glEnable(GL_LIGHT1);
glEnable(GL_LIGHT2);

And is the light model GL_LIGHT_MODEL_LOCAL_VIEWER set to 1 ?
How is set the lights attenuation ?

I remind that for quake 3, the texture brigthness is scaled up before they are sent to the card, at least 2 times. You can tweak that easily with glPixelTransferf and the GL_*color*_SCALE (multiply, better) and GL_*color*_BIAS (add, greyish).

halo
12-18-2003, 04:17 PM
The editor was written with GL, but I am designing a more advanced FPS game engine now.

I tweaked the lights and found a way to get what I wanted. By setting ambient light to full-bright, default lighting is the original vertex lighting, and GL lights increase the brightness up to full-bright. I think shininess is something I will deal with in material effects, so I will definitely revisit the issue.

Thanks all.

12-18-2003, 04:24 PM
Would you mind posting a screenshot showing your last update ?
I am eager to see how it looks now http://www.opengl.org/discussion_boards/ubb/smile.gif

halo
12-18-2003, 05:17 PM
If you want to try the demo, click here. (http://www.leadwerks.com/Phobos.zip) (1.91 mb)

This shows pre-calculated vertex lights, lightmaps, and a dynamic light that blends well with the pre-lit vertices.

The dynamic light does not yet effect the large flat CSG walls. These will be lit with another method. When finished, all the lighting methods should blend together and look pretty natural. I'm pretty stoked. With some additive lighting, this could look just like Unreal 2 (but not this test map, of course!).

There's some weird lightmaps in the hall, just because it uses multiple lightmaps, and I have to add something to sort which lightmap to use.

It strikes me as remarkably odd that you need to utilize 3 completely different methods of lighting to handle a game engine, and this doesn't even cover dynamic shadows.

[This message has been edited by halo (edited 12-18-2003).]

halo
12-19-2003, 12:51 AM
I added decal lights on the large walls, like what Half-Life uses for weapon flashes and blood splatters. It's a lot harder to create natural-looking soft lighting than it is to create dramatic, harsh game lighting.
http://www.leadwerks.com/gldemo.zip

cwc36
12-22-2003, 04:43 PM
hi,

quad:
*************************************
The brightest GL lights seem to make my objects is only as bright as the original texture. I want to actually make my lights so damn bright that they turn a textured object white, if they are close enough. How do I make the lights additive, rather than just multiplicative?
********************************************

I have finished a daynight demo. The method that i'm using is

glPushMatrix();
glFrontFace(GL_CCW); // set the front face of the skydome
glEnable(GL_BLEND); // blend the skydome
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glDisable(GL_LIGHTING);
glColor4f(1.0, 1.0, 1.0, alpha);
sky.Draw(); //skydome
glEnable(GL_LIGHTING);
glPopMatrix();


glPushMatrix();

// now change the background color based on alpha. This will make the
// background brighter
glClearColor((alpha - CONSTANT).3, (alpha - CONSTANT).3,(alpha - CONSTANT).3, 1.0f);
//draw sphere with lighting
glPopMatrix();

alpha is dynamic.

The output is linked as below: http://myopendemo.hypermart.net/opengl3.htm
Hope that will help.


[This message has been edited by cwc36 (edited 12-22-2003).]

JustHanging
12-22-2003, 11:44 PM
Hi,

This a bit of a hack, but might be worth a shot. The idea is to draw in two passes. On the first pass you draw as usual, lighting gets clamped to the texture color. Then in a second pass you add lighting that exceeds the intensity of 1.0. In practice:

First pass: Normal lighting setup, GL_MODULATE texture enviroment. This'll take care of the intensity range [0,1]

Second pass:
-glBlendFunc(GL_ONE, GL_ONE)
-glDepthFunc(GL_EQUAL)
-Subtract one from your global ambient to exclude the [0, 1] range that's already been rendered. It'll typically become a negative value, that's ok.
-No texture
This'll add the range [1..inf]. If the light saturates too rapidly, you may want to scale down the additive light, in practice scale all your light intensities (including global ambient) by a small value for the second pass.

-Ilkka

halo
10-24-2006, 03:18 PM
I asked this question a LOOOOOOOOOOOOOOOOOOONG time ago, when I was just starting out. I'm rather annoyed that no one at the time told me the right way to do this, which is to simply scale the texture color. This works consistently with lights or colors:

glTexEnvi GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE
glTexEnvi GL_TEXTURE_ENV,GL_COMBINE_RGB,GL_MODULATE
glTexEnvi GL_TEXTURE_ENV,GL_SOURCE0_RGB,GL_PREVIOUS
glTexEnvi GL_TEXTURE_ENV,GL_SOURCE1_RGB,GL_TEXTURE
glTexEnvf GL_TEXTURE_ENV,GL_RGB_SCALE,2.0

dorbie
10-24-2006, 08:41 PM
Originally posted by dorbie:
Now, you can rig vertex shaders or combiners to multiply results up a bit to cause this 'overexposure' to exceed clamped values, and newer extensions make supporting extended range & precision easier. Typically extending range by whatever trick will cost you a bit of arithmetic precision and start to introduce banding. You should learn to read more carefully because the part of my post quoted above tells you to do exactly this.