Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] PBR Materials extension #643

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
9df448c
initial commit
tsturm Jun 17, 2016
292748a
Update README.md
tsturm Jun 17, 2016
e18e2ce
Create Appendix.md
Jul 6, 2016
7b1a838
Update Appendix.md
Jul 6, 2016
158c4d4
Moved PBR concepts to Appendix.md
Jul 7, 2016
24463da
Added schema
Jul 7, 2016
5c152cd
Updated README
Jul 7, 2016
90dd746
Put list of resources to appendix
Jul 7, 2016
5078f0d
schema updates, renamed specular_glossiness schema file
Jul 7, 2016
4a17ab3
cleanups and updates in spec, split variables into factors and textures
Jul 7, 2016
ce5b6df
replace some images
tsturm Jul 7, 2016
ee7cf4d
remove duplicated figure labels
tsturm Jul 7, 2016
d473c7b
figure size fix
tsturm Jul 7, 2016
45d559b
figure reference fix
tsturm Jul 7, 2016
bbaccfd
Merge branch 'cleanup'
tsturm Jul 7, 2016
c9ac6cd
Changed prefix to FRAUNHOFER
Jul 8, 2016
c5c2ecf
Incorporated most points from pjcozzis first review
Sep 1, 2016
5fa4543
Fixed link to KHR_materials_common
Sep 1, 2016
72120eb
fix typo in equation 5
tsturm Sep 22, 2016
1e73aea
added slightly modified three.js shader example as a basis for the fi…
Sep 29, 2016
5f8804e
Merge branch 'master' of https://github.com/tsturm/glTF
Sep 29, 2016
8d4c89b
[wip] basic PBR app skeleton, using custom shaders and a basic glTF a…
Oct 25, 2016
7aed2a5
Added tangents and binormals in hammer asset, adapted shader to use t…
Oct 27, 2016
e0e419a
Simple untextured roughness/metalness example
Oct 30, 2016
187b7c1
Fixed (flipped) metalness axis in example
Oct 30, 2016
e157406
Added linear2sRGB conversion
Oct 30, 2016
39a58f9
panorama environment map and basic code to use it (WIP)
Oct 31, 2016
9b220cc
Add specular-glossiness workflow
bghgary Nov 9, 2016
9905487
Add gui for updating values on the fly, including workflow, albedo, o…
bghgary Nov 10, 2016
cf131da
Fix a bug with the color lerp and removed some unused code
bghgary Nov 15, 2016
6ca13dd
Merge pull request #2 from bghgary/master
Nov 16, 2016
e3b4b37
envMap / irrMap added (basically set up, not actively used in shader …
Nov 17, 2016
9949197
[wip] basic environment map sampling
Nov 18, 2016
3770706
Used more easily readable example numbers, added more contributors
Jan 3, 2017
524cdd0
added comment about conversion to linear space
Jan 3, 2017
d5f4790
made usage of linear space for computations more explicit
Jan 3, 2017
5d91d6d
Add space column specifying how the properties should be interpreted.
bghgary Jan 3, 2017
4751935
Merge pull request #3 from bghgary/add-space-column
Jan 4, 2017
e03182c
renamed extension prefix to EXT_ (filename not changed for now)
Jan 4, 2017
e1a4530
contributors update
Jan 4, 2017
b9bf255
Merge branch 'master' of https://github.com/tsturm/glTF
Jan 4, 2017
9e117a2
Add energy conservation to spec gloss model
bghgary Jan 4, 2017
28778ef
Fixed typo
bghgary Jan 4, 2017
de6f796
Merge pull request #4 from bghgary/add-energy-conservation-to-spec-gloss
Jan 5, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions extensions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ _Draft Khronos extensions are not ratified yet._

* [CESIUM_RTC](Vendor/CESIUM_RTC/README.md)
* [WEB3D_quantized_attributes](Vendor/WEB3D_quantized_attributes/README.md)
* [FRAUNHOFER_materials_pbr](Vendor/FRAUNHOFER_materials_pbr/README.md)

# About glTF Extensions

Expand Down
139 changes: 139 additions & 0 deletions extensions/Vendor/FRAUNHOFER_materials_pbr/Appendix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
## Physically-based rendering

<p style="text-align:justify;">Physically-based rendering attempts to produce realistic images by accurately modeling light-matter interaction. Material definitions for PBR usually consist of compact sets of parameters suitable to represent a large range of real-world materials.
This extension defines two `techniques` which represent two commonly used PBR material models.
</p>


<p style="text-align:justify;">Physically-based rendering (PBR) refers to the concept of using realistic shading/lighting models along with measured surface values to accurately represent real-world materials. PBR is more of a concept than a strict set of rules, and as such, the exact implementations of PBR systems tend to vary. Still, as they are based on the same principal idea (improve realism by approximating physical laws), they are similar across implementations.</p>

Some of the main goals behind PBR are:

**Simplicity**

<p style="text-align:justify;">PBR uses an easy to understand material description defined by a small set of intuitive parameters instead of a large array of parameters, which results in decision paralysis, trial and error, or inter connected properties that require many values to be changed for a single intended effect.</p>

**Extensiveness**

<p style="text-align:justify;">PBR can cover up most of the materials that occur in the real world with a single shading model. As deferred shading limits the number of shading models that can be used, this is highly beneficial. On forward renderers it improves performance by reducing shader switching.</p>

**Consistency**

<p style="text-align:justify;">By using physically-based shading models, which follow real physical laws, materials will look accurate and consistent in all lighting conditions without changing an immense list of parameters and settings.</p>

## Shading model

### Specular BRDF

<p style="text-align:justify;">The most common choice for a physically-based specular BRDF is the Cook-Torrance reflectance model [4]. It is based on the microfacet theory in which surfaces are composed of small-scale planar detail surfaces of varying orientation. Each of these small planes, so called microfacets, reflects light in a single direction based on its normal.</p>

The Cook-Torrance specular BRDF is defined as follows:

<img src="figures/_equation01.png" align="middle" height="55" style="display: block; margin: 0 auto; padding: 20px 0 10px 0;">

<p style="text-align:justify;">Where l is the light direction, v is the view direction, h is the half vector, n is the normal, F is the Fresnel term, G is the geometry term, and D is the normal distribution function (NDF).</p>

**Specular D**

<p style="text-align:justify;">Specular D is represented by the normal distribution function which is used to describe the statistical orientation of the micro facets at a given point. The first PBR implementations used distributions such as Phong or Beckmann, but recently the GGX distribution [Walter et al. 2007] has become a popular choice. </p>

It is defined by:

<img src="figures/_equation02.png" align="middle" height="55" style="display: block; margin: 0 auto; padding: 20px 0 10px 0;">

Where h is the half-vector(microfacet normal), n is the normal and &alpha; is the roughness of the material.

**Specular F**

<p style="text-align:justify;">The specular F term represents the Fresnel function. The Fresnel function is used to simulate the way light interacts with a surface at different viewing angles. We adopt Schlicks Approximation [7] for the Fresnel term which is the most commonly used in 3D graphics.</p>

<img src="figures/_equation03.png" align="middle" height="25" style="display: block; margin: 0 auto; padding: 20px 0 10px 0;">

Where F0 is the specular reflectance at normal incidence.

#### Specular G

<p style="text-align:justify;">Specular G represents the geometry shadowing function used to describe the attenuation of the light due to microfacets shadowing each other. This is once again a statistical approximation which models the probability of energy loss. This may occur due to microfacets being occluded by each other or light bouncing between multiple microfacets, before reaching the observer's eye. The geometry attenuation is derived from the normal distribution function. Most implementations use Smith's shadowing function [9] or Schlick's model [7].</p>

The complete geometry shadowing function is composed of the two partial functions G_1(n,l) and G_1(n,v) as follows:

<img src="figures/_equation04.png" align="middle" height="25" style="display: block; margin: 0 auto; padding: 20px 0 10px 0;">

The partial Smith shadowing function is defined as:

<img src="figures/_equation05.png" align="middle" height="55" style="display: block; margin: 0 auto; padding: 20px 0 10px 0;">

and the partial Schlick shadowing function is defined by:

<img src="figures/_equation06.png" align="middle" height="55" style="display: block; margin: 0 auto; padding: 20px 0 10px 0;">

where k is defined by:

<img src="figures/_equation07.png" align="middle" height="55" style="display: block; margin: 0 auto; padding: 20px 0 10px 0;">

### Diffuse BRDF

<p style="text-align:justify;">The Lambertian diffuse BRDF is still the first choice. Even though other models (e.g. [2]) are more accurate, the visual improvements are arguably insufficient for justifying the extra computation in real-time applications.</p>

The Lambertian diffuse is defined as:

<img src="figures/_equation08.png" align="middle" height="55" style="display: block; margin: 0 auto; padding: 20px 0 10px 0;">

<p style="text-align:justify;">Where cdiff is the diffuse reflected color of the material. In order to ensure energy conservation, the diffuse term should be balanced using the inverse of the Fresnel term from the specular component [8]:</p>

<img src="figures/_equation09.png" align="middle" height="55" style="display: block; margin: 0 auto; padding: 20px 0 10px 0;">

### Imaged-based Lighting

<p style="text-align:justify;">Image-based lighting (IBL) is the most common technique to simulate indirect lighting in the current PBR engines. It uses environment maps from real-world light probes or rendered scenes to illuminate objects.</p>

#### Importance Sampling

<p style="text-align:justify;">To use the presented shading model with imaged-based lighting, the radiance integral needs to be solved, which can be achieved by using importance sampling. Importance sampling substantially improves the Monte Carlo algorithm by introducing a guided approach to the sampling. The idea is that we can define a Probability Distribution Function (PDF) that describes where we want to sample more and where we want to sample less.</p>

The following equation describes the numerical integration:

<img src="figures/_equation10.png" align="middle" height="55" style="display: block; margin: 0 auto; padding: 20px 0 10px 0;">

which can be solved in real-time directly on the GPU [3].

<p style="text-align:justify;">But even with importance sampling, many samples are still needed to produce acceptable results. In simple scenes with only a few objects and a single environment map this is not a problem. But in more complex scenes with many different objects and multiple environmental light sources the pure importance sampling approach is not suitable anymore for real-time rendering.</p>

<p style="text-align:justify;">This problem can be solved using a split sum approximation [6]. This new technique is employed in the Unreal Engine 4 for real-time PBR of complex scenes.</p>

#### Split Sum Approximation

<p style="text-align:justify;">The split sum approximation splits the sum from (10) into a product of two sums, both of which can be pre-calculated, see (11). This approximation is exact for a constant Li(l) and fairly accurate for common environments.</p>

<img src="figures/_equation11.png" align="middle" height="55" style="display: block; margin: 0 auto; padding: 20px 0 10px 0;">

<p style="text-align:justify;">The first sum is pre-calculated for different roughness values by convolving the environment map with the GGX distribution using importance sampling and storing the results in individual mipmap levels of an environment map texture.</p>

<img src="figures/prefilteredEnv.png" align="middle" height="100" style="display: block; margin: 0 auto; padding: 20px 0 10px 0;">

<p style="text-align:justify;">The second sum in (11) includes the remainder and is equivalent to integrating the specular BRDF with a solid-white environment. By substituting in Schlick's Fresnel approximation (3) into the left hand side of (10) F0 can be factored out of the integral. This leaves two inputs (roughness and cos &theta;v) and two outputs (a scale and bias to F0), which can also be pre-calculated and stored in a 2D Look-Up Texture (LUT).</p>

<img src="figures/brdf_lut.png" align="middle" height="200" style="display: block; margin: 0 auto; padding: 20px 0 10px 0;">

<p style="text-align:justify;">The main advantage of the pre-calculated LUT is that it is constant for white light and it does not depend on a specific environment. So it has to be pre-calculated only once for a particular shading model and can be reused in every shader.</p>

<p style="text-align:justify;">Thus the split sum approximation only two texture fetches per pixel are needed to get the corresponding specular color. This is a significant improvement over the importance sample method, which requires multiple samples per pixel.</p>

### Reflectance Values

<p style="text-align:justify;">Since PBR is based on physical laws one cannot use arbitrary inputs for the reflectance values. Especially for the specular-glossiness model where the parameters allow full control over the reflectance of both metals and non-metals. The values must be correct and measured from real world data. Fortunately, several reference charts exist such as the one from [5] which provides sets of values for specific materials.</p>


## Resources

* [1] ALLEGORITHMIC, 2015. The comprehensive pbr guide vol. 2. [https://www.allegorithmic.com/pbr-guide](https://www.allegorithmic.com/pbr-guide).
* [2] BURLEY, B. 2012. Physically-based shading at disney, part of Practical Physically Based Shading in Film and Game Production. In ACM SIGGRAPH 2012 Courses, SIGGRAPH '12.
* [3] COLBERT, M., AND KIVNEK, J. 2008. Gpu-based importance sampling. In GPU Gems 3, H. Nguyen, Ed. Addison-Wesley, 459-475.
* [4] COOK, R. L., AND TORRANCE, K. E. 1982. A reflectance model for computer graphics. ACM Trans. Graph. 1, 1 (Jan.), 7-24.
* [5] DONTNOD. 2014, [https://seblagarde.files.wordpress.com/2014/04/dontnodgraphicchartforunrealengine4.png](https://seblagarde.files.wordpress.com/2014/04/dontnodgraphicchartforunrealengine4.png).
* [6] KARIS, B. 2013. Real shading in unreal engine 4. In ACM SIGGRAPH 2013 Courses, SIGGRAPH '13. [http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf](http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf)
* [7] SCHLICK, C. 1994. An inexpensive brdf model for physically based rendering. Computer Graphics Forum 13, 233-246.
* [8] SHIRLEY, P., SMITS, B. E., HU, H. H., AND LAFORTUNE, E. P. 1997. A practitioners' assessment of light reflection models. In 5th Pacific Conference on Computer Graphics and Applications(PG '97), IEEE Computer Society, 40.
* [9] WALTER, B., MARSCHNER, S. R., LI, H., AND TORRANCE, K. E. 2007. Microfacet models for refraction through rough surfaces. In Proceedings of the 18th Eurographics Conference on Rendering Techniques, Eurographics Association, Aire-la-Ville, Switzerland, Switzerland, EGSR'07, 195-206.


Loading