Issue with shadows when upgrading to 5

Hello all!

I’m trying to upgrade a Babylon 4 project to 5. It works out of the box for the most part, except for an issue with shadows not generating. I’m relatively new to shaders, so I was wondering if it might be obvious to one of you why this code works in 4.2.1 Babylon.js Playground but https://playground.babylonjs.com/#TWD7EG#1 does not load shadows in latest.

When upgrading to 5, I did have to change two includes because it seems there were some name changes. #include<shadowMapVertexDeclaration> to #include<shadowMapVertexExtraDeclaration> and #include<shadowMapFragmentDeclaration> to #include<shadowMapFragmentExtraDeclaration>.

Is there an upgrade guide for shaders that I may have missed as well?

Thank you!

edit: had wrong playgrounds linked

I have an error in console:
babylon.js:16 WebGL: INVALID_VALUE: uniformBlockBinding: invalid uniform block index

which is a webgl2 api , only used in code twice:

.Babylon.js/thinEngine.ts at 491d5db27d279bdbc73e7169290237a057894ee2 · BabylonJS/Babylon.js · GitHub

not touched for 7 months
.Babylon.js/engine.uniformBuffer.ts at 491d5db27d279bdbc73e7169290237a057894ee2 · BabylonJS/Babylon.js · GitHub

switching to the webgl1 engine fixes the issue for me.

1 Like

You’re right, I am seeing that as well. It seems like the shader doesn’t change between 4.2.1 and 5, though, so is there some new configuration I would need to use webgl2?

I’m seeing the same issue on this playground https://playground.babylonjs.com/#IJH4VG#2 linked from the docs Shadows | Babylon.js Documentation

Thats a good find, I think it may likely be considered a bug. Probably helpful to know, is your project using the NME?

Yes we are using NME. Thanks for your help on this!

I don’t have an answer for the problem, but I have a feeling it may be something related to the changes to the shader store, the new material plugin system, and changes to nme. I did a general search on the docs, maybe some of the examples that come up on the right side could be helpful .Search page | Babylon.js Documentation ,

especially this one is using an NME snippet with BABYLON.CascadedShadowGenerator and BABYLON.ShadowGenerator

.https://playground.babylonjs.com/#PNQRY1#80

here are the docs on the new material plugin. I don’t think its required to manually upgrade or anything, but probably just generally useful to read sometime. It’s kind of hard to find without knowing it’s there.

Actually that was super helpful! I added these declarations

#include<__decl__sceneVertex>
#include<__decl__meshVertex>

removed this one

uniform mat4 viewProjection;

and it seems to be working: https://playground.babylonjs.com/#TWD7EG#2

1 Like
3 Likes

haha thank you :joy:

Yes, for optimization sake we are now using the mesh/scene ubos in the shadow generator code. Note that in your case you also need to remove the declaration of world which is coming from the vertex include.

[EDIT] The sample in the doc will be fixed by:

1 Like

Is there any documentation on what code #include<__decl__sceneVertex> maps to and how Babylon maps it?

I don’t think so, it’s a bit of an advanced usage. I think there are some posts in this forum about the include / decl syntax.