BabylonJS / BabylonNative

Build cross-platform native applications with the power of the Babylon.js JavaScript framework
MIT License
753 stars 130 forks source link

Babylon Native getting different shadow shader code than appears on the Web #849

Closed syntheticmagus closed 1 year ago

syntheticmagus commented 2 years ago

For questions, please use the forum.

Describe the bug Under certain poorly-understood conditions, Babylon.js seems to be sending different shadow shader code to Native than it does to the browser.

From Spector.js: spectorjs

From ShaderCompilerD3D.cpp: vsdebugger

To Reproduce Replace the default light creation in experience.js with something like the following:

        scene.activeCamera.radius = 5;
        const light = new BABYLON.SpotLight("*spot00", new BABYLON.Vector3(2, 20, -10), new BABYLON.Vector3(0, -1, 0.3), 1.2, 24, scene);

        const shadowGenerator = new BABYLON.ShadowGenerator(128, light);
        shadowGenerator.getShadowMap().renderList.push(scene.meshes[0]);

        const ground = BABYLON.Mesh.CreateGround("Ground", 50, 50, 1, scene);
        ground.position.y = -0.4;

        ground.receiveShadows = true;

Compare with a similarly established Playground on the Web.

Expected behavior If different shader code is passed to Native versus the Web, I would expect that difference to be required to make the shadows work. As it stands, the shadows don't render, and it's unclear why the shader source is different.

CedricGuillemet commented 2 years ago

output is different: packing to 4 floats VS returning 1 float. This is generally the case when you don't have float texture support and pack a float to RGBA8. Looking at the caps in native engine, I think it's the case here: https://github.com/BabylonJS/Babylon.js/blob/c89dbd5ae3ccb3126aa03c84869fbdfa8b7f3e7b/src/Engines/nativeEngine.ts#L851

bghgary commented 2 years ago

We need to check if this still repros since we added float texture support.

CedricGuillemet commented 1 year ago

Some more flags are needed to get same shaders between web and native on my PC: https://github.com/BabylonJS/Babylon.js/blob/18d6cdcda0438711750b4a411e60af7906a4e050/packages/dev/core/src/Engines/nativeEngine.ts#L246 Once tweaked with same caps between web and native, I can see the same shader. Closing this issue: validation tests are testing shadow and this issue exists for the caps : https://github.com/BabylonJS/BabylonNative/issues/553