It looks like you're new here. If you want to get involved, click one of these buttons!
If you happen to be working on a 2D top-down game and want some global illumination on top of that, say no more! Actually, if you find something to be terribly wrong or confusing in the code then please tell me!
This project bakes diffuse global illumination for your scene where you define the resolution of the lightmap. It supports as many lightbounces as you like from sky, sun and emissive objects. The algorithm is based on path tracing and accelerated with a distance field in order to reduce waiting times and avoid crashing the program.
The code includes a tab called "ReadMe", read it!
Potential questions that you might have:
Q: Why does the lighting sometimes look bugged when I have calculated 1 bounce of light?
A: Calculate 1-2 more bounces and it will disappear!
Q: In my game the lighting is really dark, why?
A: Two words, gamma correction! Essentially our screens does not display light in a linear form, so when displaying colors we need to compensate.
Instead of:
gl_FragColor=vec4(Color,1.);
do
gl_FragColor=vec4(pow(Color,vec3(0.45)),1.);
This is correct!
Code:
https://github.com/firelava135/GIDF2D/blob/master/Code.txt
Here is an example:
Comments
Did anyone save this code? Link doesn’t work...
@UberGoober couldn't you just set up a 3d craft scene, but put all the objects on a plane. The light source could be above the plane.
@piinthesky can you make a boilerplate showing using an image on a plane?
@skar not sure exactly what you are after, but this illustrates what i was imagining: a plane with 3D objects sitting on it (cubes in this example) and the standard craft Sun lighting.....
I’m trying to find ways to do lighting in 2D not 3D, but I thought you meant to put a 2D image as a texture onto a plane and use the 3D lights on it, but that’s not going to work in the desired way.
https://github.com/mattdesl/lwjgl-basics/wiki/ShaderLesson6
@skar gotcha, here is a little demo of lighting effects using the inbuilt surfaces: Basic Bricks, Stone Brick and Desert Cliff. Quite fun to see the effect of the varying the different parameters. I expect with Shade one could do a lot more.
This is really great, thanks for setting it up. It’s as I thought though, this solution probably is not what i want to do. I’ll have to play with it some to see if it’s the best solution but it seems to me we should be able to use Mesh and Shader to have a 2D light effect without having to use craft 3D