About PBR on the fingers







In this text, I’ll talk a little about PBR, a concept of rendering based on physical principles. PBR is used in modern computer graphics, and we will talk about what it is and how it is prepared, and what important things it is worth knowing to those who are going to or are already dealing with the preparation of materials. The emphasis is shifted more towards games and game engines, where this concept is now used very widely.







Before moving on to specifics, a few words for "covering the rear."







Each engine and render has its own development pipeline, which is often unique, like a snowflake, and does not completely intersect with others. This is due, among other things, to the fact that PBR is a relatively young methodology, and we can say that we are seeing the first generation of such engines, standards are just beginning to emerge, so there is a difference and nuances in different implementations. And also because PBR is not a strict set of requirements, but rather a general direction of development.







When writing this text, I relied on my own experience plus the theory regarding several packages: Unreal Engine 4, Marmoset Toolbag 3, Substance Painter. Therefore, some things in other packages will look different, but in general the theory is universal.







In more detail I will describe the most important things, and in the end, on the residual principle, I mention that PBR is used, but not so important or tricky in the device.







I intentionally use the terms in an untranslated form, because the most current and complete sources of information are always in English, and if someone sits and waits for a translation, he automatically falls into those that are lagging and dependent on him. In my opinion, it’s right to immediately remember the terms that are used in the industry. And google, of course.







The material was prepared with the participation of the Maya3D Telegram community.







About the basics



First, let's go a little deeper into the story. Experience suggests that it is better to explain the meaning of terms and basic concepts immediately, but if you already know them, you can safely skip this section.







Further, you will notice that PBR borrows terms from anywhere, changing them a little, and that's normal.

PBR is an abbreviation for physically based rendering , which roughly means physically correct visualization , and these words speak for themselves. Sometimes the term PBS is used (here rendering changes to shader ), in some places there is even PBT (and here texturing appears). However, the difference is minimal - it is a matter of tradition, and the term PBR is traditionally used more often.







The last few years have been the mainstream of modern rendering systems, from real time and gaming to the so-called offline renderings. The name implies a certain adherence to the laws of physics, the laws of the real world, and this clarification seems to tell us: before it was not so. Let's figure out how it was and how it became, and how sideways it all came to us.







In three-dimensional graphics, from the very beginning of her life, a variety of approaches to display on the screen were implemented, until it became clear that reproducing the mechanisms of reality gives more realistic results, so to speak.







About the same story happened with the skeletal animation of the characters, which "buried" the vertex.

If we model reality, then let's use its laws and architecture, automating constants and shifting some of the work to software. Renders are increasingly striving to work the way our reality works, with each generation of iron introducing new approaches that allow you to abandon fakes.







Offline renders are renders that do not work in real time, for example, Vray or Arnold.

For some reason, probably, it narrows the flight of fantasy and cuts off the shoots of stylization, but that’s probably what.







On the other hand, tricks and fakes are moving to a new level, which is also progress.







In the real world that surrounds us, the electromagnetic field is the basis for interaction on a scale higher than atomic and lower than planetary. Everything that we see and can touch is accessible to us thanks to him. Man is an imperfect creature, we can not see the largest part of the electromagnetic spectrum, but with it there are a lot of subtleties that we use by virtue of understanding. All that we see around us is light and its whims. Nice entry, and most importantly, obvious, right?







The vast majority of people are trichromats, but there is a small percentage of tetrachromat mutants that distinguish more shades and see the world more diverse. And more often these are women.

In PBR, light has become less conventional than before. BxDF describes not only how it reaches the surface, but also how it is reflected from it, given the characteristics of the materials. This allows you to more accurately describe the scene and convey the result, as close as possible to reality.

One of the key changes that PBR has brought is the versatility of materials in any lighting. Correctly configured materials will always look correct in any scene.







In the previous generation of renders, the microsurface and the nature of the flare, the types of materials conductor / insulator were not taken into account; diffuse reflection carried partial shade and even painted glare; there were no reflection values ​​from the real world; The materials were not universal for any scene and lighting.







About the substance



There are two types:









The classification is taken from the real world (with simplifications) and tries to follow the name.

The conductors conduct electric current, have a crystal lattice and other "joys" from the school course of physics. They do not have diffuse reflection and subsurface scattering, their surface does not scatter light, it is impervious to it, but absorbs some part of it, reflecting waves of specific lengths - a color glare.







However, the current is not important for PBR. The skin also conducts current, but in PBR it is not metal, and therefore not a conductor.

