BitteWenden wrote:In my case I wanted to do something like in the given example code with using different values of the world position for an operation in each clause (at the end I want to get a world space texture). I tried to use two compare statements, but if the first value is true, there is no way to "avoid" running the second compare and then using the new (in this case wrong value). After these two statements I'm checking for that exact case and if it's true I'll use the first value instead of the second one. But I figured that there might be an easier way to accomplish it.
By the way great tool so far, it's one of the big things I am missing in Unity.
Hello,
As you may have read, conditional statements (if etc) are not ideal for shaders but there are ways to overcome this limitation. I took the liberty of preparing a simple sample that demonstrates how to achieve the effect that you are looking for. Depending on which values you need to manipulate, you might need to adjust it, or even opt for another method of comparison(threshold or range).
Sample shader -
DownloadFor demonstration purposes, I used several float nodes that can actually be set directly in the Compare parameters; no need to create them, simple input the necessary values.
As you can see from the image, I used a simple setup that uses 1 main input (X) to set the value of 2 lerp nodes. In the first check (x > 0.5), if false = 0, If true = 1; meaning that it will either show the color for < 0.5 condition or it will show the default (else) color. To make sure that we also compare it with < 0.1, we run a second check for x < 0.1, if it's true we show the blue color, if not, we show the default else red color.
I hope that makes sense, I would be happy to answer any questions that you might have. It's also important to keep in mind that you can pass on values to your shader, you could use external conditions via code. Be sure to check the "Highlighted Animation" sample for a specific example.
Looking forward to your feedback.
Thanks!