UPDATE: Shader based approach
Obviously there is some optimisation to be done, but it’s starting to look good. The way it’s done is something like this:
-
Create custom extended classes of
BitmapFilterandShader. InsideBitmapFilterchange__numPassesvariable to what you need for multipass shader. -
Render / create few textures and then inside
shader.__updatemethod send it to shader (shader.dataand respectiveuniformGLSL variables). Amongst others these are texture of light barriers, texture of scene below (to which lights will be applied to) and image of light data converted to pixels (light positions, angles, luminosity, etc.) together with other non-image data, such as scene resolution, etc. Also insidebitmapFilter.__initShadermethod assign current shader pass toshader.data. -
From this step everything is done in GLSL in fragment shader. The idea is, that at the end, the colour of every pixel will be blend of scene pixel colour and light pixel colour, where the light pixel colour is colour of the darkness, unless there is light affecting this point (distance from light to current pixel is small enough to affect it (equation of light propagation with distance, modified to look good) and there is no light barrier between this two points (basic line equation with
forcycle from light to current point). Compute this for every light in the area and blend to final colur of the light. -
(optional) You don’t have to compute light for every pixel of the screen if you have pixel-art graphics. If so, just compute lights for every pixel (or whatever else resolution) and in next shader pass copy it to rest of the scene pixel area.
-
Blur
-
Blend light colour with scene colour (something like Overlay or Hardlight equation, or something between).
Currently only major problem I have is FPS drop due to Blur step. Without it I can run stable 60 FPS, when I turn on 2 pass Gaussian blur, the FPS is reduced to 20 on my Intel HD3000 in WXGA resolution (first world problems, I know).
If anybody has any suggestions or questions, they will be appreciated.