Insulators scatter light; it penetrates their surface; they have diffuse reflection and subsurface scattering, glare with white light.

Both types of materials have a Fresnel effect.







About the pipelines



Traditionally, we have two pipelines for materials and their preparation: specular and metalness . Usually, it means that in specular there is a corresponding mirror image map, but in metalness it is not, but there is a mask of metallicity, and this can be done.







Of course, everything is not so simple here.







The specular pipeline really has a specular map, which controls the intensity and color of the gloss on F0 , the values ​​of which are completely in the hands of the artist, and does not have built-in constants in the shader. Fresnel is sometimes controlled separately, albedo controls only color, gloss / roughness controls the nature of reflections, everything is simple here.







Metalness does not have a separate gloss intensity map; these values ​​are sewn into shaders within 2-5% for dielectrics and 70-100% for conductors. The relationship of the cards here is slightly higher: albedo , metalness and roughness of the cards affect the color, intensity and nature of the specular reflection in total. There is one less card in this pipeline, and taking into account the possibility of packing grayscale cards in one RGB, such materials occupy less system memory.







The choice of modern renderings almost completely fell on metalness in view of its efficiency and greater automation, because such shaders take care of the correct Fresnel calculations. Despite the fact that specular gives more control, this control is often redundant and takes more time and effort with similar results. Therefore, we will talk specifically about the metalness pipeline in general.









Differences pipelines and maps. Wes McDermott and Allegorithmic.







About BRDF and GGX



The basis of the difference between PBR from the previous generation in the change of BxDF. BxDF is a bidirectional X distribution function , which roughly sounds like a two-beam X-ability function . But this family of functions has several abilities: it is at least reflectance , transmission and scattering - reflection, transmission and dispersion, respectively (in specialized literature and articles the artist more often meets the BRDF variant).







These functions describe the behavior of the beam when interacting with the surface: how it scatters (that is, it penetrates the upper layer and returns), it is reflected or passes through a transparent material.







In our history, BxDF is closely related to microfacet theory , which also has a lot of implementations, often named after the names of the authors: Cook-Torrance, Ashikhmin-Shirley, GGX and so on. GGX is just one of the implementations of microfacet theory - the theory of microsurfaces, which is used almost everywhere. It presents a simplified model of the microsurface, which in conjunction with BxDF simulates the reaction to light for all types of interaction.







Facet can also be translated as a “facet”, which also makes sense. In a simplified theory, a surface is a collection of small faces.

GGX is not decrypted in any way, the set of letters is taken from the variables used in the formulas (or someone’s last name is cluttered - the story hides). Artists can see this term in the roughness / gloss parameter settings.







For example, one of G is the bidirectional shadowing-masking function, a two-beam self-shadowing / masking function.



Microsurface and its effect on specular reflection. Wes McDermott and Allegorithmic.







Energy saving



Energy conservation is also one of the fundamental constants of PBR and it means that the surface cannot return more light than it receives. In particular, the albedo and specular reflection add up, and if the specular is brighter, then albedo is less bright, and vice versa. In general, this is an automated thing in engines, sometimes it is possible to turn it on and off, for example, in the Marmoset Toolbag.







About Fresnel



Augustin-Jean Fresnel (Augustin-Jean Fresnel), a French physicist of the XIX century, the creator of the wave theory of light and heaps of other cool things, described the effect of the name itself, which consists in the fact that the level of light reflected from a surface directly depends on the angle of view to this surface. At right angles, that is, F0 , we get the minimum level of specularly reflected light that is available to the material. And the larger the angle, the more light we will catch, approaching 100%.







According to this effect, any material has a glare, everything shines, in principle, you just need to find the right angle.







When we talk about the intensity of gloss in general, we always mean the gloss on F0 - this is what is controlled by the artist through the parameters albedo / roughness / metalness .



Scheme of the Fresnel effect. Wes McDermott and Allegorithmic.







About diffuse reflection



Albedo. Diffuse Base color.





Scheme of interaction in diffuse reflection. Wes McDermott and Allegorithmic.







This is light that falls on the surface and is partially absorbed by it, and partially reflected, randomly scattering in the upper layers and returning to the observer the color of this same surface. Sometimes in this case they say that it is painted in the color of the surface, but we are talking about physical correctness, so it’s worth repeating - the light does not paint, the part of the spectrum that has not been absorbed and not lost returns to us. The part of the visible light that is absorbed by the surface in the real world goes into thermal energy, and in PBR this can also be taken into account, but it depends a lot on the shader used and in this case is secondary.









