# SkeletonWeightShader

**URL:** <https://forum.babylonjs.com/t/skeletonweightshader/15245>\
**Category:** Bugs\
**Created:** [October 28, 2020, 5:40pm UTC](https://forum.babylonjs.com/t/skeletonweightshader/15245 "2020-10-28T17:40:36Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [October 28, 2020, 5:40pm UTC](https://forum.babylonjs.com/t/skeletonweightshader/15245/1 "2020-10-28T17:40:36Z")

</div>

Ok, I need help on the weight shader. Not really sure what the correct fix is.

I get an error when you try to display the mesh in CPU Animation mode and then turn on the Weight Shader and the BoneMap Shader it will drop this error:

![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/f/f7ea1ed8ad3d5dd13f0092f942fa78ad1f37213b.png)

I know, that I have fixed this in the past but cant for the life of me remember how and will have to go look up some of my other shaders to figure it out but do not have time right this second. Ill fix it as soon as I can but was just wondering what others would suggest as an easy fix.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [October 28, 2020, 9:28pm UTC](https://forum.babylonjs.com/t/skeletonweightshader/15245/2 "2020-10-28T21:28:41Z")

</div>

There’s probably a lot more information with the error than just this line?

That’s near impossible to find what’s going on with just this line.

One possible thing is that the shader is using a `matricesIndices` variable in the code, that has not been declared. Given the name of the variable, it would mean the attribute `matricesIndices` has not been declared in the vertex shader.

---

<div class="post-metadata">

**Author:** ![Drigax](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/drigax/32/16585_2.png) [@Drigax](https://forum.babylonjs.com/u/Drigax)\
**Post date:** [October 28, 2020, 9:31pm UTC](https://forum.babylonjs.com/t/skeletonweightshader/15245/3 "2020-10-28T21:31:24Z")

</div>

Sounds like the shader is missing the attribute input declaration?

might want to add something along the lines of `in vec4 matricesIndices` where you’re declaring the rest of your attributes?

Yeah what @Evgeni_Popov said

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [October 28, 2020, 9:44pm UTC](https://forum.babylonjs.com/t/skeletonweightshader/15245/4 "2020-10-28T21:44:17Z")

</div>

Was actually looking at my code of a shader that does the same think but works, the only thing I am missing is the specific attribute declaration to make sure that stuff is still there when it switches to CPU. I’ll test that when I get home and if I fixed it I’ll push.

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [October 29, 2020, 7:29pm UTC](https://forum.babylonjs.com/t/skeletonweightshader/15245/5 "2020-10-29T19:29:41Z")

</div>

Y’all can recreate it really easy, just go into a scene with a skeleton rigged to a mesh, go into the inspector and select the mesh toggle it to CPU mode then turn on the BoneWeights Shader.

I tried adding the attributes to the shader, but that did not seem to fix it… not sure why it works on the skeleton widget but not on this?

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [October 29, 2020, 9:59pm UTC](https://forum.babylonjs.com/t/skeletonweightshader/15245/6 "2020-10-29T21:59:33Z")

</div>

The `matricesIndices` and `matricesWeights` attributes are passed to the shader only when the bones are computed on the GPU (there’s no point to pass them otherwise).

So I guess the **Display BoneWeights** switch in the inspector should be disabled when **Compute bones using shader** is disabled.

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [October 30, 2020, 1:29am UTC](https://forum.babylonjs.com/t/skeletonweightshader/15245/7 "2020-10-30T01:29:37Z")

</div>

I have a use case that needs it, we are working on real time weight painting and need the CPU version to work. Ive gotten it to work with the skeleton widget where we were able to make it selectable even with animations, but for some reason these ones are not doing the same thing with the same attributes. I’m just wondering what I did differently.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [October 30, 2020, 1:50am UTC](https://forum.babylonjs.com/t/skeletonweightshader/15245/8 "2020-10-30T01:50:30Z")

</div>

Are you sure you were using CPU skinning? With the existing code I don’t see how it can work because in CPU mode the indices/weights attributes are not passed to the shader.

I have made a PR to make it work in CPU mode too:

> <https://github.com/BabylonJS/Babylon.js/pull/9311>

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [October 30, 2020, 4:21am UTC](https://forum.babylonjs.com/t/skeletonweightshader/15245/9 "2020-10-30T04:21:51Z")

</div>

yeah for sure, that was the only way we could get picking to work on the widget that was deformed by a skeleton.

---

<div class="post-metadata">

**Author:** ![Pryme8](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/pryme8/32/7212_2.png) [@Pryme8](https://forum.babylonjs.com/u/Pryme8)\
**Post date:** [October 30, 2020, 2:50pm UTC](https://forum.babylonjs.com/t/skeletonweightshader/15245/10 "2020-10-30T14:50:43Z")

</div>

I can confirm that fix works @Evgeni_Popov you are am amazingly masterful programmer.

---

<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 30, 2020, 5:18pm UTC](https://forum.babylonjs.com/t/skeletonweightshader/15245/11 "2020-10-30T17:18:18Z")

</div>

> [@Pryme8](#):
>
> you are am amazingly masterful programmer

Oh yes!
