# Around custom shaders

**URL:** <https://forum.playcanvas.com/t/around-custom-shaders/14685>\
**Category:** Help & Support\
**Created:** [September 6, 2020, 12:27pm UTC](https://forum.playcanvas.com/t/around-custom-shaders/14685 "2020-09-06T12:27:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ayrin](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/ayrin/32/849_2.png) [@ayrin](https://forum.playcanvas.com/u/ayrin)\
**Post date:** [September 6, 2020, 12:27pm UTC](https://forum.playcanvas.com/t/around-custom-shaders/14685/1 "2020-09-06T12:27:04Z")

</div>

Hello, was messing around with the custom shaders tutorial, what i want to achieve is to assign textures based on heigh map. The tutorial make dissolve the texture assigning a value to the heigh, how can i change the invisible texture with another texture to achieve my goal?

---

<div class="post-metadata">

**Author:** ![Leonidas](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/leonidas/32/6495_2.png) [@Leonidas](https://forum.playcanvas.com/u/Leonidas)\
**Post date:** [September 6, 2020, 1:36pm UTC](https://forum.playcanvas.com/t/around-custom-shaders/14685/2 "2020-09-06T13:36:42Z")

</div>

Hi @ayrin,

Here is a great GLSL shader on how to do terrain texture splatting based on height. It’s for Three.js but you can easily adapt it to Playcanvas:

> <https://stackoverflow.com/questions/18880715/texture-splatting-with-three-js>

---

<div class="post-metadata">

**Author:** ![ayrin](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/ayrin/32/849_2.png) [@ayrin](https://forum.playcanvas.com/u/ayrin)\
**Post date:** [September 6, 2020, 2:16pm UTC](https://forum.playcanvas.com/t/around-custom-shaders/14685/3 "2020-09-06T14:16:59Z")

</div>

Not so easly @Leonidas i don’t get a thing of what i should change 😃

---

<div class="post-metadata">

**Author:** ![Leonidas](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/leonidas/32/6495_2.png) [@Leonidas](https://forum.playcanvas.com/u/Leonidas)\
**Post date:** [September 6, 2020, 3:34pm UTC](https://forum.playcanvas.com/t/around-custom-shaders/14685/4 "2020-09-06T15:34:06Z")

</div>

You will have to learn how to work with shaders in Playcanvas, to be able to do that, there isn’t a ready made solution (yet).

Check the examples projects here:

[https://developer.playcanvas.com/en/tutorials/?tags=shaders](https://developer.playcanvas.com/en/tutorials/?tags=shaders)

And here is how I’d use that three.js shader code in Playcanvas (override albedo and add a few new shader uniforms):

```javascript
uniform sampler2D texture_colorMap;
uniform float tile;
uniform sampler2D texture_channel0;
uniform sampler2D texture_channel1;
uniform sampler2D texture_channel2;
uniform sampler2D texture_channel3;
void getAlbedo() {
    vec4 colormap = texture2D(texture_colorMap, vUv0);
    vec3 texel0 = texture2D(texture_channel0, vUv0 * tile).rgb;
    vec3 texel1 = texture2D(texture_channel1, vUv0 * tile).rgb;
    vec3 texel2 = texture2D(texture_channel2, vUv0 * tile).rgb;
    vec3 texel3 = texture2D(texture_channel3, vUv0 * tile).rgb;
    dAlbedo = gammaCorrectInput(colormap.r * texel0 + colormap.g * texel1 + colormap.b * texel2 colormap.a * texel3);
}

```

---

<div class="post-metadata">

**Author:** ![ayrin](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/ayrin/32/849_2.png) [@ayrin](https://forum.playcanvas.com/u/ayrin)\
**Post date:** [September 8, 2020, 6:38am UTC](https://forum.playcanvas.com/t/around-custom-shaders/14685/5 "2020-09-08T06:38:07Z")

</div>

hi @Leonidas, in your example you use a colormap where for each color you assign a materilal, i guess i can do that too, but the three.js sample use the heightmap directly to change the material based on altitude. Anyway i can use your method too coz it’s not very expensive in terms of resources and time. I will show you the result. Thanks.
