OpenGL - PBR (physically based rendering)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
the idea of physically based rendering is that we want to model light in a way that's more realistic there is no authoritative definition of what counts as physically based rendering and what doesn't but the most essential criteria is that our lighting calculation which and physically based rendering will call the bi-directional reflectance distribution function this calculation should account first for energy conservation such that when light energy strikes a surface we don't reflect off that surface more light energy than what is coming in second we want to account for the micro facets of surfaces such that the light interacts differently for smooth surfaces versus rough surfaces thirdly we should account for how light interacts differently with metal versus non metal surfaces aka dielectric surfaces and fourthly we should account for the Finnell effect which is a phenomenon where light striking a surface at a shear angle more of that light is going to bounce off at the reflected angle rather than get absorbed if you look straight down and a wooden floor it's not gonna look super glossy but when the floor is that a shear angle to your eye then it'll look more glossy because more of the light is being reflected at the inverse angle so now if we look at the first PBR example lighting what you see here are bunch of spheres being lit by four lights the four lights in the scene are these small little balls just for reference that's showing you where they are and left to right the spheres are increasing in roughness it's the minimum roughness in the left column and the maximum on the right and bought in the top of the spheres are increasing in metalness the ones at the bottom are not metal at all and the ones at the top are full metal as you can see with increasing roughness the specular highlights get bigger but fainter metalness increases the intensity of the specular highlight a bit but more noticeable about the metalness is that they have less diffuse reflection so outside the specular highlight they're just getting darker they're not as intensely red because that's how metals behave the light energy that absorbs into the metal unlike with non metal materials tends not to escape before looking at the code there are a few key formulas we're going to employ the first is an approximation of the Finnell effect called like it takes in three parameters H is the bisecting vector between V and the vector to the light and then F sub zero we can call that the base reflectivity this is actually a vector II RGB values between 0 and 1 and for dielectric materials like say plastic glass and water these values are gonna be very low for water the RT B's are all point zero two but then for metals these valleys are much higher at the low end you have say iron which is 0.5 six point five to seven point five eight and then at the high end you have metals like silver which is 0.9 five point nine three and point eight eight putting F Sub Zero aside though what to H and V do in this formula well we get their dot product such that when they point in the same direction then get a value of one and as they diverge you get a value closer to zero well we invert that by subtracting from one and so this rightmost term here that's being raised to the power of five the larger H and V diverge the larger this value gets as for F sub zero let's consider first say water four which again the F sub zero value is point zero two point zero two point zero two well one minus a very small value gets us a value close to one in contrast for a metal like say silver where they are component is 0.95 well regardless of the H and V value the R component output of this formula is going to be 0.9 five plus a little something the larger the base reflectivity the bless H and V is going to matter so you could say that for dialectics like water and glass there's a stronger Finnell effect when we look down at our wood floor it's the nonmetallic surface and so it has a strong Finnell effect it doesn't look glassy straight down but it looks glossy side on anyway this gets us a value for for Nowell which effectively is going to determine for us how much of the energy striking a surface is reflecting in a specular fashion and when we take into account energy conservation it's only the remainder of the energy that can contribute to any diffuse reflections another formula we need is a normal distribution function in this case the trowel bridge writes GG x normal distribution function I don't know what the GG X stands for what this gets us is an estimation of what proportion of the micro facets of a surface how many of them are aligned with our halfway vector our bisecting vector such that the light hitting those micro facets is going to bounce off at an angle towards our camera and here's the normal ages or halfway vector and alpha is a value between 0 & 1 denoting roughness the larger the value the rougher the surface and as you can see the rougher the surface the larger but less intense the specular highlight so that a full roughness for our sphere it doesn't look like a highlight at all the whole sphere just looks gray this makes sense because when our normal is aligned with a half wave vector then for a smooth surface most of the micro facets should also be aligned with the halfway vector the rougher our surface gets the less s is the case when more formula we'll need is an estimation of how many of the micro facets in our surface are self shadowing if you zoom way into a point on the surface some micro facets stick out such that for light coming in from shear angles that micro facet is actually blocking light reaching other micro facets and so when light strikes a surface the more that light is coming in at an angle and the rougher the surface the more we get self shadowing amongst the micro facets the formula we want here is called Smith's method which employs the Schlick ggx geometry function and K here is a measure of roughness don't ask me why it's not called alpha but anyway as you can see in the diagram the points on the surface that are angled from the light have a stronger self shadowing effect and so they're going to be a bit darker looking finally at the shader code for each of the spheres we use the same albedo color but we're using different roughness and metallic parameters this function here is our normal distribution function it's just the formula translated into code here's the Smith's method formula translated into code and here's the vanilla slick approximation we'll call these functions from main which starts by computing the normal and the view vector we also get a base reflectivity which we're going to feed into the Finnell function the built-in mix function interpolates between two values start and end value here the vector 3 of point 0 4 and albedo another 3 and when Metallica 0 we get the start value when it's 1 we get the end value and then for values between 0 & 1 we get interpolated values in between so as our metallic parameter gets closer to 1 the more our base reflectivity is going to match the albedo this loop is where we're doing the calculation for each of the 4 lights we accumulate the output luminance in this variable L oh and we'll come back to this loop but looking past at first having computed L o we simply add it to our ambient light computed right here to get our color then we do our tone mapping gamma correction and that's our output color looking back at the loop we're gonna need the light vector L the halfway bisecting vector we compute the distance to the light use that for our attenuation and that gets us an input radiance value a measure of light energy coming in from this light source this hole then gets fed into our bi-directional reflectance distribution function which in this case is the Cooke Torrance brdf we're going to need the dot products between N and V and an L H and V and an H and note that for n VN dot L to prevent / 0 errors down the line we can't have these values be 0 so make sure there's something at least a little greater than 0 we then compute our normal distribution value will call D the result of the geometry function the self shadowing estimation we call that G and the result from our Finnell function will call F in Cooke Torrance we then get our measure of specular light by multiplying these all together and dividing by 4 times n dot V and not L because we're dividing by n dahveed and on hell that's why they can't be 0 here now I can't explain all the logic here but understand that D is going to be a value between 0 & 1 that gets larger closer to 1 the more the micro facets are aligned to H G is going to be a value between 0 & 1 that gets smaller closer to 0 the more the micro facets are shadowed by other micro facets and F is going to be RGB values also between 0 & 1 which are going to get closer to 1 the more the light vector and the view vector R at a shear angle to the surface NV and n dot L are going to be in between zero and one and because we're dividing the specular by them the closer these values are to zero the larger the specular value is going to get again I can't explain the exact it a logic here but it does make sense that as the view vector and the light vector diverge from the normal the more intense the specular light should get now as for the diffused light that's denoted here as KD and this is computed as simply one minus F because thanks to energy conservation whatever is bounced off has specular light our diffuse light can only be made up of the energy left over but then the larger a metallic parameter the more KD is diminished if metallic is 1 then the diffuse component goes all the way to zero because metals actually have no diffuse light now in reality a material is either metallic or not it's basically binary 0 or 1 but because metallic surfaces can have dust and dirt on them they can get scuffed up we want those surfaces to render as partial and metallic even though in reality something is either metal or not having computed KD we can finally get our output luminance for this one light by multiplying the KT times the albedo divided by pi for reasons I don't really understand other than the specular term is also divided by pi in the distribution function up here it's effectively divided by pi I think that's the rationale basically to even out the diffuse and specular components but I can't say for sure we then add the diffuse and the specular together multiplied by the incoming radiance but just like in fun lighting the incoming light is diminished when it hits the surface at an angle we only get the full radiance energy when it's hitting the surface perpendicular straight on and note two differences from Phong shading here for one the specular is effectively also being multiplied by n dot L not just our diffuse light and also note that only the diffuse is multiplied by the albedo the specular light isn't being mixed with the albedo color at all and this better matches physical reality it's the diffuse light the light that partially absorbs into the surface and bounces around that picks up the color property of that material the specular component just bounces off the surface anyway this is how we get the output luminance before each light add them all together and then than together with the ambient getting us our output color to which we apply the tone mapping and gamma correction now in our example each sphere was rendered with its own metallic and roughness value but it was the same metallic and roughness value applied across the whole sphere that may be fine for some objects we want to render but in many cases the metalness and the roughness might vary across a surface a metal surface for example might have some parts that are dirty or rust here and more scuffed than others so to have metalness and roughness that varies across a surface we can get those values per point by sampling from textures for extra detail we can also bring in an ambient occlusion map which effectively denotes the subtle self shadowing from a complex rough surface if say you have small creases and grooves and dents and a surface a little less omnia light is going to reach into points on those surfaces be clear though that these AO maps do not replace other unbanned occlusion you might still apply screen space ambient occlusion which is calculated based on our geometry and so isn't going to capture any detail within a single surface that's what they AO maps are for so if we want to use these textures instead of the uniforms like we had before what that looks like in code is very straightforward we just sample from the appropriate textures so what this looks like in action is we have all these maps being applied onto these spheres and note in this scene we just have one light a set of the four like we did before but anyway if we zoom in you can see there's quite a bit of lighting detail going on here thanks to all those textures
Info
Channel: Brian Will
Views: 24,833
Rating: undefined out of 5
Keywords: opengl 3d rendering programming
Id: 5p0e7YNONr8
Channel Id: undefined
Length: 12min 47sec (767 seconds)
Published: Mon Aug 26 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.