Skip to main content
GameDev.net gamedev.net
🔒 Locked

Theory of PBR lighting model[and maths too]

Started by Kaiyum Aug 13, 2016 at 11:42 AM 8 replies 4.5k views
Original Post
Kaiyum
Kaiyum

Hi,

I have been doing self study on many lighting models. I have been through a really tough time understanding PBR shaders. It looks like that I need some theory along with some maths. Consider my graduations out of anything near CS/CSE. I have got the book stated here.

But I am having tough time swallowing that book. I know some c++, and prominently I write on java/c#. But a language agnostic resource is a good candidate for me. I just want to know this "PBR thing", in detail enough to implement it, on my own environment.

Any light of respective theory and math, to understand the in-out of PBR would highly help me, anyone? :)

CG bear. Playstation Partner
Tangletail
Tangletail

The math in that book is physically based, which means some prior background in physics would be good. More specifically Rays and Optics. There's a few very specific take aways that you would need to understand this.

A. Light bounces are always equal to the incident angle of the normal.

C. Every surface is usually born of microfaucets, which are tiny mirrors.
B. Diffuse reflection is when a surface is so rough that light is often scattered about.

D. Specular reflection is normally what causes mirrors. That is to say that you can think of every object as a mirror, and that most objects in life are just really shitty mirrors. And objects with really good speculars are just smoother than the normal diffuse object.

Then for math background.

It's a mix of calculus and linear algebra that supplements most of the logic. And then in a few key areas it's a mixture of statistics, and probability.

Kaiyum
Kaiyum

I am familiar with these ideas, though they are high school physics topics, lets test my nostalgia :)

A. Applicable only for mirror like surface. For rough surface, the angle of incident and the angle of reflection will not be same, is it?

C. True that

B. True that

D. True that too!

For calculus I know how to differentiate and integrate. Differentiation is like trying to obtain a change of certain property with respect to another property. Differentiation of velocity with respect to time is called force(actually force * constant, F = ma). Integration is one kind of addition over certain property. Addition of bread slices over its length is the whole yammy bread cake. :D

The partial differential comes into the scene when a property changes depending upon many properties simultaneously. For example, a game's success depends upon art, gameplay programming, graphics programming, marketing, engine programming etc. X is dependent of Y and Z and T. Though I forgot how to obtain differentials, in this case. taking Y and Z constant and make T variable + taking Y and T constant and make Z variable......something like that.

I had a rough journey over probability too, the bayes theorem, combination and permutations, nPr, nCr.......

I sense the whole book is about generating rays at the camera, and shooting them towards the scene and letting them to propagate. And calculate the final pixel value when it hits back the camera. The idea is, we see things only when the light comes into our eyes? So the ray must come into our camera, camera is our eyes. Is this the scheme of the whole book?

Then I must say, it has near zero practical value to my field as I will have to implement it on GPU. I know how fragment-vertex shader works roughly. I also know how we can GPGPU things via direct compute. But to implement a lighting model I have to understand the model. Lambartian lighting model is easy, but this PBR is making my life hell :mellow:

The book describe the whole system in its weird language, not event c++, --- ramsey(can't remember the name). I do not want the codes. I just want the theory to be explained in a nice manner so that I can implement this on the engine of my choice, platform of my choice, graphics library of my choice.

CG bear. Playstation Partner
MJP
MJP

One thing to be aware of is that physically based rendering isn't just a single technique that you implement, despite what the marketing teams for engines and rendering packages might have you believe. PBR is more of a guiding principle than anything else: it's basically a methodology where you try to craft rendering techniques whose foundations are based in our knowledge of physics. This is in opposition to a lot of earlier work in computer graphics, where rendering techniques were created by roughly attempting to match the appearance of real-world materials.

If you really want to understand how PBR is applied to things like shading models, then there's a few core concepts that you'll want to understand. Most of them come from the field of optics, which deals with how visible light interacts with the world. Probably the most important concepts are reflection and refraction, which are sort-of the two low-level building blocks that combine to create a lot of the distinctive visual phenomena that we try to model in graphics. In addition, you'll want to make sure that you understand the concepts of radiance and irradiance since they come up frequently when talking about shading models. Real-Time Rendering 3rd edition has a good introduction to these topics, and Naty Hoffman (one of the authors of RTR 3rd edition) has covered some of the same material in his introductions for the Physically Based Shading Course at SIGGRAPH.

Understanding the above concepts will definitely require some math background, so you may need to brush up on that as well. You'll really want to understand at least basic trigonometry, linear algebra (primarily vector and matrix operations, dot products, cross products, and projections), and some calculus (you'll at least want to understand how a double integral over a sphere or hemisphere works, since those pop up frequently). You might want to try browsing Khan Academy if you feel you're a bit weak on any of these subjects, or perhaps MIT's OpenCourseware.

MJP
MJP

A. Applicable only for mirror like surface. For rough surface, the angle of incident and the angle of reflection will not be same, is it?


Right. In traditional microfacet theory, a "rough" surface is assumed to be made up of microscopic mirrors that point in different directions. The rougher the surface, the more likely that a given microfacet will not point in the same direction as the surface normal, which means that the reflections become "blurrier" since light does not reflect uniformly off the surface.

I sense the whole book is about generating rays at the camera, and shooting them towards the scene and letting them to propagate. And calculate the final pixel value when it hits back the camera. The idea is, we see things only when the light comes into our eyes? So the ray must come into our camera, camera is our eyes. Is this the scheme of the whole book?

Then I must say, it has near zero practical value to my field as I will have to implement it on GPU. I know how fragment-vertex shader works roughly. I also know how we can GPGPU things via direct compute. But to implement a lighting model I have to understand the model. Lambartian lighting model is easy, but this PBR is making my life hell :mellow:


Yes, that particular book is aimed at offline rendering and always uses ray-tracing techniques, primarily path tracing. In that regard it's probably not the best resource for someone looking to learn real-time rendering, although a lot of the concepts are still applicable (or might be in the future). If you're looking to get started right away with real-time techniques then Real-Time Rendering 3rd edition is probably a better choice, although it's a bit out of date at this point. It covers some of the same ground as the PBR book, but always does it from the perspective of rasterization and real-time performance constraints. If you do decide to switch books I would recommend coming back to the PBR book at some point once you have a better grasp of the basics: I think you'll find that learning the offline techniques can give you a more holistic understanding of the general problesm being solved, and can open your horizons a bit. Plus I think it's fun to do a bit of offline work every once in a while, where you don't have to worry about cramming all of your lighting into a few milliseconds. :)

The book describe the whole system in its weird language, not event c++, --- ramsey(can't remember the name). I do not want the codes. I just want the theory to be explained in a nice manner so that I can implement this on the engine of my choice, platform of my choice, graphics library of my choice.


It uses what's called "literate programming". The code is all C++, and the whole working project is all posted on GitHub. The literate programming language just lets them interleave the code with their text, and put little markers into the code that tell you how the code combines into a full program.

Tangletail
Tangletail

I am familiar with these ideas, though they are high school physics topics, lets test my nostalgia :)

A. Applicable only for mirror like surface. For rough surface, the angle of incident and the angle of reflection will not be same, is it?

It is actually, part of the laws of reflection :P. But due to visual reasons, we approximate micro-faucets. Which is why a probability distribution function is introduced. It represents the probability of running into a microfaucet along a given surface. So physically, the angle of reflection is always equal to the angle of incident across the representative normal. But we bend this rule to get a result that's more to life with limited data.

But yeah, that book is aligned for giving you concepts of physically based rendering for things like pixar's renderman. It won't help you to implement anything to the GPU.

To do that, you'd want to take a preexisting BRDF. I'm trying to use Pixar's BRDF, however I haven't optimized it well enough (not at all), so my frames are shit.

FreneticPonE
FreneticPonE

I am familiar with these ideas, though they are high school physics topics, lets test my nostalgia :)

A. Applicable only for mirror like surface. For rough surface, the angle of incident and the angle of reflection will not be same, is it?

It is actually, part of the laws of reflection :P. But due to visual reasons, we approximate micro-faucets. Which is why a probability distribution function is introduced. It represents the probability of running into a microfaucet along a given surface. So physically, the angle of reflection is always equal to the angle of incident across the representative normal. But we bend this rule to get a result that's more to life with limited data.

But yeah, that book is aligned for giving you concepts of physically based rendering for things like pixar's renderman. It won't help you to implement anything to the GPU.

To do that, you'd want to take a preexisting BRDF. I'm trying to use Pixar's BRDF, however I haven't optimized it well enough (not at all), so my frames are shit.

Well what both you an OP are probably looking for, at least for GPU stuff, is the Disney BRDF: https://disney-animation.s3.amazonaws.com/library/s2012_pbs_disney_brdf_notes_v2.pdf

Which most everyone seems to use a variation of now, plugin things like GGX/smith geometry term, other optimizations. In fact the above offers a lot of things most don't use, usually concentrating on the metalness/roughness. I've not seen a lot of the sheen/etc. stuff done. Besides you'd want to optimize that out to save registers/G-buffer space/etc. anyway.

This, specifically the UE4/Black Ops 2 stuff, offers a more GPU centric view of PBR: http://blog.selfshadow.com/publications/s2013-shading-course/

Kaiyum
Kaiyum

Thanks guys :) I have got the RTR book, I am so in love with it! :rolleyes: Onto the forth chapter, the book is so nice explaining the things in a nice manner! So far, its a good read. I will come back after I finish it shortly :P.

CG bear. Playstation Partner
Tangletail
Tangletail

I am familiar with these ideas, though they are high school physics topics, lets test my nostalgia :)

A. Applicable only for mirror like surface. For rough surface, the angle of incident and the angle of reflection will not be same, is it?

It is actually, part of the laws of reflection :P. But due to visual reasons, we approximate micro-faucets. Which is why a probability distribution function is introduced. It represents the probability of running into a microfaucet along a given surface. So physically, the angle of reflection is always equal to the angle of incident across the representative normal. But we bend this rule to get a result that's more to life with limited data.

But yeah, that book is aligned for giving you concepts of physically based rendering for things like pixar's renderman. It won't help you to implement anything to the GPU.

To do that, you'd want to take a preexisting BRDF. I'm trying to use Pixar's BRDF, however I haven't optimized it well enough (not at all), so my frames are shit.

Well what both you an OP are probably looking for, at least for GPU stuff, is the Disney BRDF: https://disney-animation.s3.amazonaws.com/library/s2012_pbs

_disney_brdf_notes_v2.pdf

Which most everyone seems to use a variation of now, plugin things like GGX/smith geometry term, other optimizations. In fact the above offers a lot of things most don't use, usually concentrating on the metalness/roughness. I've not seen a lot of the sheen/etc. stuff done. Besides you'd want to optimize that out to save registers/G-buffer space/etc. anyway.

This, specifically the UE4/Black Ops 2 stuff, offers a more GPU centric view of PBR: http://blog.selfshadow.com/publications/s2013-shading-course/

I am using disney's BRDF XD. I keep mistaking that Pixar isn't Disney anymore.

But I just never bothered to optimize the math for it, so it runs like a fat man in the olympics.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.