Absorption of light and return to the observer of only non-absorbed waves. Wes McDermott and Allegorithmic.







The behavior of the material during diffuse reflection is determined by the albedo map, or base color , or even diffuse in some places. The difference in these names stems from tradition and different engine development pipelines, but the behavior is the same everywhere - at least there should be. The color should be captured on the albedo map, what it would look like at a right angle to the surface and 100% white lighting. Without shadows, partial shade, glare and all that is not squeezed into the definition of "pure color". This is the key difference between the current diffuse reflection in PBR and the previous generation of renderers, where the term diffuse is also used, but in a slightly different way.







A photograph of an object with a polarization filter under direct lighting captures its albedo , for example. Polarization removes glare.

It would seem that there is nothing more to say about color, but there are still subtleties.







The diffuse reflection map affects the rendering of pure metals in the metalness pipeline, staining the highlight in the corresponding color. In addition, the albedo map directly affects specular reflectance for metals, allowing you to vary it in combination with a metalness card. This is a rather tricky design, but in general it looks like this: when we make the material of the insulator, we draw a black metalness mask and the shader assigns a gloss to F0 of 4%. When we make transitions in metalness up to white, that is, pure metal, the brightness in the albedo map affects the intensity of its brightness. The brighter the color in albedo , the more intense the luster, which approaches a value of 100%. We have no control over the gloss level of the insulator. It is assumed that a 2-4% difference is uncritical and masked through roughness , or fine-tuned through specular reflectance , if necessary and possible.







This example is described taking into account the UE4 shaders, Marmoset Toolbag and Substance products. But overall it works everywhere.

The artistic effect of surface color cannot be underestimated. Often this eludes the attention of artists, and they make black plastic black to make it “like in life”. But there are usually no monolithic colors in reality, and color variations are almost always present in the material, this must be understood and used.







Diffuse reflection is described by an RGB card, or in terms of engines, by a Vector3 array, which is logical, we are talking about color.







PBR validation



Since PBR strives for real parameters and characteristics, the values ​​for albedo brightness must be validated and reduced to ranges of real values, and they cannot fall below 30-50 sRGB and rise above 240 for dielectrics. In the case of pure metals, the value of 240 can increase to 255, because this is not the value of diffuse reflection, but the value of specular reflectance .







But, of course, there are subtleties here.







For example, one of the darkest substances in the ordinary world is coal. The brightness value of albedo , translated into sRGB, is 50, and this is near the boundary of the minimum that PBR can afford for dielectrics. The values ​​below are too dark and may not look right under different lighting conditions.







Not so long ago, some people tensed and created a material that absorbs 99% of the light and looks like a black hole in space.

Why is it important?







Because diffuse and specular reflections work in pairs. Albedo values ​​that are too dark will affect the difference between albedo itself and specular reflectance , and artists will have to “twist” the light to normalize the glare on F0 and diffuse reflection, which will entail overexposure of the whole scene, and the materials will eventually become universal and apply only to a specific lighting.







Why might this not matter?







Because it depends on the composition. If the presentation of a separate model is rendered, and there is no global lighting and reflection reflection in the scene, but there is HDR lighting, then in general you can make values ​​outside 30-50 sRGB. And there is also a semi-mythical beast “artistry”. “What matters more is not physical correctness,” he says, “but perception.” And here it is possible and sometimes necessary to violate the laws that are difficult to establish.







An extremely controversial issue regarding the admissibility of violating PBR laws and the conformity of reality. Somewhere it plays into the hands of perception, and somewhere it is necessary to maintain all standards. Examples and discussion are beyond the scope of this text.

In general, maintaining the albedo brightness limit remains on the conscience of the artist or his art lead, and a large part of the work in PBR that exists today does not pass this validation at the lower limit, which does not prevent them from being qualitative and correct in an inexperienced look. The difference becomes visible only if you check the values ​​and pull up to the lower limit, or if a separately executed model is placed in a scene with the correct lighting.







But even if we do not bother with validation, do not use pure black color at 0 sRGB for dielectrics.







PBR validation is provided by various tools in both engines and editors. For example, in Substance Painter there is a filter that works on top of the entire stack of layers, checking the values.









PBR validation in Substance Painter. Wes McDermott and Allegorithmic.









Chart intensity values ​​for some materials. Data taken from Sébastien Lagarde and DONTDNOD.







About mirror reflection



Specular reflectance



Specular is a Latin word that translates as “mirror”.



Scheme of the interaction of light in specular reflection. Wes McDermott and Allegorithmic.







