Additional boolean comparator and operator nodes

Started by bigben, May 23, 2007, 08:02:54 PM

Previous topic - Next topic

bigben

HB alluded to this before (http://forums.planetside.co.uk/index.php?topic=1537.msg15312#msg15312) but until then I hadn't tried anything that got too complicated using just the standard conditional function node. Just tossing the idea back up for discussion...

The conditional node works well but it gets a bit complicated when your condition requires comparing two or more sets of variables. To get it to work, you have to construct a network of if/then/else statements to perform multiple comparisons which can get pretty cluttered.  The conitional node could probably remain as it's quite tidy for single comparisons, but it would be nice if we had 3 additional boolean nodes:

  • Boolean operator
  • Boolean comparator
  • Boolean conditional

The first two would each have two inputs and a pulldown menu of the standard boolean operators/comparators, with output values of 1 or 0. The output could be used directly as a scalar or fed into the boolean conditional node which would expect an input of 1 or 0 for the IF and the standard inputs for the THEN and ELSE.

To avoid clutter in the node network they could be placed like this(?)

> Create Function
      > Boolean scalar
            > Conditional scalar
            > Boolean operator
            > Boolean comparator
            > Boolean conditional scalar

jo

Hi Ben,

I wrote the conditional scalar node. Sorry if I'm being dense, but I don't really understand what you're getting at. Can you please give me an example of a network of conditional statements you think can be replaced by one of your boolean nodes?

You can do boolean ANDs and ORs with the conditional node, and get it to output 1 and 0 as you want. Hmm, switch the output values around and you can get a NAND and NOR operator as well.

Anyway, I suppose if you really want to be doing things with 1 and 0 then the input needs to be reduced to 1 or 0 as well. Is that the basis of your problem, that you need to use other nodes of reduce the input to 1 or 0?

Regards,

Jo

mogn

Its easy to make a bolean without using the conditional shader:

e.g replace "if x>0 then 1 else 0"  (3 nodes) with

clamp01(x*10000000)  (3 nodes)

bigben

#3
Hi Jo

Played a bit more and it's not as bad as my first impression but it might still be simplified. (I tend to post a wee bit too early sometimes ;) )
Attached is a basic clip file. To get a boolean output you have to specify 1 and 0 as the output results for each node even thought these values are implied. If you have several nested comparisons this starts getting messy and each time you add a conditional node you have to also specify the two results. 

In those situations where you have several comparisons producing the final result it would be easier just to have an input for each value to compare, with an implied output of 1 or 0 for true or false.   You could probably combine all of the boolean functions so it would just be one additional node I guess, and it wouldn't be too much of a stretch to use an existing conditional node with if Input = 1....   as the final output.

I guess it partly stems from my programming in Filemaker Pro which uses 1/0 as both a result and input for boolean operations...  ;)  (for input it actually uses 1 and NOT 1, but 1/0 fits this)

As for an actual case... I'm looking at creating a mask for object populations based on camera position and fov that is more flexible than the image-based mask I came up with (http://forums.planetside.co.uk/index.php?topic=972.msg10345#msg10345). While someone may be able to find a simpler method, I'm looking at comparing 3 calculated angles, with checks for divide by zero errors for arctan, and quadrant checking to select the appropriate comparison between values.

To go with this I also have an algorithm for optimising the size and placement of a population to follow the camera through an animation (to minimise the time spent by the populator creating 0 objects) but as the population settings are not available as inputs I'll be managing these externally and importing the values from text files.

bigben

Nothing like a shower to clear the head  ;)  Possibly a simpler change to implement would be to set the IF and ELSE to 1 and 0 respectively (and independently of each other) if their inputs are empty. Sound reasonable?

jo

Hi Ben,

I tell you what I could do - I could add a Scalar to Boolean Scalar node which would just have one input and output that as 0 or 1 (if the input is greater than 0). I could also add a threshold value for the conversion, for example 0 if the value is less than 0.5, otherwise it's 1. I'm trying to think if that's similar to the behaviour of any existing nodes, Matt will have to remind me there.

Another handy boolean operator could be a simple NOT operator to change the "truth" ( I need a shower too ;-)) of the input.

I'm not sure I want to change the behaviour of the conditional node with empty inputs, which is currently to return 0 if there is no input value, and to return the input value if there is one but no value if there is no comparison value or if value.

Of course, a lot of the time you don't really want to have these sorts of 1 or 0 things going on because they create discontinuities which create sampling/aliasing problems and can look ugly if they are visible. It's better to use a smooth step, I think the various Mix nodes are smooth steps in disguise, so you get a smooth transition from one state to the other. The same actually goes for the conditional node. I was trying to come up with a conditional node with built in smoothing but it was twisting my brain too much at the time.

