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 );
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.
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.
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?
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.
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).
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.