# Enable CPU/GPU animation switching on a CustomShader

**URL:** <https://forum.babylonjs.com/t/enable-cpu-gpu-animation-switching-on-a-customshader/13773>\
**Category:** Questions\
**Created:** [August 29, 2020, 4:24pm UTC](https://forum.babylonjs.com/t/enable-cpu-gpu-animation-switching-on-a-customshader/13773 "2020-08-29T16:24:15Z")\
**Posts on this page:** 7\
**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:** [August 29, 2020, 4:24pm UTC](https://forum.babylonjs.com/t/enable-cpu-gpu-animation-switching-on-a-customshader/13773/1 "2020-08-29T16:24:15Z")

</div>

This is kinda a extension of a prior conversation where @Evgeni_Popov helped me enable the ability to toggle this on Meshs using the Standard and PBR material. Seems like when the mesh uses a custom material though the fallback does not exists.

it looks like there is a “addCPUSkinningFallback” but Im not sure how to initiate fallback on a ShaderMat.

---

<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:** [August 29, 2020, 5:04pm UTC](https://forum.babylonjs.com/t/enable-cpu-gpu-animation-switching-on-a-customshader/13773/2 "2020-08-29T17:04:03Z")

</div>

It does work in my testings: maybe you can provide a PG so that we can have a look?

This functionality is orthogonal to materials, so it should work on the CPU/GPU whatever the material you use (with a shader material, you need to use the right #includes in the vertex shader to support skinned meshes).

---

<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:** [August 29, 2020, 10:44pm UTC](https://forum.babylonjs.com/t/enable-cpu-gpu-animation-switching-on-a-customshader/13773/3 "2020-08-29T22:44:10Z")

</div>

[https://playground.babylonjs.com/#BCU1XR#1532](https://playground.babylonjs.com/#BCU1XR#1532)

Then go into the inspector and toggle the the Mixaorig:skin ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/b/b6452e8a83cd3c968fcb07fecf980ba7fab6f557.png)

I get what you are saying now.  
Because the defines say Bone Influences 0 it skips the attributes I need. gotcha. took a second to sink in.

---

<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:** [August 30, 2020, 7:10am UTC](https://forum.babylonjs.com/t/enable-cpu-gpu-animation-switching-on-a-customshader/13773/4 "2020-08-30T07:10:33Z")

</div>

You should not add `'#define NUM_BONE_INFLUENCERS 4',` to the list of defines of the shader material, it will be automatically added as `'#define NUM_BONE_INFLUENCERS 4'` or `'#define NUM_BONE_INFLUENCERS 0'` depending on the `computeBonesUsingShaders` value.

---

<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:** [September 1, 2020, 2:05am UTC](https://forum.babylonjs.com/t/enable-cpu-gpu-animation-switching-on-a-customshader/13773/5 "2020-09-01T02:05:11Z")

</div>

What if I need to trick it?

---

<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:** [September 1, 2020, 8:48am UTC](https://forum.babylonjs.com/t/enable-cpu-gpu-animation-switching-on-a-customshader/13773/6 "2020-09-01T08:48:32Z")

</div>

How so? I don’t understand what you want to achieve.

To make your sample work in both CPU and GPU mode, you simply need to remove the `'#define NUM_BONE_INFLUENCERS 4'` line:

[https://playground.babylonjs.com/#BCU1XR#1536](https://playground.babylonjs.com/#BCU1XR#1536)

---

<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:** [September 1, 2020, 3:35pm UTC](https://forum.babylonjs.com/t/enable-cpu-gpu-animation-switching-on-a-customshader/13773/7 "2020-09-01T15:35:45Z")

</div>

Hmmmm… Im a goober I guess… my bad.
