# ShaderMaterial fragmentShader help

**URL:** <https://discourse.threejs.org/t/shadermaterial-fragmentshader-help/31290>\
**Category:** Questions\
**Tags:** shaders, fragment-shader\
**Created:** [October 30, 2021, 4:05am UTC](https://discourse.threejs.org/t/shadermaterial-fragmentshader-help/31290 "2021-10-30T04:05:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MrMateo07](https://avatars.discourse-cdn.com/v4/letter/m/90db22/32.png) [@MrMateo07](https://discourse.threejs.org/u/MrMateo07)\
**Post date:** [October 30, 2021, 4:05am UTC](https://discourse.threejs.org/t/shadermaterial-fragmentshader-help/31290/1 "2021-10-30T04:05:08Z")

</div>

Hi, everyone.

I’m working on a custom shader, it interpolates between textures.  
This is the fragmentShader part I’m stucked.

```javascript
uniform float tSelected;
uniform sampler2D tBase;
uniform sampler2D tClasica;
uniform sampler2D tPlatino;
uniform sampler2D tDoble;

vec4 _tBase = texture2D(tBase, uv);

vec4 _tSelected;
// if(tSelected = 0) _tSelected = texture2D(tPlatino, uv);
// if(tSelected = 1) _tSelected = texture2D(tDoble, uv);
// if(tSelected = 2) _tSelected = texture2D(tClasica, uv);

```

**’tSelected’** is updated, and depending that value choses one between 3 textures.  
But this throws error.

Any help or guide here?

---

<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:** [October 30, 2021, 7:01pm UTC](https://discourse.threejs.org/t/shadermaterial-fragmentshader-help/31290/2 "2021-10-30T19:01:06Z")

</div>

Hi!  
Have a look at this post: [Smooth transition between textures with GSAP - #6 by prisoner849](https://discourse.threejs.org/t/smooth-transition-between-textures-with-gsap/24631/6)

---

<div class="post-metadata">

**Author:** ![repalash](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/repalash/32/18241_2.png) [@repalash](https://discourse.threejs.org/u/repalash)\
**Post date:** [October 31, 2021, 3:16pm UTC](https://discourse.threejs.org/t/shadermaterial-fragmentshader-help/31290/3 "2021-10-31T15:16:42Z")

</div>

You have to use `==` to check for equality in glsl.  
Also `tSelected` must be integer. Otherwise you’ll have to check for \< 0.5, \> 0.5 && \<1.5 and so on.

```javascript
uniform int tSelected;

...

if(tSelected == 0) ...

```
