ShaderMaterial fragmentShader help

Hi, everyone.

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

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?

Have a look at this post: Smooth transition between textures with GSAP - #6 by prisoner849

1 Like

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.

uniform int tSelected;


if(tSelected == 0) ...
1 Like