# Example how to update mesh vertexes every frame -- with or without shaders

**URL:** https://forum.castle-engine.io/t/example-how-to-update-mesh-vertexes-every-frame-with-or-without-shaders/1132
**Category:** News
**Created:** [March 29, 2024, 7:56pm UTC](https://forum.castle-engine.io/t/example-how-to-update-mesh-vertexes-every-frame-with-or-without-shaders/1132 "2024-03-29T19:56:58Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [March 29, 2024, 7:56pm UTC](https://forum.castle-engine.io/t/example-how-to-update-mesh-vertexes-every-frame-with-or-without-shaders/1132/1 "2024-03-29T19:56:58Z")

</div>

| [![Update mesh example](https://forum.castle-engine.io/uploads/default/original/2X/e/e3a7d36be3acaeb38279eb6d432e39974ff86321.png)](https://castle-engine.io/wp/wp-content/uploads/2024/03/screenshot-1.png "Update mesh example") |

We have a new example [examples/viewport\_and\_scenes/mesh\_update](https://github.com/castle-engine/castle-engine/tree/master/examples/viewport_and_scenes/mesh_update) that may be quite useful to many developers. It shows two approaches to update a mesh at runtime. This has a lot applications — e.g. you may want to animate / deform the mesh following some algorithm or allow for some user interactions or game events to change the mesh.

Quoting from the example README:

This example demonstrates how to dynamically (as often as possible, to reflect e.g. time passing by) update the mesh of a 3D object, while still being efficient. There are 2 approaches:

1. Call `TCoordinateNode.SetPoint` as often as you want, e.g. from view’s `Update` method.

In this example, every `TViewMain.Update` increases `Time` and then calls `TViewMain.UpdateCoordinateNode`. The `TViewMain.UpdateCoordinateNode` updates the coordinates of the 3D object, the `Time` affects the waves shape.

The point here is that `TCoordinateNode.SetPoint` is very efficient. It only updates the necessary rendering resource (VBO contents in OpenGL) and doesn’t do any unnecessary work (doesn’t rebuild anything, doesn’t recreate any resource from scratch).

2. Use shaders. You can use our [shader effects](https://castle-engine.io/compositing_shaders.php) to add a _vertex shader_ that changes the position of each vertex right when it’s supposed to be displayed.

I encourage you to experiment with this example and try to stress-test it. It should handle very large values of `GridWidth` and `GridHeight`.
