Jump to content

Shadows on a large area


Andrevv
 Share

Recommended Posts

Hello everyone!
This is my first question about my first babylon.js project. It will be a strategy game with complex economics (similar to Caesar 3, Knights and Merchants).
The framework is amazing, I like it very much, but I have some problems with shadows. Everything works fine, until I add lots of instances of a mesh across a large ground. The shadow becomes just a blob, almost invisible. I think the problem comes from DirectionalLight.prototype.setShadowProjectionMatrix where all mesh positions are checked to see how big the area is for casting shadows. The bigger the area, the more detail will be lost.

Can someone give me some advice on how to handle this problem?
I thought of the following:
1. Increase the mapSize from 1024 to a much larger value, but it doesn't make much difference with 2048 and the fps drops very much.
2. Somehow force the shadow casting area to be smaller with the help of customProjectionMatrixBuilder, and make it follow the camera, but how?
3. Make the shadow part of the model, like an old-school circle shadow with transparency. Ugly, but at least I get 60 fps :)
Any other idea may be helpful :)

You can take a look at it if it helps: http://feszer.go.ro/babylon.js/1/

1.PNG2.PNG

P.S. I know, that instances can't have different animations, I will handle that with separate clones for every action, I think :)

Link to comment
Share on other sites

Hello this is exactly the right analysis :)

1. This is an option. It could work to some extends.

2. This is my favorite. You can control the size of the shadowmap and not take in account all meshes if they are not visible. The center of the projection would be the camera area

3. Could work as a fallback :D

Link to comment
Share on other sites

  • 10 months later...

If I do

light.setShadowProjectionMatrix(camera._projectionMatrix.clone())

I get:

app.js:12432 Uncaught TypeError: Cannot read property 'length' of undefined
    at i../node_modules/babylonjs/babylon.js.i._setDefaultAutoExtendShadowProjectionMatrix (app.js:12432)
    at i../node_modules/babylonjs/babylon.js.i._setDefaultShadowProjectionMatrix (app.js:12432)
    at i../node_modules/babylonjs/babylon.js.i.setShadowProjectionMatrix (app.js:12432)

 

But I have absolutely no idea what I'm doing. Haha.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...