Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (799)
Games in Android Showcase (237)
games submitted by our members
Games in WIP (865)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  2D soft shadows  (Read 17833 times)
0 Members and 1 Guest are viewing this topic.
Offline Cyraxx

Junior Devvie


Medals: 1



« Posted 2016-02-20 01:01:02 »

Hi!

I'm in the process of creating the light engine for my LibGdx project. I'm using box2d's raycasting to build a light mesh (it is show on the picture).





With this method though I can only create hard shadows and I don't have any idea how I could make the shadow edges smooth or "realistic" looking.
I was hoping that s'one will be able to shed some light on my issue.
Offline boxsmith
« Reply #1 - Posted 2016-02-20 06:26:25 »

There's an aging gamedev.net article on drawing shadow penumbrae with textured "fins" here. This seems like it might be readily applicable to the method you're using right now.

Another approach relies on shaders to generate a soft shadow texture; it's more complicated, but lets you use arbitrary sprites to cast shadows. You can read about it here.
Offline Quexten

Junior Newbie





« Reply #2 - Posted 2016-02-20 14:02:49 »

The library box2dlights achieves this by rendering the light meshes into a framebuffer that's lower resolution than the screen resolution.
Then it blurs the framebuffer using gaussian blur and renders that to the screen.
For reference: https://github.com/libgdx/box2dlights
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Cyraxx

Junior Devvie


Medals: 1



« Reply #3 - Posted 2016-02-22 18:02:45 »

I managed to implement the penumbra's outline as shown on this picture.


I have a penumbra texture but my problem is I don't know how to texture the ABC triangle with it.
Could anyone explain how should I do it?

The penumbra texture:
Offline boxsmith
« Reply #4 - Posted 2016-02-22 18:26:50 »

Quote
You can clearly see how the shadow fin will be rooted at the bottom left, and the two edges running vertical and diagonally to the top edge. Also note the line of white pixels along the right side, this prevents blending artefacts along the vertical edge. The bottom right half of the texture is unused, although if you really wanted to you could pack something else in here just as long as you're careful not to bleed over the edge.

It sounds like A goes in the bottom-left corner, B the top-right, C the top-left.
Offline Cyraxx

Junior Devvie


Medals: 1



« Reply #5 - Posted 2016-02-22 18:53:53 »

Quote
You can clearly see how the shadow fin will be rooted at the bottom left, and the two edges running vertical and diagonally to the top edge. Also note the line of white pixels along the right side, this prevents blending artefacts along the vertical edge. The bottom right half of the texture is unused, although if you really wanted to you could pack something else in here just as long as you're careful not to bleed over the edge.

It sounds like A goes in the bottom-left corner, B the top-right, C the top-left.

So when I'm creating the triangle's mesh and sending the texture coordinates per vertex, I'd have to set A(0,0), B(1,1) and C(0,1) then use these coords in the fragment shader to get the appropriate color of the penumbra texture?
Offline cylab

JGO Kernel


Medals: 195



« Reply #6 - Posted 2016-02-22 19:20:38 »

So when I'm creating the triangle's mesh and sending the texture coordinates per vertex, I'd have to set A(0,0), B(1,1) and C(0,1) then use these coords in the fragment shader to get the appropriate color of the penumbra texture?

Should be right, don't hesitate - just do it! Cheesy

Mathias - I Know What [you] Did Last Summer!
Offline Cyraxx

Junior Devvie


Medals: 1



« Reply #7 - Posted 2016-02-22 20:00:58 »

[EDIT]

I'd still like to get a little help with the blending modes.
Right now I've managed to get everything working apart from that.

Here is a pic of the problem:


I should mention that I'm implementing deferred rendering since I'm going to use normal mapping later on.

At the moment here is how I'm rednering my scene:
- I'm drawing every diffuse texture into an FBO
- Then I'm binding the FBO's texture and drawing it with ambient lighting to the default FBO
- Then drawing the light's meshes one by one using additive blending and binding the diffuse FBO's texture
- Then drawing the penumbras (not sure what blending mode to use here or how to set it up)

To be honest I'm not sure that this rendering method is correct at all.
Could s'one tell me how to set up the the penumbra drawing or if my method of rendering is good at all?
Thanks in advance!  Smiley
Offline Cyraxx

Junior Devvie


