# Use GPUComputationRenderer texture for dynamic InstancedMesh objects positions

**URL:** <https://discourse.threejs.org/t/use-gpucomputationrenderer-texture-for-dynamic-instancedmesh-objects-positions/37741>\
**Category:** Questions\
**Tags:** gpgpu\
**Created:** [May 3, 2022, 2:57am UTC](https://discourse.threejs.org/t/use-gpucomputationrenderer-texture-for-dynamic-instancedmesh-objects-positions/37741 "2022-05-03T02:57:42Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![prisoner849](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/prisoner849/32/535_2.png) [@prisoner849](https://discourse.threejs.org/u/prisoner849)\
**Post date:** [May 4, 2022, 9:59am UTC](https://discourse.threejs.org/t/use-gpucomputationrenderer-texture-for-dynamic-instancedmesh-objects-positions/37741/7 "2022-05-04T09:59:01Z")

</div>

Read the texture with heights in vertex shader and add that value to Y-component of translate values of `instanceMatrix`.

```nohighlight
    shader.vertexShader = `
      uniform sampler2D heightMap;
      attribute vec2 instUV;
      varying float vHeight;
      ${shader.vertexShader}
    `.replace(
      `#include <project_vertex>`,
      `
      vec4 mvPosition = vec4( transformed, 1.0 );
      #ifdef USE_INSTANCING
        mat4 im = instanceMatrix;
        float h = texture2D(heightMap, instUV).r; // read
        vHeight = h;
        im[3].y += h * 5.; // add
        mvPosition = im * mvPosition;
      #endif
      mvPosition = modelViewMatrix * mvPosition;
      gl_Position = projectionMatrix * mvPosition;
      `
    );

```

 ![изображение](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/6/c/6cb3f1bf4e5e79c88ffd835b9985311d6d60f77b.png)

**Demo: [https://codepen.io/prisoner849/full/zYRGBmK](https://codepen.io/prisoner849/full/zYRGBmK)**

PS It’s just an option, **not the ultimate solution**.

---

_[View the full topic](https://discourse.threejs.org/t/use-gpucomputationrenderer-texture-for-dynamic-instancedmesh-objects-positions/37741)._
