2D Lighting - How to learn the basics?


#1

Hey,

I’ve been chomping at the bit to get started on Open GL rendering for creating 2D lights, but I can’t wrap my mind around it. I’ve checked out the Open GL source tutorials, Simple 2D Lighting, and How to learn GLSL and shaders for Defold, but I couldn’t understand the basic requirements for the code and setup.

How do I set up render targets, masks, the renderscript, and etc to get a simple light? I’m very new to editing render scripts. I’ve only used materials, render.predicate, and render.draw() very minimally.


#2

I know that there are parts of examples posted here in the past but I’m not sure there is a fully working runable example for this exactly.

Render targets are just textures you setup. You enable these textures when drawing tags in your render script.

Materials can use render target textures as texture inputs. So when you render to a quad (in your game world so it shows up to your camera) which is scaled up to the size of your screen you can use whichever render target textures you’ve produced and combine them in a useful way to your game.

For lights you can use a bunch of approaches… for example you can have soft circular sprites with a render tag which you draw onto a render target texture which then can act as a color mask for where you shade.

Maybe @Leviathan could put up his example. @ross.grams do you have one you could put up too that’s a runable project?


#3

The grading tutorial does not do lighting, but it walks you through setting up render targets, render script and materials. Check it out and you will hopefully have a better grasp of how to proceed: https://www.defold.com/tutorials/grading/


#4

If you have read through my posts and links in the “Simple 2D Lighting” thread, I don’t have a lot more to say. I did put up a working example of my lighting setup in the Rendercam thread, here. It’s not perfect and I haven’t tested it in a while, but maybe it will help.

I also did a little demo of the bouncing solitaire cards effect. It’s not lighting, but maybe a simpler intro to render targets for you? Link here.