Page 1 of 2

IF in shaders

Posted: Thu Jun 03, 2021 11:29 am
by wazzcob
Help with writing shader code like this:

Code: Select all

  fixed4 c;
  
  if (IN.worldPos.y < _Y2)
    c = _Color2;
  else if (IN.worldPos.y > _Y1)
    c = _Color1;
  else
  {
    c = lerp(_Color1, _Color2, (IN.worldPos.y - _Y1) / (_Y2 - _Y1));
  }
And yes, by the way, I've come across rumors that if-else constructs in shaders are not correct.

Is this really the case or am I wrong?

Re: IF in shaders

Posted: Thu Jun 03, 2021 11:44 am
by frunggle
wazzcob wrote: Thu Jun 03, 2021 11:29 am Help with writing shader code like this:

Code: Select all

  fixed4 c;
  
  if (IN.worldPos.y < _Y2)
    c = _Color2;
  else if (IN.worldPos.y > _Y1)
    c = _Color1;
  else
  {
    c = lerp(_Color1, _Color2, (IN.worldPos.y - _Y1) / (_Y2 - _Y1));
  }
And yes, by the way, I've come across rumors that if-else constructs in shaders are not correct.

Is this really the case or am I wrong?
Lol, programmer! Hey!

About what you write, I have no idea. However, I believe that for such a spelling they will certainly not go to jail :lol:

Re: IF in shaders

Posted: Thu Jun 03, 2021 12:03 pm
by vadbor
It is always nice to see new members on our forum, especially if they want to join this or that project. I hope your skills are useful to us.

Re: IF in shaders

Posted: Fri Jun 04, 2021 10:22 am
by wazzcob
Huh, good answers! But nothing useful, alas...

Re: IF in shaders

Posted: Sat Jun 12, 2021 8:19 am
by wazzcob
nevertheless, this question is still interesting to me... I want a more or less intelligible answer to it!