LWJGL 2D Lighting & Shadows

I followed this tutorial https://github.com/mattdesl/lwjgl-basics/wiki/2D-Pixel-Perfect-Shadows
Everything works perfectly except that I skip the part where the tutorial says you to render the occluders in full color

//STEP 4. render sprites in full colour		
		batch.begin();
		batch.setShader(null); //default shader
		batch.draw(casterSprites, 0, 0);
		batch.end();

So I disabled that
What I now get is this

What I want is to have the shadow not cast the object entirely like this.

render the background, then the shadows, then your foreground.

That’s exactly what I disabled, if I would render the foreground you would be able to see players in the dark at full color.
I just want that when shadows are casted that the casted sprites are lightened up and not fully black.

firstLayer = spriteFBO1 * shadowFBO
secondLayer = spriteFBO2 * shadowFBO * 0.85 + 0.15

Basically you reduce the shadow effect and add ambient light, for all sprites you want not to be fully dark / stand out from the black terrain. I will look funky, but you might make it work.

Basically you need 3D lighting for the effect you are after.

That won’t work since I set the player’s sprites to cast shadows. So now it’s completely black. What I want is for the shadow that’s casted on the player to be smoothened out backwards like I showed in the 2nd picture.

So the player’s sprites are completely black at this moment, and not affected by lighting. they just cast shadows.

Oh. I think you’re talking about normal maps. Something like this?

http://www.java-gaming.org/index.php?topic=27516.0

As you can see here, the sprites are casting shadows and are lit up WHEN they are in the light(I can’t just render the scene over the shadows, it would show all entities in the dark.)

So yeah a basic form of normal mapping? Not really sure of any other ways to do this other than normal mapping.

Is there an easy way without normal mapping? I don’t need depth I just want the sprites to be lit when they’re in the light. Davedes I need you’re help :stuck_out_tongue:

Like the side that is facing the light source should be lit up?

I think he wants the occluders be lit up, but the entities behind the occluder be in the shadows.

You two are spot on

Anyone? ??? :-\

You could blur the generated “shadow map” a lot. That’d cause the light to bleed over edges and light the shadow casters as well. I think that’s what the image you showed as an example does.

I have no idea how to do that with shaders, it’s confusing.
But what I could do is create a separate caster sprite that already is blurred and render that to the shadowmap. and render the full color sprite underneath that.
Edit: Wait that would only work for 1 direction :S I need to do it with shaders, anyone willing to provide some tutorial/link or a piece of code

A simple improvement is to render the shadow map at a reduced resolution and then blur it. That’ll have higher quality while also being faster as you’ll get a higher blur radius for the same blur kernel. If however you have no experience with shaders or framebuffer objects, this will probably be a bit tricky to implement. Still, a blurring shader is quite easy to write, especially a fullscreen one.

Hmm, it might be easier for you to just try to follow this tutorial instead: http://www.gamedev.net/page/reference/index.html/_/technical/graphics-programming-and-theory/dynamic-2d-soft-shadows-r2032. I think they have the effect you’re looking for:

The trick here is to only have convex polygon objects and extruding the faces facing away from the light, which leaves the occluder lit while occluding everything behind it.

Hhhm I would need to find a way to convert the occluder sprites to polygons