OTOH, this kind of stuff is very useful for things like turning other things on and off and all sorts of other stuff of a more "structural" nature.

BTW, I haven't checked out your clip file just yet but I will later on today.

Regards,

Jo

bigben

#6
Hi Jo

Quote from: jo on May 27, 2007, 10:35:22 PM
I'm not sure I want to change the behaviour of the conditional node with empty inputs, which is currently to return 0 if there is no input value, and to return the input value if there is one but no value if there is no comparison value or if value.


Attached a variation of the first clip.
[attachimg=#2]

In this case the inputs are false (3<2) and true (5>4) but with no inputs for the If result (remove the IF and ELSE results) the output is whatever the first input is, which in this case is 0 (False).

Quote from: jo on May 27, 2007, 10:35:22 PM
OTOH, this kind of stuff is very useful for things like turning other things on and off and all sorts of other stuff of a more "structural" nature.

This is exactly what I'm using it for. Whether it is sharp or soft is irrelevant because it's only being used to turn on or off other regions of a mask out of frame or masking other things like population density.

Gotta dash.... will review this comment later this afternoon

Thanks for the feedback.


jo

Hi Ben,

Quote from: bigben on May 27, 2007, 11:24:16 PM

Attached a variation of the first clip.
[attachimg=#2]

In this case the inputs are false (3<2) and true (5>4) but with no inputs for the If result (remove the IF and ELSE results) the output is whatever the first input is,

After checking out this, and your first clip, I think I see what you mean now. You would like to have a Boolean operator/conditional node which doesn't require you to supply/hook up the 1 and 0 constant nodes, is that right? So for the "5 greater than 4" node you would just have the input and the conditional value and it would output 1 or 0 depending on the comparison? I can certainly add a node which does that, I think it would pretty useful and help to make simpler (probably quicker too) networks when you want to do Boolean stuff.

BTW, I'm not sure if this is what you were getting at or not, but the behaviour you describe above is what I would expect to happen.

Regards,

Jo

bigben

Quote from: jo on May 28, 2007, 12:06:35 AM
Hi Ben,


After checking out this, and your first clip, I think I see what you mean now. You would like to have a Boolean operator/conditional node which doesn't require you to supply/hook up the 1 and 0 constant nodes, is that right?

That's exactly it.

Quote from: jo on May 28, 2007, 12:06:35 AM
Quote from: bigben on May 27, 2007, 11:24:16 PM
In this case the inputs are false (3<2) and true (5>4) but with no inputs for the If result (remove the IF and ELSE results) the output is whatever the first input is,
....

BTW, I'm not sure if this is what you were getting at or not, but the behaviour you describe above is what I would expect to happen.

Putting the two together to make sure we might be talking about the same thing. The problem I have with that example is that the output will vary depending on the first input if the result nodes are empty, but for an OR statement you should get the same result regardless of which is first (which you do if you provide result inputs)

Anyway, I know how to get what I need for now and will look forward to something simpler at a later date.

As it turns out the functional mask I was working on doesn't need too many conditional nodes... it's not working yet but that's another story for another forum (perhaps)

Thanks for considering the changes.

Ben

jo

Quote from: bigben on May 28, 2007, 04:14:39 AM
Quote from: jo on May 28, 2007, 12:06:35 AM
After checking out this, and your first clip, I think I see what you mean now. You would like to have a Boolean operator/conditional node which doesn't require you to supply/hook up the 1 and 0 constant nodes, is that right?

That's exactly it.

Excellent :-).

Quote
Putting the two together to make sure we might be talking about the same thing. The problem I have with that example is that the output will vary depending on the first input if the result nodes are empty, but for an OR statement you should get the same result regardless of which is first (which you do if you provide result inputs)

I see it as an error if there is not at the very least a comparison value and an If value. The Else value is optional. To me it doesn't make sense otherwise, and so that's how it works. To be consistent for all conditional operators I output the input value in that case, and I don't see why the OR operator should be any different. I should add all that to the documentation for the node - and a screenshot while I'm at it :-).

Regards,

Jo

bigben

Quote from: jo on May 28, 2007, 06:13:24 AM
I see it as an error if there is not at the very least a comparison value and an If value. The Else value is optional. To me it doesn't make sense otherwise, and so that's how it works. To be consistent for all conditional operators I output the input value in that case, and I don't see why the OR operator should be any different. I should add all that to the documentation for the node - and a screenshot while I'm at it :-).

It would definitely be an error, and something you hope wouldn't be attempted. I was just seeing what happened based on what you had said. You'd hope that an IF result would be the minimum used, but a note in the docs probably wouldn't hurt just in case ;)

bigben