[Help] 2D Shadows/Image Modes

I was watching https://www.youtube.com/watch?v=4BtjcH-iLR0 and he was explaining how a 2d shadow system would work.
I made a little image using minecraft textures in gimp and used the image mode ‘Multiply’ on it.
-=Without Light=-
[spoiler]
http://www.infinitecoder.net/games/without.png
[/spoiler]

-=With Light=-
[spoiler]
http://www.infinitecoder.net/games/with.png
[/spoiler]

-=Remember=-
Remember, these are just images, not the real game.

-=Need Help With=-

  • Texturing a light
  • Using the image mode ‘multiply’ to draw it

If you can help, that’d be great!

If you are using LibGDX there is Box2DLights which will make your life easier. If you are using LWJGL then you have to learn about glBlendFunc to achieve the lighting in your screenshots; or shaders. And it won’t be “dynamic” in the sense that objects won’t affect the light – for that you need to use meshes or shaders.

I am using LWJGL, and am pretty new to it, so I’ll learn some stuff. It also wont be dynamic. It will be a game which revolves underground with wall torches as light.

i don’t know if this is the good way to do it, but i did this effect once in a flash game, i made it like this :
-layer 1 = game (your 1st picture)
-layer 2 = a whole black square that cover the game with alpha value lower than 100%
-“layer” 3 = i said “layer” cause this one is related to the 2nd layer, it’s a mask form that “delete” a certain area of the 2nd layer, so like that you’ll have a light effect.
now i hope LWJGL expert will help you to realize these steps or give you a magic method to do it ::slight_smile:

You could render light images in a FBO in one pass, and in the second pass, simply use a shader which computes the screen position and fetches the color from the light FBO and multiplies it by the color of the to-render-pixel.

Any one know how to do this in Java2D

Sure, you could cycle through all of the light sources close enough to a certain pixel. Then, you could find an average value of the distances and multiply that by a light intensity constant. Then, repeat, for all of the pixels within a light source’s radius.

Does that mean that I will need to access all the pixels of the textures used to make up the game?

No, the textures have nothing to do with the lighting. What you need to do is blend the textures, and a “second” layer of pixels together. You change the color of the pixels and then blend them together with the texture. You should not change the RGB of the texture itself. I have no idea how to do blending in J2D though.

Opiop, I understand what your saying, basically its like like having a black overlay, and then using longarmx’s formula to calculate the “transparency” of the pixels depending on how far away from the light source the pixels are, which means I’m going to need to work out radii of the circle of range for each light source.

Would the same go for depth fog? Like the further down you go, the darker it gets?