Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!






Shadows

Posted by Aardvajk, 30 April 2014 · 395 views

Decided to celebrate getting the character controller stable by having a big break from physics for a while and get some graphical stuff working. Getting the model and animations integrated was a quick job as I'd written and polished my code for this stuff in the 2D game (animation controller, blending etc) so decided to implement shadows.

Attached Image

[EDIT] Thanks to Ashaman, now have PCF edges to the shadows as well.

Attached Image

I'm staying away from stencil shadows after my last attempt and am just doing standard shadow mapping here, using an orthographic projection for the depth rendering as I want sort of cartoony, always from above shadows for this game. It actually works suprisingly well. I do nine samples in the pixel shader and average the result to get the depth at each pixel. Produces very nice results if the depth texture is 2048 x 2048, and passable if it is 512 x 512.

Had to rewrite a bunch of stuff in the Scene and SceneItem classes to allow for rendering different passes, at the moment just so I can render the depth pass, then the main pass, but this will come in handly later on I expect for other fancy effects. You can also now easily create an object that casts no shadow, just by setting its RenderPass::Depth method to RenderMethod::Null and so on.

Had to abandon shadows being casted onto the player character as looked a right mess. One thing about orthographic, from above shadows is you can't have them cast on vertical walls either as it looks wrong, so I pass the normal of the pixel into the shadow pixel shader, and only shadow it if its dot with 0, 1, 0 is above a certain threshold.

Since journals are always better with images, here is my depth texture for you to enjoy.

Attached Image

Thanks for reading.




Great work !

 

 

I do nine samples in the pixel shader and average the result to get the depth at each pixel.

Are you fetching 9 depth values, create the avg depth from it and compare it vs the scene depth ? The correct way would be to fetch 9 shadow values (comparision already done, result is 0=out of shadow, 1 = in shadow) and average this result, resulting in some soft shadow edges (PCF).

 

A nice,easy improvement is to start with 4 shadow-fetches and only continue to fetch (eg) 16 more if not all of the original 4 are either completly in shadow or out of shadow.

Great work !

 

 

I do nine samples in the pixel shader and average the result to get the depth at each pixel.

Are you fetching 9 depth values, create the avg depth from it and compare it vs the scene depth ? The correct way would be to fetch 9 shadow values (comparision already done, result is 0=out of shadow, 1 = in shadow) and average this result, resulting in some soft shadow edges (PCF).

 

A nice,easy improvement is to start with 4 shadow-fetches and only continue to fetch (eg) 16 more if not all of the original 4 are either completly in shadow or out of shadow.

 

Ah, interesting. Yes, I am doing it the (wrong) way you describe. Thanks for the tip, will have a look at that.

 

[EDIT] Got it, excellent, thanks.

November 2014 »

S M T W T F S
      1
2345678
9101112131415
1617181920 21 22
23242526272829
30      

Recent Entries

Recent Comments

Recent Entries

Recent Comments

PARTNERS