Hello,
does anyone know of a method for applying a function or if-statement component-wise in HLSL (prefered; bonus points if it also/or works in GLSL)?
My example is a function that should allow me to modulate the color of game-sprites, by making them completely white (1.0f), completely black (-1.0f) and lerping everything in between.
float targetValue;
float alpha;
if (target > 0.0f)
{
targetValue = 1.0f;
alpha = target;
}
else
{
targetValue = 0.0f;
alpha = -target;
}
return lerp(value, targetValue, alpha);
That is the base function for a single value, and now I want to have this applied to all components of a float2-4. I know that intrinsic functions can be somehow declared scalar/vector, and I know that I could just write functions that overload on input of float2-float4, but I wanted to see if there is a more advanced solution. Maybe some way of applying the if-check per component or so.
Any ideas?