- Home /
Question by
frogsbo · Aug 11, 2014 at 06:28 PM ·
shadersurfacesyntaxconditional
Surface Shader If Condition W = :( A == B ? V syntax
i found some strange syntax in a surface shader, but i can't find any documentation on what it is.
can't i just write if... else in a void surf()?
what is :(a==b ? syntax and where can i learn it?
float4 resultCol1 =
Alti >= _TopLimit ? tex2D(_TexTop, IN.uv_TexTop)
Comment
Answer by tanoshimi · Aug 11, 2014 at 06:35 PM
The syntax in your description doesn't match the syntax in your code snippet, but it sounds like you're describing a ternary operator.
ThankYou Tanoshimi. oh ok if elsif works in surface shader. if you are interested this is runs in surface shader too:
float4 resultCol1 =
// Above topLimit, 100% topTexture
Alti >= _TopLimit ? tex2D(_TexTop, IN.uv_TexTop)
// Below botLimit, 100% botTexture
: (Alti <= -_BotLimit ? tex2D(_TexBot, IN.uv_TexTop)
// Between sideLimit and -$$anonymous$$idLimit, 100% $$anonymous$$idTexture
: (Alti <= _$$anonymous$$idLimit && Alti >= -_$$anonymous$$idLimit ? tex2D(_Tex$$anonymous$$id, IN.uv_TexTop)
// Above 0 outside thresholds, blend between side and top
: (Alti > 0 ? lerp(tex2D(_TexTop, IN.uv_TexTop), tex2D(_Tex$$anonymous$$id, IN.uv_TexTop),
1 - ((Alti - _$$anonymous$$idLimit) / (_TopLimit - _$$anonymous$$idLimit)))
// Below 0, outside thresholds, blend between side and bot
: lerp(tex2D(_TexBot, IN.uv_TexTop), tex2D(_Tex$$anonymous$$id, IN.uv_TexTop),
1 - ((abs(Alti) - _$$anonymous$$idLimit) / (abs(_BotLimit) - _$$anonymous$$idLimit))))));