PDA

View Full Version : Direct x equivilent in opengl



bobtedbob
12-02-2011, 04:36 AM
Hi

Is there an equivilent to the opengl point light in opengl?

Example code :


// Fill in a light structure defining our light
D3DLIGHT9 light;
ZeroMemory( &light, sizeof(D3DLIGHT9) );
light.Type = D3DLIGHT_POINT;
light.Diffuse.r = 1.0f;
light.Diffuse.g = 1.0f;
light.Diffuse.b = 1.0f;

// Point lights have no direction but do have a position
light.Position = pos

// Tell the device about the light and turn it on
light.Attenuation0 = 0.1f;
light.Range=200.0f
gD3dDevice->SetLight( 1, &light );
gD3dDevice->LightEnable( 1, TRUE );

Thanks

tksuoran
12-02-2011, 04:44 AM
Yes. For legacy fixed function lighting, see http://glprogramming.com/red/chapter05.html

thokra
12-02-2011, 04:45 AM
Sure. But you don't set the values this way.

Check out: http://glprogramming.com/red/chapter05.html

BTW, this was a 1 sec Google search. But since I'm in a good mood I don't mind.

bobtedbob
12-02-2011, 04:57 AM
Thanks but I have seen the webpage you have linked and it doesn't answer my specific question.

In directx there are multiple types of light

Ambient Light
Spot Light
Directional Light
Point Light

The first three map very well to opengl but the point light doesn't

The specific parameter of interest in the example I posted was

light.Range=200.0f

This is where I took the example from.

http://www.toymaker.info/Games/html/lighting.html

The range is the maximum distance the light can travel, the attenuation is covered as you say in the links posted above but the important bit of the point light is the range, ie where the spot light is no longer relevant and the ambient light is now the default.

V-man
12-02-2011, 05:09 AM
I believe the range parameter doesn't exist in GL.

thokra
12-02-2011, 05:15 AM
In fixed-function OpenGL lights are identified by the information you pass.

See: http://www.opengl.org/sdk/docs/man/xhtml/glLight.xml

By default, for instance, a light source has the position (0, 0, 1, 0) (notice the w-component). This means you have a directional light source. The direction is the default value of GL_SPOT_DIRECTION: (0, 0, -1, 0).

If you want to have a point light source you need to set a position other than the default and a w-component > 0.

If you want a spot light source you also need to set a different GL_SPOT_CUTOFF since the default is the special value 180.

bobtedbob
12-02-2011, 05:16 AM
Yeah I thought so as the documentation doesn't mention anything like this (but wanted to confirm), does anyone know how wine gets round this then as they render directx commands in to opengl and can render point like directx programs?

thokra
12-02-2011, 05:18 AM
I believe the range parameter doesn't exist in GL.

Nope. Not using FF. But if you think about it, that's actually more realistic since you can't tell light rays to suddenly vanish at some distance. :)

thokra
12-02-2011, 05:20 AM
[..] how wine gets round this [..]

I think Wine will simply ignore the distance calculation.

bobtedbob
12-02-2011, 05:25 AM
the attenuation in opengl is rubbish, its almost impossible to say... be very bright at the spot of the point light then fade out gradually till at radius 200 you have blended in with the ambient light.

I may also be very bad at attenuation in opengl :)

Also with spot light I found that if you are outside of the degree's of spotlight it is pitch black or very dark. That isn't too relistic to me.

thokra
12-02-2011, 05:31 AM
the attenuation in opengl is rubbish [..]


Actually the attenuation factor is exactly the same as in Direct3D. I think you're doing it wrong.

EDIT: BTW, neither the GL nor D3D are realistic when it comes to attenuation, since the physically correct attenuation is merely 1 / d ^ 2. The thing is that with three factors you can tweak the attenuation more so you get the desired visual result - still, it's not physically correct.

EDIT2: Considering the range, in the real world there is no such thing. In geometric optics the luminance some differential area receives decreases with the squared distance, so not providing the user with an explicitly value from to indicate that all calculations be discarded IS more realistic.

EDIT3: The fact that there's no incident light outside the spot lights cone is mathematically correct. D3D simply maintains two spot cutoff angles. In the range between the two the lighting contributions are simply faded out by some function (linear for instance).

V-man
12-02-2011, 06:15 AM
[..] how wine gets round this [..]

I think Wine will simply ignore the distance calculation.

I would image Wine ignores it as well. I don't feel like looking at the code.
Also, not many games use D3DLIGHT. They then to use light maps.

Or they would be using shaders and the people working on Wine concentrate a lot of their work writing code converters.

Alfonse Reinheart
12-02-2011, 09:30 AM
the attenuation in opengl is rubbish, its almost impossible to say... be very bright at the spot of the point light then fade out gradually till at radius 200 you have blended in with the ambient light.

That's because light doesn't work that way. It's only "rubbish" if you insist on using non-gamma-correct lighting, non-HDR lighting, and unrealistic light attenuation. If you're doing anything remotely conversant with reality, it's fine.