This refers to that part of the light flux that is reflected from the surface according to the law of the angle of incidence and returns to the observer in full. Specular reflectance , or specular reflection, is glare, and it is very closely related to the characteristics of the microsurface. It is found in both pipelines, but it is directly controlled in the specular pipeline and indirectly in metalness .







The fact is that direct control of the brightness is a very vile thing. We remember the conductors and insulators, but few artists will remember the exact intensity values ​​without a table before their eyes, and there are also exceptions in the form of precious stones. Having access to this shader setting, it’s very easy to get away from physically correct values ​​somewhere in the astral plane, breaking the entire visual range, and even preparing materials on our shoulders and the video card’s memory is another card.







In addition, measurements of real world values ​​fit into a small framework that can be automated, which is what they did in metalness , having selected direct control and the need to think about this as well.







In a specular pipeline, the specular parameter is controlled by a grayscale map in values ​​0-255, a linear color or a scalar parameter.







The scalar parameter here is the value that is set for the two-dimensional space that is projected onto the model. In other words, when you move the slider in Marmoset for specular, this is the scalar parameter.

In a metalness pipeline, there is usually no direct control of gloss intensity through the specular parameter. Instead, the basic intensity values ​​for F0 are inscribed in the shaders: 4-5% for insulators and 80-100% for pure metals, which corresponds to the values ​​of real materials. The rest of the work on mixing and calculating the Fresnel effect is taken over by the engine, and artists are invited to control the brilliance as such through roughness and albedo .







Cavity



With specular reflectance there is one rather important nuance, which is that sometimes the material has places where the specular gloss is completely absent, for example, when simulating through holes that are always shaded. Or the luster is much lower than other places, for example in deep cracks or other irregularities where the light falls into the trap. This is usually controlled through the cavity parameter; This map allows you to tell the shader where its fixed value is decreasing. In UE4, for example, there is a specular parameter in materials, and this name can be confusing, but you need to know that this is not a direct specular control, as you might think, but just a cavity control to reduce flare within 0-4%. The same parameter is in Substance products and so on. That is, if we need to imitate an absolutely non-reflecting place, we draw a map with black values ​​and connect to this parameter. Shader removes fixed flare.















An example of the effect of cavity on specular reflectance. In the upper picture in the text, the shutter pin and cylinder pin are the default flare values. At the bottom in these places there is a cavity mask and they will not glare at any angles, simulating light trapped in the depth of geometry. Render from Marmoset Toolbag 3







About metallicity



Metalness



Metallicity in PBR is a critical feature because metals and non-metals behave differently in lighting. Insulators have diffuse reflection and no flare, conductors have the opposite - their surface does not allow light to scatter due to high density. Insulators mirror 2-5% of the light flux, conductors - 70-100%, and these values ​​are inscribed in the shaders as constants.







It would seem that this can be finished, but the planet Earth is rather harmful and pure metals it quickly covers with oxide film, dirt, dust and other things unpleasant for theory, which translates into the use of gradients in a black and white metalness map. And this is already unpleasant for the artist, fascinated by theory and waiting for the results predicted by it. Because when rendering transitions between metal and non-metal, we get a rendering artifact, regardless of whether we have rich UE4 or a more modest Unity budget. And the only recommendation (in addition to “avoid if possible”) is to increase the resolution of the texture or a specific place: at high texel density artifacts at the transition points are less noticeable.







The artifact of the metal / non-metal transition is also present in the specular pipeline, it is simply inverted and not so noticeable, because it is dark.



Metal / non-metal transition artifacts. Wes McDermott and Allegorithmic.







According to the PBR theory, color glare occurs only in metals. Because they do not have diffuse reflection, but there is a surface itself, and sometimes the light nevertheless loses a part of the spectrum, heating it, and the rest is a color glare. And if in a specular pipeline we would have to use a color RGB card in specular input, loading memory with two more channels, then in metalness everything is available in albedo right away. And, according to the metalness map, the shader either colors the flare if we have pure metal, or not if it is an insulator. Easy.







Yes, the yellow color of a bar of gold is a glare, not a diffuse reflection. It's just that the surface of this bar is imperfect, and the highlight is gently smeared on it if the bar is not polished.







Another thing is that artists usually do not care about such subtleties. From the point of view of the material editor, we still make color albedo for gold, for example, in Substance Painter, so what's the difference, the artist will ask. An important nuance for understanding, therefore again: albedo controls the color of non-metals and the level of brightness of the glare of metals.







