Rendering blur shadow on demand

Hello guys,

it’s time to continue improving my babylon projects.

Since I want to improve the performance of my scene as much as I can without loosing quality I try to get rid of unnecessary computation. In a recent post I was tought to set the refreshRate of my shadowGenerator to 0. My plan is to change the value to 1 every time the scene is changing.

  1. Unfortunately it didn’t work but I found out that the reason was that I set useBlurExponentialShadowMap = true. Why am I not able to render the shadow only once if my shadow is blurred? Is there a more efficient way to create a blurry shadow?

  2. Besides that is it possible to render the shadow manually on demand? Right now my approach is to set the refreshRate = 0 and before my scene changes I set the refreshRate = 1. After that again to 0. it would be much more convenient to keep it on 0 and call refreshShadow directly after my scene changed.

  3. I try the same thing with autoUpdateExtends for my lights. It’s only necessary to update for the time my scene changes.

Thank you very much for your advise

Best

EDIT:

Okay, I don’t know what the problem was with blurred shadow but it works. My function looks like this:

export async function toggleLightUpdate(props) {
    props.lights.forEach(light => light.autoUpdateExtends = props.state)
}

export async function toggleShadowRender(props) {
    props.shadowGenerators.forEach(sg => {
        sg.getShadowMap().refreshRate = props.state ? 1 : 0
    })
}    

const updateLightAndShadow = async () => {
            await Promise.all([
                toggleLightUpdate({ state: true, lights: props.lights }),
                toggleShadowRender({ state: true, shadowGenerators: props.shadowGenerators })
            ])
            setTimeout(async () => {
                await Promise.all([
                    toggleLightUpdate({ state: false, lights: props.lights }),
                    toggleShadowRender({ state: false, shadowGenerators: props.shadowGenerators })
                ])
            }, 10)
        }

As you can see I wait 10ms until I set the values to its initial state. Is there a way to specify that in 1 render frame or something? Or what would be the best practice in general?

Lol ok :slight_smile:
As a general note, it is quite impossible to help with just a bit of your code. The general recommendation is to provide a repro in the Playground

For 1 a repro would be nice.

For 2 you can simply set refreshRate = 0 again when you want to regenerate the shadows: that will re-trigger a “render once”.

The problem from 1 is solved already. I don’t know why that happened but after some structural adjustments of the code it worked fine.

Thanks for the hint. Setting the refreshRate = 0 again is working :slight_smile: