Lesson 10 – Physically-based rendering PV227 – GPU Rendering Jiˇrí Chmelík, Jan ˇCejka Fakulta informatiky Masarykovy univerzity 21. 11. 2016 PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 1 / 34 Physically-based rendering (PBR) Think about the physics behind everything: Light Lights Materials Sensors / Eyes In practice, still approximations More and more popular in real-time rendering, in rendering engines PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 2 / 34 Light propagation – Homogeneous media Light interacts with the material it travels through In homogeneous materials, the light is absorbed Loses some of its energy Clean water, glass, air, oil, . . . Low Absorbtion High Absorbtion PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 3 / 34 Light propagation – Heterogeneous media Light interacts with the material it travels through In heterogeneous materials, the light is scattered Scatters the energy without losses Milk, skin, wood, (dirty water, air with fog), . . . Low Scattering High Scattering PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 4 / 34 Light propagation – Absorbtion vs. Scattering Absorbtion vs. Scattering PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 5 / 34 Light interaction – Materials Light changes its direction at the boundary between two materials Reflection Refraction Without losses of energy PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 6 / 34 Reflection Perfect reflection: θi = θo Amount of reflected light depends on θi and on the wavelength Described by Fresnel equations PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 7 / 34 Fresnel reflection Depends on the wavelength, reflection has a color (!) Metals have usually higher values Dielectrics have usually lower values Mostly without any change until 50◦, then goes straight to one In practice: Schlick’s approximation: FSchlick (F0, L, N) = F0 + (1 − F0)(1 − L · N)5 where F0 is Fresnel reflection at 0◦, L is direction to light, N is surface normal PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 8 / 34 Fresnel reflection at 0◦ Fresnel reflections at 0◦ for some materials PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 9 / 34 Refraction Snell’s law sin θi sin θt = v1 v2 In metals, all energy is absorbed In homogeneous materials, the light continues in different direction In heterogeneous materials (including skin, wood, plastic, . . . ), the light is scattered and absorbed PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 10 / 34 Refraction – diffuse light Diffuse lighting When all the (non-absorbed) light exits the surface at approximately the same point as the light enters. PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 11 / 34 Refraction – sub-surface scattering Sub-surface scattering (SSS) When all the (non-absorbed) light exits the surface at different places. PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 12 / 34 Ambient lighting? “Does not exist in PBR” Average of lighting coming from all directions. PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 13 / 34 Microfacets Only some objects are flat (mirrors, water surface, . . . ), others are not With microfacets, the surface is represented with very small facets Smaller then ‘pixel’, not for displacement in geometry, not for normal mapping (Larger than light’s wavelength) Each mifrofacet is a flat surface Many microfacets models, for different materials Different distribution of orientation of facets Different shadowing between facets Different approximation of the model PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 14 / 34 Microfacets Top: smooth surface, Bottom: rough surface PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 15 / 34 Distribution of microfacets We are usually interested in facets which are oriented in the proper direction to give us perfect reflection. i.e. facets that are oriented in the half-vector direction Gaussian distribution, . . . PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 16 / 34 Geometrical attenuation Shadowing: Facets occlude the light for other facets Masking: Facets cannot be seen due to other facets Interreflection: Facets reflect the light to other facets, and then the light is reflected to the viewer PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 17 / 34 Task: Implement microfacets models Cook-Torrance (1982) Oren-Nayar (1994) Ashikhmin-Shirley (2000) Normalized Blinn-Phong (2008) PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 18 / 34 Legend to the following equations N, T, B are surface normal, tangent, and bitangent L is direction to the light, V is direction to the viewer H is half-vector, vector between the light and the viewer All dot products are non-negative, e.g.: max(0, N · L) All vectors are normalized All results must be multiplied by light’s intensity and color Fresnel(V · H) = F0 + (1 − F0)(1 − V · H)5 PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 19 / 34 Cook-Torrance Useful for most surfaces, metals, All microfacets are perfect mirrors Single parameter m (roughness), usually in range (0, 1) PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 20 / 34 Cook-Torrance cont. Diffuse: Idiff = Colordiff · (N · L) Specular: Ispe = F · G · D 4 · (N · V) where Fresnel F = Fresnel(V · H) Geom. atten. G = min(1, 2·(N·H)·(N·V) (V·H) , 2·(N·H)·(N·L) (V·H) ) Beckmann distribution D = e (N·H)2−1 m2·(N·H)2 m2·(N·H)4 (m is roughness of the material) Diffuse is energy-conserving, specular is energy-conserving, but not together PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 21 / 34 Oren-Nayar For non-shiny objects like concrete, flowerpots, bricks, Moon All microfacets are Lambertian (diffuse) surfaces No specular highlights Retroreflections at boundaries Single parameter m (roughness) PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 22 / 34 Oren-Nayar cont. Diffuse: Idiff = Colordiff · (N · L) · (A + B · max(0, cos(φ)) · C) where θi = arccos(N · L) θo = arccos(N · V) α = max(θi , θo) β = min(θi , θo) cos(φ) = norm V − N · (V · N) · norm L − N · (L · N) A = 1.0 − 0.5 · m2 m2+0.57 B = 0.45 · m2 m2+0.09 C = sin(α) · tan(β) Diffuse is energy-conserving PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 23 / 34 Ashikhmin-Shirley For brushed objects (metal) with anisotropic reflections All microfacets are perfect mirrors Two parameters shinT , shinB: shininess exponents in tangent and bitangent directions, usually greater than 1 PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 24 / 34 Ashikhmin-Shirley cont. Diffuse (not energy-conserving with specular): Idiff = Colordiff · (N · L) or diffuse (energy-conserving with specular): Idiff =Colordiff · (N · L) · · 28 23 (1 − F0)  1 − 1 − (N · L) 2 5    1 − 1 − (N · V) 2 5   where F0 is Fresnel reflection at 0◦ PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 25 / 34 Ashikhmin-Shirley cont. Specular: Ispe =Fresnel(V · H) · (N · L) · · (shinT + 1)(shinB + 1) 8 · (N · H) shinT ·(T·H)2+shinT ·(B·H)2 1−(N·H)2 (V · H) · max((N · L), (N · V)) PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 26 / 34 Normalized Blinn-Phong Improvement of the original Blinn-Phong (1977) Specular is energy conserving, without creating or losing energy Diffuse is the same Idiff = Colordiff · (N · L) Original specular Ispe = (N · L) · Colorspe · (N · H)shin Normalized specular Ispe = (N · L) · Colorspe · shin + 8 8 (N · H)shin where shin is shininess exponent PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 27 / 34 Normalized Blinn-Phong cont. Original Blinn-Phong, Colorspe = 120/255 shin = 25 shin = 50 shin = 75 shin = 100 Normalized Blinn-Phong, Colorspe = 32/255 shin = 25 shin = 50 shin = 75 shin = 100 PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 28 / 34 Task: Implement microfacets models Task 1: Implement Normalized Blinn-Phong Fragment shader BlinnPhongNormalized_fragment.glsl Parameters in variables: Colordiff in material_diffuse Colorspe in material_specular shin in material_shininess Compare with the original Blinn-Phong PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 29 / 34 Task: Implement microfacets models Task 2: Implement Cook-Torrance Fragment shader CookTorrance_fragment.glsl Parameters in variables: Colordiff in material_diffuse F0 in material_fresnel m in material_roughness Notice the highlight when looking from near surface angles Comparative with Blinn-Phong. To get approx. the same result: Set Specular color and Fresnel color to the same value Set roughness = 2 2+shininess PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 30 / 34 Task: Implement microfacets models Task 3: Implement Oren-Nayar Fragment shader OrenNayar_fragment.glsl Parameters in variables: Colordiff in material_diffuse m in material_roughness Set roughness to 0.5 and compare with Blinn-Phong with black specular PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 31 / 34 Task: Implement microfacets models Task 4: Implement Ashikhmin-Shirley Fragment shader AshikhminShirley_fragment.glsl Parameters in variables: Colordiff in material_diffuse F0 in material_fresnel shinT in material_shininess_tangent shinB in material_shininess_bitangent Test on cylinder or teapot, set different shininess in tangent and bitangent directions (e.g. 20 and 500) When using simple computation for diffuse color, and setting shininess to the same values, the result should be compatible with Blinn-Phong. PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 32 / 34 Further reading SIGGRAPH cources on PBR: http://renderwonk.com/publications/ s2010-shading-course/ http://blog.selfshadow.com/publications/ s2012-shading-course/ http://blog.selfshadow.com/publications/ s2013-shading-course/ http://blog.selfshadow.com/publications/ s2014-shading-course/ http://blog.selfshadow.com/publications/ s2015-shading-course/ http://blog.selfshadow.com/publications/ s2016-shading-course/ PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 33 / 34 Further reading Cook, R., Torrance, K.: A Reflectance Model for Computer Graphics Oren, M., Nayar, S.: Generalization of Lambert’s Reflectance Model Ashikhmin, M., Shirley, P.: An Anisotropic Phong BRDF Model Akenine-Möller, T., et al.: Real-Time Rendering Pharr, M., et al.: Physically Based Rendering, From Theory to Practice PV227 – GPU Rendering (FI MUNI) Lesson 10 – PBR 21. 11. 2016 34 / 34