_needNormals error with shadowGenerator

Hi,

BabylonsJS: 5.29 (lastest)
Compilation: OK (if I roll back the refreshRate modification)
Problem: _needNormals error if use REFRESHRATE_RENDER_ONEVERYFRAME

I have only one shadow, so I search and test on a simple playground until finding the solution.

“shadowGenerator.getShadowMap().refreshRate” from “REFRESHRATE_RENDER_ONCE” to “REFRESHRATE_RENDER_ONEVERYFRAME”

But when I do this changement in my global project code, I get the following error :

Uncaught TypeError: Cannot create property '_needNormals' on string '#define SM_FLOAT 1
#define SM_ESM 0
#define SM_DEPTHTEXTURE 0
#define SM_NORMALBIAS 0
#define SM_DIRECTIONINLIGHTDATA 1
#define SM_USEDISTANCE 0
#define SM_SOFTTRANSPARENTSHADOW 0
#define NUM_BONE_INFLUENCERS 0'
    at t.isReadyForSubMesh (supervisor-babylonjs.js:196517:1683252)
    at t.isReady (supervisor-babylonjs.js:196517:843950)
    at t.isReady (supervisor-babylonjs.js:196517:504727)
    at t._checkIsReady (supervisor-babylonjs.js:196517:507834)
    at supervisor-babylonjs.js:196517:508143

If I remove all “addShadowCaster()” and “receiveShadows” calls, the error disappears but no shadows.
If I roll back “shadowGenerator.getShadowMap().refreshRate” to “REFRESHRATE_RENDER_ONCE”, the error disappears but only one shadow.

Sadly, I can not create a playground link, because the project is too big and intra-linked.
So I don’t know how to detail more.

Hope someone will be able to help me and perhaps find a solution for others also.

Thank you in advance,
Best regards.

It’s going to be hard to help without a repro somewhere…

What happens if you don’t set refreshRate? REFRESHRATE_RENDER_ONEVERYFRAME is the default value so you can avoid setting it.

Hi,
refreshRate + REFRESHRATE_RENDER_ONCE = Everything works but only one shadow
refreshRate + REFRESHRATE_RENDER_ONEVERYFRAME = Crash with error: caught TypeError cannot create property _needNormals on string #define SM_FLOAT 1

When you say refreshRate + REFRESHRATE_RENDER_ONEVERYFRAME did you test by doing shadowGenerator.getShadowMap().refreshRate = REFRESHRATE_RENDER_ONEVERYFRAME explicitely in your code? My point was to test by removing this line altogether because refreshRate = REFRESHRATE_RENDER_ONEVERYFRAME is the default value. Setting it explicitely could be the problem because we are doing some special things when the user is assigning the refreshRate property. So I want to know if the problem comes from assigning this property or not.

1 Like

Hi back,

I am a developer, we can win a lot of time together, so do not lose time with basics questions =)

If you prefer to have full lines:

shadowGenerator.getShadowMap().refreshRate = BABYLON.RenderTargetTexture.REFRESHRATE_RENDER_ONCE;

Works, but only one shadow (normal due to REFRESHRATE_RENDER_ONCE limitation)

shadowGenerator.getShadowMap().refreshRate = BABYLON.RenderTargetTexture.REFRESHRATE_RENDER_ONEVERYFRAME;

Crash (Uncaught TypeError: Cannot create property ‘_needNormals’ on string '#define SM_FLOAT 1 […])

The shadowGenerator is called for all GLB loaded (the following code is for illustration):

BABYLON.SceneLoader.ImportMeshAsync('', rootUrl, filename, scene).then(function (result) {
    [...]
    shadowGenerator.addShadowCaster(result.meshes[0]);
    [...]
}
_needNormals error is directly linked to material, so I try to change the GLB loaded

I do not have a crash (with REFRESHRATE_RENDER_ONEVERYFRAME setting) if I use “cubeSphereMorph.glb” from “https://patrickryanms.github.io/BabylonJStextures/Demos/morphTarget/glb/” (as simple external GLB)

I simply think I have found an issue with BablyonJS and some GLB, because of the same part of the code work in PL with “cubeSphereMorph.glb”.

So it depends on GLB loaded, but I don’t know why and what to change in the GLB and/or settings in BabylonJS?

Best regards.

Just to be sure, can you test by commenting (removing) the line shadowGenerator.getShadowMap().refreshRate = ... in your code?

The mesh material in cubeSphereMorph.glb does not have any texture, so it may be why it works. Do you use scene.executeWhenReady as a way to start your scene? If not, can you try to use it?

One test you can also do is adding engine.getCaps().parallelShaderCompile = null; when the engine is created and see if that helps.

Hi,

The problem is found and also the solution is linked =)

In fact, a GLB has different 3D parts, but each 3D part can have only one material (standard, PBR, or other).

In our case, we have two materials on the same part, and BabylonJS can not understand it.

Hope it will help other people who can have the same complex issue.

Best regards.

1 Like

Glad you found the problem!

Do you mean you are using a multi material? That would be nice if we could reproduce the problem and maybe fix/improve Babylon.js to handle this case.

1 Like