c++ - 2D Ambient lighting in OpenGL -
im making 2d side scroller game , implementing lights. lights light gradient texture rendered on top of terrain multiplied make brighten area. however, dont know how nor understand how ambient lighting. following picture sums have , bottom part want.
i open answers regarding shaders know how use them.
i ended creating fbo texture size of screen, clearing color of ambience , drawing in nearby lights. then, passed through shader made takes in 2 textures uniforms. texture draw , light fbo itself. shader multiplies textures being drawn fbo , came out nicely.
ambience.frag
uniform sampler2d texture1; uniform sampler2d texture2; varying vec2 texcoord; void main( void ) { vec4 color1 = vec4(texture2d(texture1, gl_texcoord[0].st)); vec4 color2 = vec4(texture2d(texture2, texcoord)); gl_fragcolor = color1*vec4(color2.r,color2.g,color2.b,1.0); }
ambience.vs
varying vec2 texcoord; uniform vec2 screen; uniform vec2 camera; void main(){ gl_position = ftransform(); gl_texcoord[0] = gl_multitexcoord0; vec2 temp = vec2(gl_vertex.x,gl_vertex.y)-camera; texcoord = temp/screen; }
Comments
Post a Comment