Lab A06 GGX Lighting with GenAI

GGX Specular (F0 = 0.04, roughness = 0.1)

Blinn-Phong (beta = 1000, light colour = vec3(1.0))

The GGX Model

f(l,v)=D(h)F(l,h)G(l,v,h)4nlnvf\left(\mathnormal{l}, \mathnormal{v} \right)=\frac{ D(\mathnormal{h}) F\left(\mathnormal{l}, \mathnormal{h}\right) G\left(\mathnormal{l}, \mathnormal{v}, \mathnormal{h}\right) }{4\left|\mathnormal{n} \cdot \mathnormal{l}\right|\left|\mathnormal{n} \cdot \mathnormal{v}\right|}
D(h)=α2π[(nh)2(α21)+1]2D(\mathnormal{h})= \frac{\alpha ^ 2}{\pi [ (n \cdot h)^2 (\alpha ^2 - 1) + 1] ^2}

Fresnel

F(l,h)=F0+(1F0)(1(vh))5F0=(n1)2(n+1)2F(\mathnormal{l}, \mathnormal{h})=F_0+\left(1-F_0\right) *(1-(v \cdot h))^5 \quad F_0=\frac{(n-1)^2}{(n+1)^2}

Smith One-sided Masking-Shadowing G1

G1(nv)=21+1+α2tan2θv=2(nv)nv+α2+(1α2)(nv)2G_{1}(n \cdot v)= \frac{2}{1+\sqrt{1+\alpha^2 \tan ^2 \theta_v}} = \frac{2(n\cdot v)}{n \cdot v+\sqrt{\alpha^2+\left(1-\alpha^2\right)(n \cdot v)^2}}

Joint Masking-Shadowing G2

G2(n,l,v)=G1(nl)G1(nv)G_{2}(n, l, v)=G_{1}(n \cdot l) G_{1}(n \cdot v)

Task 6.1 Generate the vertex shader and fragment shader

Try to use GenAI tools to help generate the GGX fragment shader code.

You can use the same vertex shader from Blinn-Phong, the difference is in the fragment shader.

Task 6.2 Read the fragment shader functions

What kind of Normal Distribution Function and Smith masking-shadowing functions the source code is using ? They might be different from what is introduced the lecture.

Try to find correspondence between the variables in the code and in the GGX equation if your souce code is using functions similar to what has been introduced in the lecture.

Fresnel function

Normal distribution function (NDF)

Smith Masking-Shadowing function G1

Joint Smith Geometry Function G2(n,l,v)=G1(n,l)*G1(n,v)

The main GGX function

The GGX function calls NDF, FResnel, G2

Task 6.3 Try to understand the backbone of the code conceptablly

Task 6.4 Try to fit the code into your program and debug

Revise the Blinn-Phong fragment shader.

Try to replace the specular component with GGX. Setting F0 and roughness.

Create new GGX shader variables in main.cpp and use the GGX shader to render your models.

Improve your understanding of GGX with code fitting and debugging.

Task 6.5 Try to test different values of F0 and roughness

Task 6.6 Try to compare GGX rendering with Blinn-Phong

Last updated