IF in shaders

Programmers and people with programming knowledge sit here
wazzcob
Posts: 24
Joined: Fri Feb 05, 2021 5:11 am

IF in shaders

Post 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?
User avatar
frunggle
Posts: 66
Joined: Mon Oct 05, 2020 9:46 am

Re: IF in shaders

Post 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:
User avatar
vadbor
Posts: 125
Joined: Mon Oct 05, 2020 9:43 am

Re: IF in shaders

Post 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.
wazzcob
Posts: 24
Joined: Fri Feb 05, 2021 5:11 am

Re: IF in shaders

Post by wazzcob »

Huh, good answers! But nothing useful, alas...
wazzcob
Posts: 24
Joined: Fri Feb 05, 2021 5:11 am

Re: IF in shaders

Post by wazzcob »

nevertheless, this question is still interesting to me... I want a more or less intelligible answer to it!
Post Reply