4
\$\begingroup\$

I have a simple day and night cycle by at day disabling OpenGL lighting and at night enabling openGL Lighting. When I enable everything appears darker. My question is How would I make it that at a specific spot there would be a light that will only light up its surrounding area for example:

http://media.giantbomb.com/uploads/0/276/1414275-light_large.png

Where the light is is where I want to position my light. My application is in 2D.

EDIT:

I read up more about 2D Lighting and I thought about it how would I do it so that I have a QUAD that is over all the screen and has a certain opacity and then i draw s circle on a QUAD that is yellow and it overwrites the quad so that the images that are drawn behind it aren't effected, like poking a hole in it..

\$\endgroup\$
2
  • 2
    \$\begingroup\$ Just add a point or spotlight. \$\endgroup\$
    – rasmus
    Commented Sep 13, 2012 at 23:20
  • \$\begingroup\$ How? :P I cant find how to do so anywhere.. \$\endgroup\$ Commented Sep 14, 2012 at 17:43

2 Answers 2

0
\$\begingroup\$

I would use a 2D lightmap and blend it using GL_DST_COLOR,GL_ZERO and playing on opacity.

If you want a more complex thing look for projected texture using a shader :

// The vertex shader

varying vec4 pos;

void main(void){
  pos=vec4(gl_Vertex);
  gl_Position=ftransform();
}

// The fragment shader

uniform sampler2D inputImage;
varying vec4 pos;

void main(void){
gl_FragColor=texture2DProj(inputImage,gl_TextureMatrix[0]*pos);
}

Another solution is by using 3D lightmapping (if 3D textures are available on your platform), wich is also easy to implement.

I hope it helps :)

\$\endgroup\$
2
  • \$\begingroup\$ I read up more about 2D Lighting and I thought about it how would I do it so that I have a QUAD that is over all the screen and has a certain opacity and then i draw s circle on a QUAD that is yellow and it overwrites the quad so that the images that are drawn behind it aren't effected, like poking a hole in it.. \$\endgroup\$ Commented Sep 14, 2012 at 17:20
  • \$\begingroup\$ @gopgop: That is basically exactly what he just told you to do in his first suggestion. Since it seems you may have found your own answer, it is generally helpful to post that answer and accept it (so anyone else searching for this same problem can see your solution). \$\endgroup\$ Commented Oct 15, 2012 at 1:15
1
\$\begingroup\$

Another option is to perform per-pixel lighting in your pixel shaders. If you calculate vector L to light (in screenspace) for each fragment (and supposing fragment normal N is (0,0,1) in screenspace ) then modulate fragment color by some f(N, L). If you prefer some fancy shading model, you're free to implement one.

This solutions is not dependent on some texture resolution and is always smooth, but requires either additional post-process pass, or using this piece of shader to color each object with spot on it...

\$\endgroup\$
1
  • \$\begingroup\$ I read up more about 2D Lighting and I thought about it how would I do it so that I have a QUAD that is over all the screen and has a certain opacity and then i draw s circle on a QUAD that is yellow and it overwrites the quad so that the images that are drawn behind it aren't effected, like poking a hole in it.. \$\endgroup\$ Commented Sep 14, 2012 at 17:22

Not the answer you're looking for? Browse other questions tagged .