# How to render same texture multiple times with different positions on a material?

**URL:** <https://forum.playcanvas.com/t/how-to-render-same-texture-multiple-times-with-different-positions-on-a-material/28451>\
**Category:** Help & Support\
**Tags:** textures, materials, shaders\
**Created:** [November 18, 2022, 11:27am UTC](https://forum.playcanvas.com/t/how-to-render-same-texture-multiple-times-with-different-positions-on-a-material/28451 "2022-11-18T11:27:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ertugrul\_Cetin](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/ertugrul_cetin/32/23984_2.png) [@Ertugrul\_Cetin](https://forum.playcanvas.com/u/Ertugrul_Cetin)\
**Post date:** [November 18, 2022, 11:27am UTC](https://forum.playcanvas.com/t/how-to-render-same-texture-multiple-times-with-different-positions-on-a-material/28451/1 "2022-11-18T11:27:15Z")

</div>

Hi, after dealing with [How to render a texture only once on the material? - #8 by Ertugrul\_Cetin](https://forum.playcanvas.com/t/how-to-render-a-texture-only-once-on-the-material/28436/8) I got another issue.

I have two materials and blending these two. One is for the ground (terrain/map) and applied 3 ground textures on it. And the other one is showing some magic textures.

I’d like to render this magic texture multiple times on the material. For example, it will be rendered in the position [10, 10] for character #1, and the other magic texture will be rendered in the position [20, 20] for character #2.

diffuseMapOffset can’t help here because I need to render multiple times the same texture in different locations. diffuseMapOffset only helps if you need one texture, if I go with this path I need to create multiple materials for multiple textures so it’s not ideal IMHO.

So any suggestions would be great!

My current shader;

```javascript
uniform sampler2D texture_splat;
vec2 character_position;
vec2 my_cord;

void getAlbedo() {

    my_cord = $UV;

    vec4 texture = texture2DSRGB(texture_splat, $UV * vec2(8,8));

    dAlbedo = mix(dAlbedo, texture.rgb, texture.a);
}

```

Here is the image, the texture is only rendered once - location [0,0]

 ![Screen Shot 2022-11-18 at 13.47.34](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/3X/8/4/8439e3045a02e8800ee36efcf3e75c8bea4457ce.jpeg)

---

<div class="post-metadata">

**Author:** ![mvaligursky](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/mvaligursky/32/11681_2.png) [@mvaligursky](https://forum.playcanvas.com/u/mvaligursky)\
**Post date:** [November 18, 2022, 11:53am UTC](https://forum.playcanvas.com/t/how-to-render-same-texture-multiple-times-with-different-positions-on-a-material/28451/2 "2022-11-18T11:53:26Z")

</div>

One option is to use clustered spot lights with cookie texture, similar to  
[https://playcanvas.github.io/#/graphics/clustered-spot-shadows](https://playcanvas.github.io/#/graphics/clustered-spot-shadows)

If your terrain is just a flat plane, you could do this  
[https://playcanvas.github.io/#/graphics/mesh-decals](https://playcanvas.github.io/#/graphics/mesh-decals)

You could also clone the terrain many times, and use simple shader on it with emissive texture, and use texture transform to move your texture to where you need to.

---

<div class="post-metadata">

**Author:** ![mvaligursky](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/mvaligursky/32/11681_2.png) [@mvaligursky](https://forum.playcanvas.com/u/mvaligursky)\
**Post date:** [November 18, 2022, 11:55am UTC](https://forum.playcanvas.com/t/how-to-render-same-texture-multiple-times-with-different-positions-on-a-material/28451/3 "2022-11-18T11:55:10Z")

</div>

Or you could extend your current shader that projects a single texture, to accept lets say 5 positions, and project it 5 times.

---

<div class="post-metadata">

**Author:** ![Ertugrul\_Cetin](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/ertugrul_cetin/32/23984_2.png) [@Ertugrul\_Cetin](https://forum.playcanvas.com/u/Ertugrul_Cetin)\
**Post date:** [November 18, 2022, 12:04pm UTC](https://forum.playcanvas.com/t/how-to-render-same-texture-multiple-times-with-different-positions-on-a-material/28451/4 "2022-11-18T12:04:03Z")

</div>

> One option is to use clustered spot lights with cookie texture, similar to

I know this, but for performance reasons, I can’t use it. My terrain is not flat, I’m using heightmap - just shared this image for a simple example.

> Or you could extend your current shader that projects a single texture, to accept lets say 5 positions, and project it 5 times.

Could it be problematic (performance-wise) if I need to increase size 5 from to for example 70?

---

<div class="post-metadata">

**Author:** ![Ertugrul\_Cetin](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/ertugrul_cetin/32/23984_2.png) [@Ertugrul\_Cetin](https://forum.playcanvas.com/u/Ertugrul_Cetin)\
**Post date:** [November 18, 2022, 12:13pm UTC](https://forum.playcanvas.com/t/how-to-render-same-texture-multiple-times-with-different-positions-on-a-material/28451/5 "2022-11-18T12:13:51Z")

</div>

> [@Ertugrul\_Cetin](#):
>
> > Or you could extend your current shader that projects a single texture, to accept lets say 5 positions, and project it 5 times.

Due to my limited knowledge with shaders, I don’t know how - maybe you can point me some directions to achieve this?

---

<div class="post-metadata">

**Author:** ![mvaligursky](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/mvaligursky/32/11681_2.png) [@mvaligursky](https://forum.playcanvas.com/u/mvaligursky)\
**Post date:** [November 18, 2022, 12:18pm UTC](https://forum.playcanvas.com/t/how-to-render-same-texture-multiple-times-with-different-positions-on-a-material/28451/6 "2022-11-18T12:18:29Z")

</div>

> [@Ertugrul\_Cetin](#):
>
> Could it be problematic (performance-wise) if I need to increase size 5 from to for example 70?

yes, clustered lights would perform better in this case for sure

---

<div class="post-metadata">

**Author:** ![mvaligursky](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/mvaligursky/32/11681_2.png) [@mvaligursky](https://forum.playcanvas.com/u/mvaligursky)\
**Post date:** [November 18, 2022, 12:20pm UTC](https://forum.playcanvas.com/t/how-to-render-same-texture-multiple-times-with-different-positions-on-a-material/28451/7 "2022-11-18T12:20:42Z")

</div>

> [@Ertugrul\_Cetin](#):
>
> Due to my limited knowledge with shaders, I don’t know how - maybe you can point me some directions to achieve this?

you currently have a uniform for playerPosition. Have 5 of those uniforms.  
And clone the code you have to use that uniform.  
But this will be hard to extend to 70 … the cost would be crazy high.

If you need 70 or so, clustered lights sound like a great option.

The other way could be to have dynamic mesh for each projected image - it should only contain few triangles where needed, instead of whole terrain.

---

<div class="post-metadata">

**Author:** ![Ertugrul\_Cetin](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/ertugrul_cetin/32/23984_2.png) [@Ertugrul\_Cetin](https://forum.playcanvas.com/u/Ertugrul_Cetin)\
**Post date:** [November 18, 2022, 12:52pm UTC](https://forum.playcanvas.com/t/how-to-render-same-texture-multiple-times-with-different-positions-on-a-material/28451/8 "2022-11-18T12:52:51Z")

</div>

Thank you for the help, let me check those!
