YOUR ACCOUNT

Login or Register to post new topics or replies
Zep Palen
Posts: 47
Filters: 10
I have been playing with the IF Component to use as a color replacement Tool in a script and came about this funny situation.

The attached screenshot shows two almost identical setups. All are same colors and operation type. Except for the ELSE result. The ELSE result map is set to a none Alpha in TEST 1 and to a Alpha in TEST 2.

I am aware of that comparisment is done on a bitwise basis on the Source input maps and therefor values here is not just as using the RGB values to test with.
But that is not really the issue...

The issue is: IF (Source A < Source B = TRUE) in TEST 1 then it should also be in TEST 2 and because of that just return the THEN Result.

What am I missing here?

  Details E-Mail
ThreeDee
Lost in Space

Posts: 1672
Filters: 112
Certainly looks like a bug, IF component seems to use ELSE as the alpha source regardless of the operation.
  Details E-Mail
Zep Palen
Posts: 47
Filters: 10
Yes. Exactly what I thought. And in other operation modes it makes similar results.

It seems like the bug is only there if Alpha is set to other values than full opacity on the ELSE input map.
  Details E-Mail
Vladimir Golovin
Administrator
Posts: 3446
Filters: 55
Yes, the alpha handling looks buggy, especially given the fact that the help states that "All four channels, including the alpha channel, are processed this way.". We'll look into this.
  Details E-Mail
Vladimir Golovin
Administrator
Posts: 3446
Filters: 55
Actually, I just checked the alpha-channel separately, and everything seems to be in order. I'm attaching the test filter. Open it in the editor and go through all operations: everything seems to work as expected.

AlphaTest.ffxml
  Details E-Mail
Vladimir Golovin
Administrator
Posts: 3446
Filters: 55
Quote
What am I missing here?


Let's see:

Setup #1:
A.Alpha = 1.0
B.Alpha = 1.0
THEN.Alpha = 1.0
ELSE.Alpha = 1.0
OP = A.Alpha < B.Alpha = 1.0 < 1.0
Expected result = ELSE.Alpha = 1.0
Factual result = 1.0

Setup #2:
A.Alpha = 1.0
B.Alpha = 1.0
THEN.Alpha = 1.0
ELSE.Alpha = 0.0
OP = A.Alpha < B.Alpha = 1.0 < 1.0
Expected result = ELSE.Alpha = 0.0
Factual result = 0.0

Your picture shows the same results, for both cases.

Perhaps you're missing the fact that the return of 1.0 < 1.0 is not true, it's false, and this holds for both cases, so the ELSE.Alpha is going to the output in both cases. When you change it from 1.0 to 0.0, the output just changes accordingly.
  Details E-Mail
Zep Palen
Posts: 47
Filters: 10
My point is that the IF component gets 2 different results of the same math.

it is like saying that 2 +2 = 4 only returns true sometimes.


in the following code sample the code should always goto label a. Never to label b. And that is what my example is about.

var q = white

IF (2+2=4) then
label a
ELSE
label b
END
  Details E-Mail
Vladimir Golovin
Administrator
Posts: 3446
Filters: 55
Quote
Certainly looks like a bug, IF component seems to use ELSE as the alpha source regardless of the operation.


Which is expected, because the operation and both its operands (A.Alpha = 1.0
and B.Alpha = 1.0) are the same in both examples -- why should the execution branch be different? The only difference is ELSE.Alpha: 1.0 in the first example and 0.0 in the second one.
  Details E-Mail
Vladimir Golovin
Administrator
Posts: 3446
Filters: 55
Zep, the correct pseudocode for your examples is this:

Code
function iffy(truth, falsehood)
  if (2+2=5) then
    return truth
  else
    return falsehood
end function

// now let's call the function a couple of times

// this call will return 1.0 because
// the value for falsehood is 1.0
example_1 = iffy(1.0, 1.0)

// this call will return 0.0 because
// the value for falsehood is now 0.0
example_2 = iffy(1.0, 0.0)


Edit: corrected an obvious error.
  Details E-Mail
Zep Palen
Posts: 47
Filters: 10
It still doesn't make sense to me. At least not the way the component and its input parameters are named.

The way I see your explaination is that I should read it something like:

function iffy(THEN, ELSE)
if (SourceA<SourceB) then
return truth
else
return falsehood
end function

If that is the case the component and its parameters namings are "slightly" misleading smile:)

It is kind of turning IF...THEN....ELSE upside Down.
  Details E-Mail
Vladimir Golovin
Administrator
Posts: 3446
Filters: 55
I'd rather say

Code
function iffy(SourceA, Operation, SourceB, Truth, Falsehood)
  if (SourceA Operation SourceB) then
    return Truth
  else
    return Falsehood
end function


