What does Faceforward formula mean?

The description of Faceforward on Blender’s manual page is:

Orients a vector A to point away from a surface B as defined by its normal C. Computes (Dot(B,C)<0)?A:-A

Could anyone please explain to me what Faceforward is about?

So we have a normal vector C which controls how steep the surface (or the plane) B is, and we have a vector A which points away from B.
-What does the part (B•C < 0)?A:-A mean?
-How can B•C if B is not a vector? I learnt that Dot Product can only be performed on 2 vectors.
-Why is there a question mark?
-What does “A:-A” mean? “A such that negative A”?

Any help is appreciated!

P/S: I don’t know about coding language.


Edit: The node confuses me.


If we have Vector input, why do we need Incident input? All vectors that are existing are supposed to be Incident vectors, aren’t they, at least that is what happens with other Vector Maths like Vector Rotation, Reflection, Refraction… So we have 2 incident vector inputs, to me it seems like the Vector input inputs all available vectors and the Incident input inputs only a specific vector. If this is the case, please explain to me why.

And what is Reference input? Is it the Normal vector input? Why is it named like that?

I don’t have any live examples, but I made this as an example

https://cdn.discordapp.com/attachments/950425974254731314/1043538939115487263/Example.blend

2 Likes

(Predicate)? T : F is the syntax for the “ternary conditional operator” commonly used in C-like programming languages. It means: if the Predicate is true, then T; if not, then F.

I do not know how the Faceforward node is used, but the wording from the manual is indeed confusing.

[…] pointing away from a surface B […]

Seems to mean that B is a vector representing a surface. It’s not uncommon to represent a surface by its normal vector, so ok. But…

[…] a surface B as defined by its normal C […]

C is the surface’s normal, so it’s not clear what B is.

Regardless of the wording, you should probably think of this node as a special kind of If-Else: you supply it with three independent vectors (Vector (A), Incident (B) and Reference (C)); if B and C point in generally opposite directions (that is, if their dot product is negative), return Vector (A); if that is not the case, return the opposite of Vector.

Seems oddly specific, but I’d wager this is a commonly used operation in renderers, so OpenGL provides a dedicated function for it, and thus so does Blender.

1 Like

Yeah, also my reasoning. Probably something common in raytracing or something because it seems rather arbitrary an operation

Hi! Thanks for your help!
I’ve asked on Reddit 24 hours ago and have only received one answer:

I agree that the documenting is bad. What do you think of what they say?
The helper told me to do tests, but I don’t even understand the plugins of the node, I asked about this problem in the second half of my post, could you please check it out?

Thank you!

Well, we know it’s not a typo in the manual, as the node does have three inputs. But the same thought crossed my mind when I first read the Blender documentation: "the formula makes sense if A=B", so (Dot(B,C)<0)?A:-A becomes (Dot(A,C)<0)?A:-A, which is a formula that gets two vectors and, if necessary, flips the first one to make sure they have opposite directions. Probably useful for light rays hitting surfaces, etc.

So why have A,B,C as separate inputs? Well, why not? It gives you more flexibility. If you want A=B, just input the same vector twice in the node and you’re good to go.

About the second half of your post, I’m not sure I understand it. If the question is about “how to use the node”, or “what do these inputs mean”, my advice is what I wrote in the previous post: ignore the input names, and think of it as a very particular kind of conditional (If-Else) node.

1 Like

We can think about a plane which goes perpendicular to “Reference” input.
If “Incident” points behind that plane, “Vector” gets inverted.

1 Like

Hi! I’ve tested both functions:
(Dot(A,C)<0) ? A : -A
(Dot(B,C)<0) ? A : -A
and their outputs match Blender’s outputs.
I’ve understood how this function works on a very basic level (how it inputs and outputs things…). But I’m really struggling to understand the Mathematical theory aspects of it. I don’t know if the developers really tried to make the function comprehensible. Because once I consider the description/definition of it, I find a lot of conflicting information and it raises me a lot of questions (any programmer/developer reading this, please help):

  1. What’s the purpose of making the names of the inputs in Blender’s node different from the names of the inputs in the document?
  2. Does B literally act as “incident vector” (according to what’s written on the node) or as “a surface” (according to the document)?
  3. It seems like “surface B” is represented by a vector in the node, that means a vector can represent a surface? Is this even Mathematically correct?
    I know that a surface’s orientation can be controlled by a normal vector (because Vector Reflection and Vector Refraction works this way), but what even is going on here? B is defined as a surface (in the document), but the input of the node is vector (in the node).
  4. What does the word “reference” (in the node) mean in this context? Why not just simply use the word “normal”?
  5. Assuming B does act as surface according to the document, what controls the orientation of the surface then? Surface B or normal vector C?
  6. Why performing Dot Product on a surface and a vector (i.e. B•C)? I don’t think this makes sense Mathematically.
  7. “Orients a vector A to point away from a surface B as defined by its normal C” - Is the function’s job really just to make A points away from the surface? Because it does make vector A points into the surface too.
    (Dot(B,C)<0) ? A : -A means:
    – If B points inwards (i.e. B•C < 0), keep A that way (even if A pointed inwards or outwards, doesn’t care, keep it that way).
    – If B points outwards (i.e. B•C > 0), flip A (if A pointed inwards, flip it to point outwards and vice versa).
    So does Faceforward’s job really to only make A points outwards?

Thank you! Very helpful. Great visualizer.

1 Like