Hey guys I’m trying to implement lighting and shadows for a 2d game that is made out of polygons. Although my game is a side scroller I am using a top down approach for the lighting / shadows. I’m trying to combine two techniques:
Technique 1. 3 pass rendering for lighting (SEE http://www.java-gaming.org/topics/realistic-lighting-in-a-2d-game/20161/msg/161973/view.html#msg161973)
—Pass 1: Render map and polygons to FBO #1
—Pass 2: Render lights to lightmap FBO #2
—Pass 3: Combine both offscreen textures with fragment shader.
Technique 2. Shadows: (SEE htt p:// lw jgl.org/forum/ind ex.php/topic,5203.0.html (sorry couldn’t link it properly, remove spaces))
Except I have some differences:
—1. Background won’t be fully black
—2. Shadows will be semi - transparent rather than fully black, and shadows will darken other shadows if they overlap
—3. I don’t want shadows to exist on top / underneath lights (SEE http://prntscr.com/46jgw8)
My goals:
-if no lights exist the area should be mostly in shadow. I want lights to Add to the brightness of the game, and the shadows they create should not darken the map any more than if the light didn’t exist.
My problem:
I’m unsure how to combine the shadows with the lightmap in a way that makes sense, so shadows don’t exist where lights do. (NB only occurs with multiple lights)
My proposed solution:
—Pass 1: Render map and polygons to FBO #1
Section I’m unsure about:
—Lightmap starts off empty (all pixels set to “dark colour” RGBA (0.1,0.1,0.1,1))
—Somehow render the shadows and multiple lights to the lightmap (FBO #2). Shadows can’t render where any of the lights are (or need to combine somehow) and lights can’t block out shadows completely?
—Pass 3: Combine both FBO #1 with FBO #2 with fragment shader.
Can anyone help me with this?
Thanks,
roland