# Submesh's 'indexCount' does not updating with shader material

**URL:** <https://forum.babylonjs.com/t/submeshs-indexcount-does-not-updating-with-shader-material/40612>\
**Category:** Questions\
**Tags:** webgl\
**Created:** [May 9, 2023, 4:23am UTC](https://forum.babylonjs.com/t/submeshs-indexcount-does-not-updating-with-shader-material/40612 "2023-05-09T04:23:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![giraphics](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/giraphics/32/22151_2.png) [@giraphics](https://forum.babylonjs.com/u/giraphics)\
**Post date:** [May 9, 2023, 4:23am UTC](https://forum.babylonjs.com/t/submeshs-indexcount-does-not-updating-with-shader-material/40612/1 "2023-05-09T04:23:56Z")

</div>

Hi Everyone,

I have a dynamic lidar point cloud implementation(WebGL) where point counts change per frame.

For this implementation:

- Point cloud is a simple custom mesh(using BABYLON.Mesh and BABYLON.VertexData). My geometry comprises vertex, color, and index buffers.
- I allocated N vertices and initialized them with a linear arrangement.
- I update N number of vertices per frame
- For drawing dynamic point cloud, I use [Submesh’s indexCount](https://github.com/BabylonJS/Babylon.js/blob/28257aef7dc94d4aee2af17a34dbb4cc4914902d/packages/dev/core/src/Meshes/subMesh.ts#L205) and set N vertices to control draw count dynamically.

This point cloud custom shape implementation has standard and shader materials.

- Standard material uses BABYLON.StandardMaterial’s `fillMode = BABYLON.Material.PointListDrawMode`
- Point cloud material uses BABYLON.ShaderMaterial `pointsCloud` set as `true`

The standard material point cloud shader works:-

- [Demo Link](https://drive.google.com/file/d/1oDTkzUrZy8ORtDWSDqsx8MXGgFa9owi-/view?usp=share_link)

But the shader material is not working at all. This is a BLOCKER for us.

- [Demo Link](https://drive.google.com/file/d/1I7so9fWr7YcviGcMVfHCfRpL0UXLDI-y/view?usp=share_link)

Here is a playground example: [Babylon.js Playground](https://playground.babylonjs.com/#13NK7G)

- You can use `useShader` variables to switch between two material types and observe the difference.
- For controlling dynamic draw count, use `dynamicCount` variable.

How can I update the index count dynamically on the shader material-based mesh? Kindly assist.

---

<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:** [May 9, 2023, 10:27am UTC](https://forum.babylonjs.com/t/submeshs-indexcount-does-not-updating-with-shader-material/40612/2 "2023-05-09T10:27:58Z")

</div>

When you set `material.pointsCloud = true`, the system sets `fillMode` to `PointFillMode`, assuming that the mesh to which you will apply the material is unindexed. If your mesh has indices, you must set `material.fillMode = BABYLON.Material.PointListDrawMode` yourself (as you did in the case of the standard material):

> **[Babylon.js Playground](https://playground.babylonjs.com/#13NK7G%231)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![giraphics](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/giraphics/32/22151_2.png) [@giraphics](https://forum.babylonjs.com/u/giraphics)\
**Post date:** [May 9, 2023, 1:20pm UTC](https://forum.babylonjs.com/t/submeshs-indexcount-does-not-updating-with-shader-material/40612/3 "2023-05-09T13:20:16Z")

</div>

Thanks, @Evgeni_Popov, for this quick help. It is interesting to know the PointFillMode logic behind the scene. Thanks again.
