# Shader, multiview: viewProjectionR is missing to declare but used

**URL:** <https://forum.babylonjs.com/t/shader-multiview-viewprojectionr-is-missing-to-declare-but-used/54302>\
**Category:** Questions\
**Created:** [October 23, 2024, 8:45am UTC](https://forum.babylonjs.com/t/shader-multiview-viewprojectionr-is-missing-to-declare-but-used/54302 "2024-10-23T08:45:04Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![yorkie](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/yorkie/32/35417_2.png) [@yorkie](https://forum.babylonjs.com/u/yorkie)\
**Post date:** [October 23, 2024, 8:45am UTC](https://forum.babylonjs.com/t/shader-multiview-viewprojectionr-is-missing-to-declare-but-used/54302/1 "2024-10-23T08:45:04Z")

</div>

See [Babylon.js/packages/dev/core/src/Shaders/ShadersInclude/pbrVertexDeclaration.fx at master · BabylonJS/Babylon.js · GitHub](https://github.com/BabylonJS/Babylon.js/blob/master/packages/dev/core/src/Shaders/ShadersInclude/pbrVertexDeclaration.fx#L2).

No `viewProjectionR` is declared, but used here: [Babylon.js/packages/dev/core/src/Shaders/pbr.vertex.fx at master · BabylonJS/Babylon.js · GitHub](https://github.com/BabylonJS/Babylon.js/blob/master/packages/dev/core/src/Shaders/pbr.vertex.fx#L183).

To fix this issue in `pbrVertexDeclaration.fx`:

```glsl
#ifdef MULTIVIEW
uniform mat4 viewProjectionR;
#endif

```

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [October 23, 2024, 3:22pm UTC](https://forum.babylonjs.com/t/shader-multiview-viewprojectionr-is-missing-to-declare-but-used/54302/2 "2024-10-23T15:22:04Z")

</div>

It is actually declared here:  
[Babylon.js/packages/dev/core/src/Shaders/ShadersInclude/sceneFragmentDeclaration.fx at master · BabylonJS/Babylon.js](https://github.com/BabylonJS/Babylon.js/blob/master/packages/dev/core/src/Shaders/ShadersInclude/sceneFragmentDeclaration.fx)  
or here if UBO:  
[Babylon.js/packages/dev/core/src/Shaders/ShadersInclude/sceneUboDeclaration.fx at master · BabylonJS/Babylon.js](https://github.com/BabylonJS/Babylon.js/blob/master/packages/dev/core/src/Shaders/ShadersInclude/sceneUboDeclaration.fx)

And imported from there:  
[Babylon.js/packages/dev/core/src/Shaders/pbr.fragment.fx at master · BabylonJS/Babylon.js](https://github.com/BabylonJS/Babylon.js/blob/master/packages/dev/core/src/Shaders/pbr.fragment.fx#L26)

---

<div class="post-metadata">

**Author:** ![yorkie](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/yorkie/32/35417_2.png) [@yorkie](https://forum.babylonjs.com/u/yorkie)\
**Post date:** [October 24, 2024, 4:05am UTC](https://forum.babylonjs.com/t/shader-multiview-viewprojectionr-is-missing-to-declare-but-used/54302/3 "2024-10-24T04:05:19Z")

</div>

I think this matrix should be in vertex shader

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [October 24, 2024, 2:31pm UTC](https://forum.babylonjs.com/t/shader-multiview-viewprojectionr-is-missing-to-declare-but-used/54302/4 "2024-10-24T14:31:20Z")

</div>

It is ALSO there:  
[Babylon.js/packages/dev/core/src/Shaders/pbr.vertex.fx at master · BabylonJS/Babylon.js](https://github.com/BabylonJS/Babylon.js/blob/master/packages/dev/core/src/Shaders/pbr.vertex.fx#L3)

pointing to:  
[Babylon.js/packages/dev/core/src/Shaders/ShadersInclude/sceneVertexDeclaration.fx at master · BabylonJS/Babylon.js](https://github.com/BabylonJS/Babylon.js/blob/master/packages/dev/core/src/Shaders/ShadersInclude/sceneVertexDeclaration.fx)

---

<div class="post-metadata">

**Author:** ![yorkie](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/yorkie/32/35417_2.png) [@yorkie](https://forum.babylonjs.com/u/yorkie)\
**Post date:** [October 28, 2024, 3:46am UTC](https://forum.babylonjs.com/t/shader-multiview-viewprojectionr-is-missing-to-declare-but-used/54302/5 "2024-10-28T03:46:07Z")

</div>

> <https://github.com/BabylonJS/Babylon.js/blob/master/packages/dev/core/src/Engines/Processors/shaderProcessor.ts#L418-L422>

If the above is the correct lines to process the ` __decl__ ` include files, the `#include< __decl__ pbrVertex>` at the “pbr.vertex.fx” will point to “pbrVertexDeclaration.fx” instead of “sceneVertexDeclaration.fx”.

---

<div class="post-metadata">

**Author:** ![yorkie](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/yorkie/32/35417_2.png) [@yorkie](https://forum.babylonjs.com/u/yorkie)\
**Post date:** [October 28, 2024, 9:54am UTC](https://forum.babylonjs.com/t/shader-multiview-viewprojectionr-is-missing-to-declare-but-used/54302/6 "2024-10-28T09:54:00Z")

</div>

And this patch([core: fix missing viewProjectionR decl for multiview in shaders · M-CreativeLab/Babylon.js@3cf42f0 · GitHub](https://github.com/M-CreativeLab/Babylon.js/commit/3cf42f0ce5f31955aee52967b28d70e66eaa1518)) fixes the program linking problems in my device.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [October 28, 2024, 3:17pm UTC](https://forum.babylonjs.com/t/shader-multiview-viewprojectionr-is-missing-to-declare-but-used/54302/7 "2024-10-28T15:17:22Z")

</div>

ok maybe I do not understand the core problem 🙂  
can you share a repro that shows we have a problem?

So far I’m not aware of a bug so this may help me realize what is going on

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [October 28, 2024, 3:23pm UTC](https://forum.babylonjs.com/t/shader-multiview-viewprojectionr-is-missing-to-declare-but-used/54302/8 "2024-10-28T15:23:22Z")

</div>

> [@yorkie](#):
>
> pbrVertexDeclaration

Ok I dug more and you are TOTALLY right! something is missing. I would just need a repro case to add a test so we do not miss that again. Can you repro in the PG?

---

<div class="post-metadata">

**Author:** ![yorkie](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/yorkie/32/35417_2.png) [@yorkie](https://forum.babylonjs.com/u/yorkie)\
**Post date:** [October 29, 2024, 4:27am UTC](https://forum.babylonjs.com/t/shader-multiview-viewprojectionr-is-missing-to-declare-but-used/54302/9 "2024-10-29T04:27:44Z")

</div>

> [@Deltakosh](#):
>
> Ok I dug more and you are TOTALLY right! something is missing. I would just need a repro case to add a test so we do not miss that again. Can you repro in the PG?

Thanks for your reply and confirmation. However, reproducing this issue in the Playground (PG) is quite challenging due to the specific environment required. This issue occurs specifically in Web runtimes that have the WebGL `ovr_multiview2` extension and have Uniform Buffer Objects (UBOs) disabled (such as `engine.disableUniformBuffers = true`). Under these conditions, the `Effect` will use definitions like those in pbrVertexDeclaration, otherwise it will use sceneVertexDeclaration. That’s why Babylon.js works correctly in most browser environments.

I encountered this issue while developing a new WebXR runtime that renders one or more WebXR applications (including Babylon.js apps) and a host environment (like Unity or UE) simultaneously in the same scene, viewed through an XR headset or glasses. To address rendering latency in this scenario, I temporarily disabled WebGL UBOs and discovered this problem.

In addition to this issue, I found that `viewProjectionR` was also not set correctly in this environment, so I added another patch to resolve it: [core: update viewProjectionR for multiview rendering if uniform is un… · M-CreativeLab/Babylon.js@48cb6fe · GitHub](https://github.com/M-CreativeLab/Babylon.js/commit/48cb6fe731d994a12f49dfe2e219346d11598444)

If you’re open to it, I’d be happy to submit these 2 patches as separate Pull Requests to Babylon.js, but I would appreciate some guidance on how to add corresponding regression tests and others required 🙂

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [October 29, 2024, 3:14pm UTC](https://forum.babylonjs.com/t/shader-multiview-viewprojectionr-is-missing-to-declare-but-used/54302/10 "2024-10-29T15:14:42Z")

</div>

I actually did the first PR already 🙂  
[Fix missing matrix by deltakosh · Pull Request #15745 · BabylonJS/Babylon.js](https://github.com/BabylonJS/Babylon.js/pull/15745)

Please send the second one

For the regression test, you need to add a new PG here:  
[Babylon.js/packages/tools/tests/test/visualization/config.json at master · BabylonJS/Babylon.js](https://github.com/BabylonJS/Babylon.js/blob/master/packages/tools/tests/test/visualization/config.json)

And store the reference here:  
[Babylon.js/packages/tools/tests/test/visualization/ReferenceImages at master · BabylonJS/Babylon.js](https://github.com/BabylonJS/Babylon.js/tree/master/packages/tools/tests/test/visualization/ReferenceImages)

---

<div class="post-metadata">

**Author:** ![yorkie](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/yorkie/32/35417_2.png) [@yorkie](https://forum.babylonjs.com/u/yorkie)\
**Post date:** [October 29, 2024, 3:41pm UTC](https://forum.babylonjs.com/t/shader-multiview-viewprojectionr-is-missing-to-declare-but-used/54302/11 "2024-10-29T15:41:27Z")

</div>

Thank you, that’s great!

BTW, do you guide me how to enable multiview in PG?

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [October 29, 2024, 3:44pm UTC](https://forum.babylonjs.com/t/shader-multiview-viewprojectionr-is-missing-to-declare-but-used/54302/12 "2024-10-29T15:44:47Z")

</div>

Cc @RaananW for that part;)
