2D lighting and shading

BlitzMax Forums/BlitzMax Programming/2D lighting and shading

Twinprogrammer(Posted 2012) [#1]
Hello,

I've been trying to make a 2D game with lighting and shading. How would you be able to make that?

Twinprogrammer


*(Posted 2012) [#2]
erm do a google on 2d lighting and shading?


col(Posted 2012) [#3]
If you're using native BMax then using the SetBlend can help you here. Best school of thought is to render everything black then apply light to where you want it using bitmaps, or better still using OpenGL with some shaders would be the ultimate solution for you.


Twinprogrammer(Posted 2012) [#4]
What do you mean by 'native' Blitz max ? Also, the way I do it is use translucent ovals set to a white color. So how will I apply light ? Is there a command ?

Twinprogrammer


col(Posted 2012) [#5]

What do you mean by 'native' Blitz max ?


Any BMax2D command thats in the manual can be thought of as a native BMax command.

An alternative is to use the OpenGL driver, you could mix Max2D and OpenGL commands by saving the state of the BMax2D variables ( current blend mode, rotation angle, cls colour, drawing colour, alpha, linewidth - everything that Max2D changes ), then, if you know OpenGL, you can use the OpenGL commands directly in your code, in other words - you can access the hardware directly. When you're finished you can restore the BMax2D state as it was previously and carry on using the Max2D commands as if nothing has changed. Using that approach you mix Max2D and OpenGL as much as you want, also allowing you to create and use shaders for special effects. There are plenty of previous posts about doing this.


So how will I apply light ? Is there a command ?



Look up 'SetBlend [BLENDMODE]'

Try rendering the unlit areas first using SetBlend SHADEBLEND, the render your light with SetBlend LIGHTBLEND. This can have problems if you want 'transparent' images. Which is why I suggest using OpenGL and shaders then you have full control over the pixel blending.

There are also examples that have been posted that use ray casting to polygon shadow casters for some good lighting and shadows that use OpenGL.

EDIT:- Some links:-
BMax Polygon based lighting and shading
BlitzMax forum search for 'shaders'
OpenGL documentation

Last edited 2012