(you can't use THEN and ELSE as argument names, they are reserved keywords.)

Quote
If that is the case the component and its parameters namings are "slightly" misleading


What naming and parametrization would you suggest?
  Details E-Mail
Zep Palen
Posts: 47
Filters: 10
Quote
(you can't use THEN and ELSE as argument names, they are reserved keywords.)


I am aware of that.

I was just showing that you would enter the values fr om your "THEN" and "ELSE" inputs there.

Quote
What naming and parametrization would you suggest?


I have no idea because I don't think I understand the purpose of the component.
It just doesn't make sense with the visual design as IF..THEN..ELSE


I would also expect this component to output only what is in THEN or ELSE, but I can reproduce situations where it outputs the Sources instead.
It seems extremely illogical.
  Details E-Mail
Zep Palen
Posts: 47
Filters: 10
Here it outputs Source B - RED where I would expect it to output either WHITE or BLACK.

As I said it might not be the purpose of the component, but I think most would expect it do either output what is input in THEN or ELSE.

  Details E-Mail
Vladimir Golovin
Administrator
Posts: 3446
Filters: 55
Quote
but I can reproduce situations where it outputs the Sources instead.


Sources (or, more precisely, their RGBA channels) don't leak into the output. For example, if you use R and G channels in Sources, but only B and Alpha in THEN and ELSE, you'll never see any red or green in the output.

Quote
Here it outputs Source B - RED where I would expect it to output either WHITE or BLACK.


Did you read the help for the IF component?
http://filterforge.com/more/help/Comp...th/If.html

And this article?
http://filterforge.com/more/help/Misc...sWork.html

Pay attention to this part (emphasis mine):

Quote
most RGB Math components process their inputs on a channel-wise basis. That is, they accept RGB colors and perform their titular operation on all color channels separately.


Channel-wise. Not bit-wise, as you presumed in the original post. There are no bits in Filter Forge, because it doesn't make sense to handle double-precision floating point numbers as binary numbers.
  Details E-Mail
Zep Palen
Posts: 47
Filters: 10
I read the articles and help before creating this thread, but it still doesnt make sense.

But lets leave this by it. We will probably never agree on the interpretation of logics here anyway.
  Details E-Mail
Vladimir Golovin
Administrator
Posts: 3446
Filters: 55
OK. I'll just give you a hint on how to get the results you expect. In order to get TRUE and FALSE color to the output in their original form, you must convert both colors you want to compare to grayscale before feeding them into SourceA and SourceB. There are multiple methods of grayscaling (which in your case means different "color comparison functions"), but you can just go with the default settings of the Desaturate component. Here's an example:

Color Comparison.ffxml
  Details E-Mail
Skybase
2D/3D Generalist

Posts: 4025
Filters: 76
Quote
I read the articles and help before creating this thread, but it still doesnt make sense.


Umm... hi. Maybe this might be a bit helpful. I'm hoping I read what the problem was exactly, it's a bit hard following up on a conversation. So sorry if didn't contribute.

The screenshot shows what the if component would be doing for each channel. The blend node simply generates a color, where each color is broken into R, G, and B channels (example doesn't show alpha but the same thing happens). In this case the operation is A < B. For each channel, if A is < B then it'll output 1 (or white).

  Details E-Mail
Skybase
2D/3D Generalist

Posts: 4025
Filters: 76
Here's the example filter. Let me know if this helped explain something. If it didn't or I missed the point of it all... sorry smile:(

If - Channelwise.ffxml
  Details E-Mail
Zep Palen
Posts: 47
Filters: 10
Yes I already figured out how it Works and also see that it can probably not Work different with channel wise processing. It is just not the way most would expect it to Work.

Especielle the outputs can be confusing because many will see this as a bug since they (and I) will not think about that the output can be a pixel put together from rgba values from both THEN and ELSE.

I DO see the logic in that now after reproducing this component with a LUA script)

Maybe there should be an option on the component to compare on color integer values per pixel rather than channelwise.
  Details E-Mail
Vladimir Golovin
Administrator
Posts: 3446
Filters: 55
Zep, I'm glad to hear that you've figured this out. Plus now we have a thread that can serve as a definitive guide for dispelling any IF-related confusion.

Quote
Maybe there should be an option on the component to compare on color integer values per pixel rather than channelwise.


You're probably talking about comparing colors as-a-whole, not channelwise. The thing is, there are multiple methods of converting three RGB channels into a single value for comparison, plus you have to factor in the alpha channel somehow. The problem is that this may be confusing, and on the plus side you are free to implement your own 'color value function'.

Anyway, here's my version of simplified IF that implements non-channelwise comparison, which is based on my example above, packaged into a group:

Simple IF.ffxml
  Details E-Mail
Zep Palen
Posts: 47
Filters: 10
Thank you.

Quote
You're probably talking about comparing colors as-a-whole, not channelwise


Yes I mean color values. Not ARGB values.

I made a LUA script for this.

The Alpha should not be an issue. Add it as the most significant value and then thats it. In addition just make an option to disregard Alpha values in the sources and it Works.

This leads to a wish of some features added to a future version of FF like creating enum input controls.
  Details E-Mail

Join Our Community!

Filter Forge has a thriving, vibrant, knowledgeable user community. Feel free to join us and have fun!

33,711 Registered Users
+18 new in 30 days!

153,531 Posts
+39 new in 30 days!

15,347 Topics
+72 new in year!

Create an Account

Online Users Last minute:

17 unregistered users.