Lighting model for two-dimensional horror games

    image
    The most impatient: lagging demo , written in chrome . It takes 20 seconds to load on my machine.

    This idea came to me about 2 years ago. I drew attention to the fact that, in low light conditions, I perceive visible objects mainly in bluish tones and with a slight loss of sharpness. Perhaps this is a purely psychological perception, but we are not talking about that now. I was curious about what a 2D game would look like with such lighting features. In order to find out, I, without understanding the shaders, sketched a demo in the most convenient language for me - javascript. Since the effect is applied to dimly lit areas, it is not the most noticeable of what is happening on the screen, but it adds quite noticeable charm.

    The result is obtained from three buffers:
    A picture is formed on the first buffer, to which the post-effect will be applied;
    The second buffer is used for motion-blur'a light map. In terms of meaning, it implements “memory” - after the area is lit up, it will still be visible for some time, even if no light source is already directed at it.
    On the third, the light map itself is drawn - lighting with geometric shadows for the current frame.

    Each frame of the second buffer is shaded and blurred, a third buffer is highlighted on top of it. The result is used as information for the post-effect: at relatively high illumination values, the pixel is shaded according to the standard algorithm, and at low - a slight blur and gradual fading of the red and green channels already begin.

    In my implementation, the blur from the post effect is calculated for 255 radii before launch, and it takes 20-30 seconds.

    The old version, more nimble, without geometric shadows and with an abundance of bydcode can be poked here .
    Fresh, with shadows - here .
    Both versions were written in chrome. My Firefox seems to be trying to draw everything too, but it doesn’t perceive the coordinates of the mouse (I will be grateful if someone tells me how to fix this), and FPS will be lower (probably just the old version). I don’t have an opera.

    Management in the fresh version:
    LMB - create convex objects from which the shadow will be cast. The direction of creation (clockwise or counterclockwise) has a difference.
    RMB - cancel creation / delete an object under the arm.
    SCM - turn on / off the second light source.

    The blur algorithm was taken from here .
    Background picture from the recently released game They bleed pixels .

    Also popular now: