PDA

View Full Version : Spotless spotlights :(



glBomb
08-13-2006, 11:51 AM
A question regarding lights.Are spot lights really diffuse lights with the spot_cutoff ,spot_direction properties set to focus the light? Can i use spot lights to light up a region in an orthographic view. Like suppose i use glOrtho() to set up the view & then place textured quads in say the z=0 plane to place images for a 2D GAME. Now i use a spot light to light up a region of the z=0 plane...will it work?
Or do i have to use texture effects & light maps instead ?

I have also noticed that using spot lights does not high light a particular region of a plane when its facing the light source.The whole region is uniformly lit. How do i light up a particular region only & severely attenuate the light in the surrounding area.Basically if someone could post some code for properly creating & managing SPOT LIGHTS it will be really helpful

glome
08-13-2006, 01:14 PM
>A question regarding lights.Are spot lights really
>diffuse lights with the spot_cutoff ,spot_direction
>properties set to focus the light?

Yes. (well not just diffuse. Like all lights they can have specular and ambient component too. But they are normal lights, if that is what you mean.)

>Can i use spot lights to light up a region in an
>orthographic view.

Projection method makes no difference.

>Like suppose i use glOrtho() to set up the view &
> then place textured quads in say the z=0 plane
>to place images for a 2D GAME. Now i use a spot
>light to light up a region of the z=0
>plane...will it work?
>Or do i have to use texture effects & light maps instead ?
>I have also noticed that using spot lights does
>not high light a particular region of a plane
>when its facing the light source.The whole region
> is uniformly lit. How do i light up a particular
> region only & severely attenuate the light in
>the surrounding area.

The OpenGL lights (spot or otherwise) are per vertex. To lit a large plane/polygon you need to subdivide it to small pieces or calculate the light per pixel in a shader.
See the picture at the bottom of this page:
http://www.lighthouse3d.com/opengl/glsl/index.php?spotlight

In a 2D game it will be easy to just overlay a texture/circle to present the spot light. This is the medhod you most likely should use.

>Basically if someone could
>post some code for properly creating & managing
>SPOT LIGHTS it will be really helpful

Read chapter 5 from the Opengl Red Book. The book is really really old, but mostly still valid.
http://www.gamedev.net/download/redbook.pdf

plasmonster
08-19-2006, 11:00 AM
Projective textures can be pretty cool for spotlights too.

glBomb
08-19-2006, 12:10 PM
Hey that light house link is really cooool...thankx glome!! :)
Since writing shaders means i have to go through all the GLSL stuff,isnt there any shader provided by openGL itself that i can use just to test the spotlight effect.Perhaps some thing with the GLUT library. I dont want to get into writing shaders immediately..i dont really want spectacular effects....i just want to clearly see the spot light lighting up a region properly more like a spotlight than a directional one

@sgram
Projective textures ??!!

glome
08-21-2006, 03:14 AM
>isnt there any shader provided by openGL itself
>that i can use just to test the spotlight effect.

No. Unless you count the fixed function be a "shader".

Using shaders in a 2D game is a bit overkill, so just overlay a circle on top of the other graphics and that's all the spotlight you need.