Jump to content

Shadow quality and resolution


Recommended Posts

Hi guy,

I have a very large scene(2541 meshes) and I wrote a bit of code to loop through the meshes array and get specific meshes(Oak trees) so that they could be pushed into the shadows render list, however the shadows quality is very poor...see image.

This is the code for my shadowGenerator, as you can see I just want simple shadows no need for ESM or blurred shadows of any kind.

            var shadowGenerator = new BABYLON.ShadowGenerator(8192, sunLight);
            for(var i = 0; i < scene.meshes.length; i++){
                    var tree = scene.meshes;

The issue seems to be shadowMap related and I truly don't know what to do about it. In some areas of my level the trees don't even seem to cast a shadow as if they were outside of the light's view. If you guys have any tips or ideas I'd appreciate the help a lot.


Link to comment
Share on other sites

Hi David,

When you say to put the light as close to my scene as possible what exactly do you mean? I'm sorry I'm a bit confused.

My level is about 5000 units by 5000 units in size, so my light's vector3 position  is;  5000, 5000, 1000. Is my scene too big for the light(see image of level)?

Does the unit size of the scene affect the shadowMap quality?

Thank you for your help.


Link to comment
Share on other sites

That's a big map.  Did you look at softening the shadow?
    shadowGenerator.useBlurExponentialShadowMap = true;
    shadowGenerator.useKernelBlur = true;
    shadowGenerator.blurKernel = 64;

Another thing is increasing the size of the shadowMap - you have 8192.  What have you tried?  I spent a lot of time getting shadows right - lights, intensities, positions, shadowMinZ, shadowMaxZ, self shadowing...

Link to comment
Share on other sites

Well the reason the shadowMap size is 8196 is that anything smaller doesn't show a shadow at all.  when I use "useBlurExponentialShadowMap = true;"  like you suggested the shadows get nice and blurred and it looks pretty good, however, FPS dips to 15 and I'm using an nVidia GeForce GTX 970 which is a decent card. Perhaps my scene is just too big, it's already and between the 2500 plus meshes, 12 million plus vertices  and 78 drawcalls .

Link to comment
Share on other sites

I spent a fair amount of time in blender getting my vertices count way down, but you have millions!  I don't know what the impact would be of making your scene 1/2 as big, but it is a lot of effort if it doesn't make a difference.  I think DK's suggestion to merge meshes would help a lot, if that is possible - ie: are your building walls with the same material one mesh?  I have a GTX1050 and with certain shadow/light settings my computer struggles to get 30FPS on much smaller levels, so it was a lot of tweaking, but i am made visual sacrifices for useBlurExponentialShadowMap = true.  Obviously my levels look nowhere as realistic as yours :)  hopefully somebody with more experience on big levels can give you some pointers...

Link to comment
Share on other sites

I mainly use 3dsmax for my modeling and some AutoCAD as my background is in architecture. I baked all the materials into single texture atlas so each house and even the trees are using just 1 diffuse map 1 ambient and 1 bump if required. The scene only has a total of 81 materials. I guess on better rig the scene would probably fly, but at the moment the shadows is what matters the most to me. I appreciate the help a lot though honestly all tips help, if you ever need any help with graphics feel free to ask me anything.

Link to comment
Share on other sites

You have pretty big numbers :)

So here are some hints:

- Use instances as soon as possible. For trees, for houses

- 78 draw calls is a good number but...

- 12 millions is not a good one: You clearly need to simplify the scene

- Is light moving? If not, just bake the shadows in the ambient channel in 3ds max and turn off dynamic shadows. This is one this scene was done: https://www.babylonjs.com/demos/espilit 

Link to comment
Share on other sites

I will try and use LOD on the tree's and houses, I was trying to avoid more  3d modeling but I guess it can't be helped.

Most of my meshes are instances already there's just so many of them perhaps too many.

I can try baking the shadows too as the light is not a moving light. Don't really know how that will work for such a large scene, maybe if i break it into smaller pieces and use LOD as the camera moves around.

Thank you for all the help guys!

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.

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.


  • Recently Browsing   0 members

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