Facing Ratio Linear attribute

Facing Ratio Linear attribute

PuChiNgBaLLz
Advocate Advocate
937 Views
3 Replies
Message 1 of 4

Facing Ratio Linear attribute

PuChiNgBaLLz
Advocate
Advocate

Hello there, could someone explain a little bit better the definition of linear in Facing ratio shader?

this is what appears in the arnold user guide

Linear

When enabled, the facing_ratio shader will output a linear, normalized angle instead of N·Eye.

 

i assume that when disabled each normal is multplied by the angle to the camera, but does it mean when enabled that the angle is linear and normalized? anywhere to find a deeper description of the maths?

0 Likes
Accepted solutions (1)
938 Views
3 Replies
Replies (3)
Message 2 of 4

maxtarpini
Collaborator
Collaborator

A dot product is not linear because it represents a cosine function. Visually, the scalar magnitude of the dot product increases non-linearly as the surface normal aligns with the view direction. If the result is linearized, the increase in magnitude will become uniform with respect to the angle between the vectors.

0 Likes
Message 3 of 4

maxtarpini
Collaborator
Collaborator
Accepted solution

Just to confuse you even more ;).. see the red dots ?.. they're the projection of the blue dots over the diameter .. now the blue dots have a constant step distance over the circumference (and so the angles they form are all the same).. but once projected, the distance between the red dots is not linear.. meaning.. for an angular constant increase there's no constant increase in its projected magnitude. Guess what's the pink line?.. it's the cosine of the angle.


Think of the red dots as a 1-0 (white-to-black) gradient.. it starts (from the center) and remain white for a while then it abrutly fall to black.

That's the gradient you see in the doc when linear is disabled.


Now if you wanna a constant gradient, all the red dots should be equally spaced. So you'll have a linear gradient from white to black. Of course then the angles won't be anymore all the same.

 

To understand the docs you need to read them in this way .. they say, facing ratio outputs an angle.. well it outputs the magnitude between surface normal and view direction. When the magnitude (the output gradient) is linear, - the angles are not; when the magnitude is 'cosine', - the angles are linear.circle_proj_cos.jpg

🖖

 

P.S:: (this is a bit OT, maybe for those advanced or just interested).. the last sentence above that's the reason we use 'costheta' and not the angle directly while integrating phase fncs for example.. because with costheta we uniformly sample the (hemi)spherical domain while if we'd use the angle directly we would not.

Message 4 of 4

maxtarpini
Collaborator
Collaborator

That's the underlying theory 😋

Of course you can linearize the cosine output by simply 'un-wrapping' it ..
ie. if we do this: c = cos(t) .. then, t = acos(c)

However a cosine has 0,PI (half circumference) range, ie. from 1 to -1 (diameter with red dots).

And because we wanna the result normalized in 0-1 (radius.. from circum to center), we take it as:

c = cos(t*(PI/2)) for t in 0-1,

so to normalize the linearization, we'll divide it by PI/2 : acos(c) /(PI/2)
Eventually we simply need to invert it to be in 1-0 and we have our linear similarity :

1-(acos(c) /(PI/2))

 

Coolest thing on earth ;).. is that you can check this on the fly with romboMathParser, a free shader I posted here on this forums.

fcklinearcosine.png

Just don't forget to reverse the view direction and that to truly see the linear gradient, you need to use Linear-Raw as view transform (ie. output is untouched).
Eventually it's not 'perceptually linear'.. so you just figure out is linear comparing it to the cosine counterpart.

🖖

0 Likes