Medals: 1



« Reply #8 - Posted 2016-02-24 21:16:43 »

I really don't like bumping my own thread, but I'm kind of desperate for an answer since I'm stuck with this. Sad
Offline cylab

JGO Kernel


Medals: 195



« Reply #9 - Posted 2016-02-24 22:08:04 »

I can't give you tested code, but you want a simple multiplication of the fin texture and the FBO, so according to https://www.opengl.org/wiki/Blending#Blend_Equations, you want something like:
1  
glBlendFunc(GL_DST_COLOR, GL_ZERO)


Mathias - I Know What [you] Did Last Summer!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Hydroque

JGO Coder


Medals: 25
Exp: 5 years


I'm always inspiring a good time.


« Reply #10 - Posted 2016-02-25 01:52:03 »

I can't give you tested code, but you want a simple multiplication of the fin texture and the FBO, so according to https://www.opengl.org/wiki/Blending#Blend_Equations, you want something like:
1  
glBlendFunc(GL_DST_COLOR, GL_ZERO)


One thing to note is that this is alpha blending. With that image given, you need to turn all white into alpha. This will allow the alpha blending to work. I know a lot of people who can't get glBlendFunc(GL__DST_COLOR, GL_ZERO); to work. Try glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); That is all in the GL11 package.

Happy coding!

You think I haven't been monitoring the chat? http://pastebin.java-gaming.org/c47d35366491fHere is a compilation <3
Offline cylab

JGO Kernel


Medals: 195



« Reply #11 - Posted 2016-02-25 08:41:03 »

For his usecase he needs color modulation and not alpha blending, since he is trying to darken existing pixels.

Mathias - I Know What [you] Did Last Summer!
Offline pitbuller
« Reply #12 - Posted 2016-02-25 18:11:30 »

Exclude penumbras from lights geometry and then just render them as additive. All lighting is additive and penumbra areas are just partially shadowed lights. No need to make this any harder. If you render multiple lights to single buffer you can't solve this problem with blending anymore.
Offline Cyraxx

Junior Devvie


Medals: 1



« Reply #13 - Posted 2016-02-26 09:09:09 »

Exclude penumbras from lights geometry and then just render them as additive. All lighting is additive and penumbra areas are just partially shadowed lights. No need to make this any harder. If you render multiple lights to single buffer you can't solve this problem with blending anymore.

I'm already doing that somewhat. Since my light's geometry is built with a triangle fan I can't exclude all of it.



The cyan lines on the picture are the light's geometry and the red triangles are the shadow fins.
Half of the soft shadow is looking fine but the problem is the white triangle areas. Thats where part of the shadow fin meets with part of the light so they (I guess) amplify eachother and that's what I can't solve at the moment.
Offline cylab

JGO Kernel


Medals: 195



« Reply #14 - Posted 2016-02-26 11:00:43 »

Hmm, I can think of 3 possible solutions here:
  • take an incorrect shortcut and move the whole penumbra into the half not covered by the triangle strip, squishing the soft shadow into half the width (you could make up for this with some texture editing)
  • move to a buffer per light and do the multiplication blend
  • bite the bullet and fix your light geometry triangle fan: you could just add an edge from the light source to the far corner of the shadow fin and move the end-point of the neighbouring triangle to the corner of the occluder


Mathias - I Know What [you] Did Last Summer!
Offline pitbuller
« Reply #15 - Posted 2016-02-26 17:40:09 »

Just fix that geometry. With modern GPU triangle strips don't usually offer any performance benefits sometimes they can even make things worse. Just always use indexed triangles and life is easier.
Pages: [1]
  ignore  |  Print  
 
 

 
Riven (201 views)
2019-09-04 15:33:17

hadezbladez (4920 views)
2018-11-16 13:46:03

hadezbladez (1814 views)
2018-11-16 13:41:33

hadezbladez (5196 views)
2018-11-16 13:35:35

hadezbladez (1025 views)
2018-11-16 13:32:03

EgonOlsen (4389 views)
2018-06-10 19:43:48

EgonOlsen (5230 views)
2018-06-10 19:43:44

EgonOlsen (2973 views)
2018-06-10 19:43:20

DesertCoockie (3876 views)
2018-05-13 18:23:11

nelsongames (4308 views)
2018-04-24 18:15:36
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!