Metallicity is described by a 0-255 black-and-white map in a linear color and can be a scalar parameter without a map.







About Roughness



Roughness. Glossiness Smoothness



If we imagine the surface of a conditional material at high magnification, we will inevitably see its imperfection, a whimsical topology that is essential for light. Light randomly deviates, bumping into these imperfections, and partially eludes the observer, and partially returns to him. In PBR, the microfacet theory implementation in conjunction with BRDF is responsible for this, according to which the surface of the conditional material can be represented as a set of small flat squares, the angle of which is controlled by the roughness , or gloss , or even smoothness card in some places.







Even simpler - each pixel on the roughness map has a separate square of the surface. Extrapolation during rendering forms the general nature of the flare.

Both cards mean the same thing, only in roughness the white color is the maximum deviation, that is, the light ray does not return to the observer and the clarity of the flare is blurred, and the black one is the minimum, that is, the light ray goes to the observer, and the glare is as sharp as possible, approaching to the mirror. And in gloss these values ​​are inverted.







If the specular sets the gloss intensity (or the hardcode of the values ​​in metalness ), then the roughness describes the nature of this gloss. That is, in what place our material glare more orderly, approaching the mirror in terms of properties, and in which it is processed with a rasp and the highlight there is so messy that it becomes soft, as in the example of the golden bar.

Roughness in the hands of the artist allows you to work miracles, describing the surface and its history, which changes when the angle of light changes, bringing the desired life into the picture - all these handprints, dust, small scratches.







The roughness is determined by a grayscale map at 0-255, stored in linear color.









Roughness map and interaction diagram. Wes McDermott and Allegorithmic.







About pseudo-relief



Normal bump



To understand what normal maps are, you need to quickly go over the theory of three-dimensional graphics. Normal is a vector perpendicular to a tangent surface, one of the entities in the mathematics of calculating surface illumination.







By normal, I was rightly kicked in the comments, there is a little more detail.

There are two types of normals in the polygon plot: vertex normal and face normal , respectively, vertex normal and polygon normal. Interpolation of these values ​​gives either a smooth surface or separation at the edges of hard edges .







For example, Zbrush does not take vertex normals into account when rendering, which is why the surface at low levels of detail is not smooth. Due to this, resources are greatly saved, which allows you to operate with millions of polygons.



With hard / soft edges, there is one more nuance, which is that hard edges double the number of their vertices in the render due to the peculiarities of the render itself. The same story with UV seams, because they seek to unite. This does not apply to PBR, but this is regularly encountered by all modeling artists.

Here we should make a small digression and talk about terminology. The term polygon in three-dimensional graphics has a floating meaning.The word itself came from Greek and means "polygon", it applies both to triangles - a unit of the polygonal mesh, and to polygons with 3 + n angles. In English there is a term face with a similar application history. Face normal in this case is the normal of the triangle.







Renders operate with triangles, because any polygons 3 + n have meaning only in the editor.

, , . , «» . , , . , , ( tangent space , ) ( object space , ) , , .







( bump ) , , . , — normal bump bump. — . , bump , , . , , Mikk, ( Y, ).

Normal bump PBR-, , — , . , . , . , « »; , , . Rockstar RAGE — GTAIV/V, RDR1/2, Star Citizen CryEngine/Lambeyard. , , , , .







PBR .









Subsurface scattering, SSS.



, , : , . , , , .







, SSS, , : ( ) RGB-. .









SSS. .









Translucency



, SSS, . Translucency — , . Translucency - .









: , . .









Ambient occlusion



ambient occlusion — , . , . AO — , . cavity PBR-, . PBR- , . AO, . , SSAO ( screen space ambient occlusion ), HBAO ( horizon based ambient occlusion ) , . , — deferred rendering .







, - PBR , , roughness , .









, , . : https://www.gamingscan.com/what-is-ambient-occlusion/







, RTX GI , .







What to read



Since this article is not a detailed guide or manual, but rather a memo, for a detailed study of the topic, you can read the materials at the links below.







GGX presentation, a bunch of theory and math







Allegorithmic PBR Guides:

https://academy.substance3d.com/courses/the-pbr-guide-part-1

https://academy.substance3d.com/courses/the-pbr-guide-part-2







Theory by Marmoset







Theory from the Filament Engine







Description and implementation of PBR in 3dCoat







UE4 Documentation







Presentation by Sebastien Lagarde







If it’s not clear who Sebastian Lagarde is, then here’s an extensive presentation on Frostbite







Unity Documentation







Intro fixed, thanks for the tip to zhovner .








All Articles