2
$\begingroup$

This is the website I am learning from.

In the specular part of IBL this is the split sum approximation

enter image description here

Now the left part of the equation I have asked in This post and I have understood everything now this question is about the right part.

On simplifying the right part of the equation with the procedure shown in the website we get this

enter image description here

And on translating this to code we get this

enter image description here

I have so many questions about this code.

1)What is the V vector? How did they compute that

2)Why have they assumed N=(0,0,1)?

3)why is NDotL=max(L.z,0)? How did they simplifying a dot product to an min/max Operation same question I have for NDotH

4)G_Vis=GVDoth/(NDotHNDotL) why the division by (NDOTH*NDOTL)? that was nowhere in the equation.

5)what is vector L? it looks like they have reflected vector V about H to get this but why?

These are just some of the questions I have come up with so far but if there are any other important parts I should not know about A general explanation on how they derived this code would be appreciated

$\endgroup$
0
3
$\begingroup$

1)What is the V vector? How did they compute that

It's the vector toward the camera (view vector), i.e. direction of the reflected ray. The lookup table they're building is parameterized in terms of NdotV, so they are working backward from NdotV to obtain a corresponding V vector. For purposes of doing this integration it doesn't matter what N and V are exactly, just that they have the correct NdotV. So, just to make things concrete, they assume that $N = (0,0,1)$ and V is aligned with the positive x-axis (i.e. in the positive xz half-plane). Then you have $V = (\sin θ, 0, \cos θ)$ where θ is the angle from N to V (this is just the equation for a circular arc from z down to x). Now $N \cdot V = \cos θ$, so by a standard trig identity $\sin θ = \sqrt{1 - \cos^2 θ} = \sqrt{1 - (N \cdot V)^2}$.

2)Why have they assumed N=(0,0,1)?

This whole thing is a pre-integration of the BRDF alone, it doesn't depend on any scene or lighting environment. So it doesn't matter where the BRDF is or how it is oriented in space, only the relative orientation between the N, L, and V vectors is important. So just for the sake of convenience they have chosen to fix N = (0, 0, 1), let V vary only in the xz half-plane as mentioned above, and let L vary over the whole hemisphere. To put it another way, they have chosen to set the coordinate system to be aligned with N and V.

3)why is NDotL=max(L.z,0)? How did they simplifying a dot product to an min/max Operation same question I have for NDotH

Since N = (0, 0, 1), dotting N with any vector just takes the z component of that vector. $N \cdot L = 0L_x + 0L_y + 1L_z = L_z$. (This is why it's convenient to assume a coordinate system in which N = (0, 0, 1).) Taking the max with 0 clamps it to the upper hemisphere, otherwise the dot product would go negative if the vector happens to be pointing below the hemisphere. This clamp is a standard thing to do when dealing with opaque BRDFs to avoid accidentally getting unwanted negative values in your calculations— although it is not really necessary here since they check if (NdotL > 0.0) immediately afterward.

4)G_Vis=GVDoth/(NDotHNDotL) why the division by (NDOTH*NDOTL)? that was nowhere in the equation.

It is a standard part of the microfacet BRDF formulation: $$ f_r(p, w_i, w_o) = \frac{DFG}{4(\omega_o \cdot n)(\omega_i \cdot n)} $$ Note that $\omega_o = V$, and $\omega_i = L$, these are just different notations/names for the incoming and outgoing light vectors. However I think there is a typo in the code, the denominator should contain NdotV rather than NdotH. I am also not sure why there is a multiplication by VdotH in the numerator, or where the factor of 4 went, but perhaps they have accounted for it elsewhere. I would probably double-check the BRDF equations here against some other sources as I don't think it's entirely correct.

5)what is vector L? it looks like they have reflected vector V about H to get this but why?

As noted, L is the vector toward the incoming light. H is the "half-angle" vector exactly halfway between L and V, so reflecting V around H will give you L, or vice versa. The significance of H is that in microfacet BRDFs, it is the normal vector of those microfacets that are "active" for a given L and V. So, to importance-sample a BRDF, we sample a random normal vector from the NDF, and use that as H. Since H and V are specified, we then calculate L from those.

$\endgroup$
1
$\begingroup$

I recommend to ignore my post (however I consider papers that I've sent valueable) and read post of Nathan Reed, which is much better in explaining this problem!

I'm still a junior when it comes to computer graphics so you may want to take my opinion with a grain of salt:

To start with - I used to learn/implement stuff using website that you've sent (OpenGL) and I don't recommend that. After few months of learning I knew barely anything. Then I start reading original papers and implementing them on my own to better understand PBR, what N * G * F means in Cook-Torrance shading model and I got much better understanding of basics. I was recommend by many graphics programmers to avoid tutorial pages and straight read and implement papers. In case if you don't understand something in the paper you're reading, you found paper on subject that you don't understand and read about it.

1). As I said - avoid this site or use only to get interesting papers - here are original notes from [Karis2013] UE4 presentation - https://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf ; Please notice comment "/sin" "/cos" in listing at page 7 and usage of Pythagorean trigonometric identity. Maybe it's position on the hemishpere, I don't really want to dig in, I'm sorry. But I would recommend checking Epic Games repository on Github if you want to see how they're using it.

2.) In the same paper [Karis2013] there is listing at the page 4. and function ImportanceSampleGGX. It uses N to determine orientation of the world and returns either float3(0,0,1) or float3(1,0,0) based on N.z value.

3). $$N = (0, 0, 1)$$ $$L = (x, y, z)$$ $$ dot(N, L) = (0 * x, 0 * y, 1 * z) = (0, 0, z) = L.z$$

4). http://jcgt.org/published/0003/02/03/paper.pdf#page=30

http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html

https://www.microsoft.com/en-us/research/wp-content/uploads/1977/01/p192-blinn.pdf

These links might be helpful to understand BRDF better. Why there are strange division? I don't know, it's probably due to optimization, I don't know what NDF is being used. However, what happens here is you're multiplying D and G component, so you can do split multiplication with Fresnel. It doesn't matter how you write it. You can just create function NDF_GGX(...) and multiply it by G, add pdf and it'll work the same. You can take a look at modern UE4 code - https://github.com/EpicGames/UnrealEngine/blob/2bf1a5b83a7076a0fd275887b373f8ec9e99d431/Engine/Shaders/Private/AmbientCubemapComposite.usf#L255 to understand it better. That's why I'm saying to write your own code. I would say that [Karis2013] is omitting a lot of code and uses many optimizations without saying WHY.

5). It's just light direction. When you already calculated V and H, it is easy to get L by using reflection. Take a look at the picture here - https://en.wikipedia.org/wiki/Blinn%E2%80%93Phong_reflection_model#Description

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.