# Week 9
## PBR & Game texturing
# Physically Based Rendering
Physically based techniques attempt to simulate reality by using principles of physics to model the interaction of light and matter. Rendered scenes are based on physically accurate lights, materials, and light transport (i.e., Global Illumination).
In physically based rendering, realism is usually the primary goal. There is less tweaking and fewer parameters to get the correct results. However the computational cost usually becomes a lot more expensive and we need to understand physical lighting phenomena.
- [Photorealistic Materials in Unity!, published on Mar 11, 2018 by Brackeys](https://www.youtube.com/watch?v=_LaVvGlkBDs)
## Physically Based Rendering in Arnold
Arnold is **a physically based renderer**, but it also lets you break the rules and create materials and lights that do not obey the laws of physics if you wish.
Designing materials based on physical laws can tremendously simplify shading and lighting, even when we do not necessarily strive for realism or physical accuracy. **By understanding and applying a few principles** we can make images that are more believable, and create materials that behave more predictably in different lighting setups.
### Arnold references
- [Linda.com: Maya 2018 Essential Training](https://www.lynda.com/Maya-tutorials/Maya-2018-Essential-Training/604210-2.html?srchtrk=index%3a3%0alinktypeid%3a2%0aq%3aArnold+%2b+maya%0apage%3a1%0as%3arelevance%0asa%3atrue%0aproducttypeid%3a2)
- 9: Create Materials
- Work with Arnold materials
- Opacity and refraction in Arnold
- 12: Render in Arnold
- [Arnold for maya user guide 4](https://support.solidangle.com/display/AFMUG/Understanding+Physically+Based+Rendering+in+Arnold)
- [Learning sceans](https://support.solidangle.com/display/AFMUG/Learning+Scenes)
- [Material library](https://support.solidangle.com/display/A5AFMUG/Material+Library)
This material library is meant as a beginners guide for the type of material effects that are possible when using the Standard Surface shader. Bear in mind that the values used here are not based on any physical, real world values and are meant only as a starting point for beginners to explore. It is embedded as presets for AiStandardSurface material.
The **Arnold Standard Surface** shader is a physically-based shader capable of producing many types of materials. It includes a diffuse layer, a specular layer with complex Fresnel for metals, specular transmission for glass, subsurface scattering for skin, thin scattering for water and ice, a secondary specular coat, and light emission.
## IBL: Image Based Lighting
Image-based lighting (IBL) is a 3D rendering technique which involves capturing an omnidirectional representation of real-world light information as an image, typically using a specialized camera. This image is then projected onto a dome or sphere analogously to environment mapping, and this is used to simulate the lighting for the objects in the scene. This allows highly detailed real-world lighting to be used to light a scene, instead of trying to accurately model illumination using an existing rendering technique.
Image-based lighting often uses high dynamic range imaging for greater realism, though this is not universal.
### HDRI: High Dynamic Range Image
High-dynamic-range imaging (HDRI) is a high dynamic range (HDR) technique used in imaging and photography to reproduce a greater dynamic range of luminosity that is possible with standard digital imaging or photographic techniques. The aim is to present a similar range of luminance to that experienced through the human visual system.
### Comparison with traditional digital images
Information stored in high-dynamic-range images typically corresponds to the physical values of luminance or radiance that can be observed in the real world. This is different from traditional digital images, which represent colors as they should appear on a monitor or a paper print. Therefore, HDR image formats are often called scene-referred, in contrast to traditional digital images, which are device-referred or output-referred.
HDR images often don't use fixed ranges per color channel—other than traditional images—to represent many more colors over a much wider dynamic range. For that purpose, they don't use integer values to represent the single color channels (e.g., 0-255 in an 8 bit per pixel interval for red, green and blue) but instead use a floating point representation. Common are 16-bit (half precision) or 32-bit floating point numbers to represent HDR pixels.
### Using Arnold SkyDome Light
- To obtain HDRI
- [sIBL Archive](http://www.hdrlabs.com/sibl/archive.html)
Licence: All sIBL-sets on this page, including the images within, are licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 License.
Remember: always mention where you got them from.
- [A light probe image by Paul Debevec and Dan Lemmon](http://ict.debevec.org/~debevec/Probes/)
### Using Arnold Photometric Light
- To obtain IES
- [Visual Photometric Tool™](http://www.visual-3d.com/tools/photometricviewer/)
# Game Texturing
- Recommended reference: [3D Game Textures](https://proquestcombo-safaribooksonline-com.ezproxy.torontopubliclibrary.ca/search?q=3D%20game%20texture), 4th Edition by Luke Ahearn, A K Peters/CRC Press, 2016
- Shader Basics
- The Power of Two and the Grid
- 16×16, 32×32, 64×64, 128×128, 256×256, 512×512, 1024×1024, 2048×2048
- Modular design
- Node-Based Shader Systems
- Assets for a Futuristic Interior
- Game Optimizations
- [Maya shading: from 3D Modeling and Animation course website](https://jiharu.github.io/intm3d/week05.html)
- Understanding what are shading, texturing, and materials.
- Differentiate between different shader types.
- Applying materials with proper textures onto different objects.
## Ambient occlusion
**Ambient occlusion** refers to the attenuation of indirect or diffuse light on an object. It refers to the darker areas of the object such as in creases, cracks, and crevices. Ambient occlusion is caused by indirect light's inability to bounce around and illuminate areas that are blocked by nearby features, that instead absorb the light rays. **These subtle variations in lighting are visual clues for our eyes to detect surface details and distinctions** that would otherwise be washed out and unnoticeable. Ambient occlusion adds realism to your scene by adding shadows in crevices, nooks and crannies, and so on. For each surface point, it calculates how much light is blocked by other geometry.
In the example below, the ice blocks stand out because of the shadowing between them. The cracks between the ice bricks appear darker because the light is blocked by the ice bricks' local geometry.
Applying normal map, © CC BY-SA 3.0
When ambient light is used, objects in your scene may appear to be too bright and geometric detail may become lost. Ambient occlusion solves this problem by subtracting ambient light and thus adding shadowing.
## Creating ambient occlusion textures
There are several ways to apply ambient occlusion.
### Toad objects
You can download the toad object files from here: [toad high resolution](obj/toad.obj), [toad low resolution](obj/toad_low.obj)
### Ambient occulusion using Arnold in Maya
- [Tutorial: Ambient occlusion using render layer.](https://www.youtube.com/watch?v=75JFUwA5XL0)
Or, you can apply the ***aiAmbientOcclusion*** Arnold shader directly to your object.
When you tweak ambient occlusion parameters, please check the [Arnold manual: ambient_occulson](https://support.solidangle.com/display/NodeRef/ambient_occlusion).
Comparison: ambient occlusion surface shading using Mental Ray.
## Baking a texture
You can "bake" lighting, texturing, and shadow information. Command location: in the "Rendering" module, go to Arnold/Utilities/Render Selection To Texture.
### Test image
Image by Haru Ji.
## Creating textures with an occlusion map using Photoshop
- Once the bake is completed open the project file that you specified earlier.
- In that folder, select your baked texture file and open this with Photoshop.
- Drag the Occlusion bake on top of your model's texture layer(s) and select Multiply as the layer blending mode. You may also want to apply a slight Gaussian blur to your occlusion layer, especially if it being used on an organic surface. For hard sharp edged surfaces like this one no blur was applied.
### Creating textures for composition
You can download these images for your rendering practices.
Initial skin map for the color map & ambient / bump map
Color map & specular map.
### Applying baked maps to a high resolution surface.
Texturing on the high-res Toad geometry. All images by Haru Ji.
### Applying baked maps to a low resolution surface to create ***Level of Details***.
Texturing on the low-res Toad geometry.
### Blending different shaders in Arnold
The ***Mix Shader*** shader is used to blend or add two shaders (including light AOVs). It returns a linear interpolation of Shader1 and Shader2 according to the Mix Weight attribute. A Mix Weight value of 0 outputs Shader1, a value of 1 outputs Shader2, and a value of 0.5 mixes evenly between Shader1 and Shader2.
Applying a chequer texture to the ***Mix Weight*** attribute of the ***aiMixShader***.
#### Blending examples
aiWireFrame + aiAmbientOcclusion
aiWireFrame + aiStandardSurface (Jade preset)
- [Arnold manual: mix shader](https://support.solidangle.com/display/A5AFMUG/Mix+Shader)
## Shader application: Substance designer
[Substance Designer](https://www.allegorithmic.com/products/substance-designer) is the 3D Material Authoring and Scan Processing Tool. It has become the standard in the entertainment industry for PBR material authoring.
- [SUBSTANCE SOURCE: SIGNATURE MATERIALS BY DANIEL THIGER](https://www.allegorithmic.com/blog/substance-source-signature-materials-daniel-thiger?utm_source=Allegorithmic+Newsletter&utm_campaign=96259e4370-EMAIL_CAMPAIGN_2018_01_18&utm_medium=email&utm_term=0_2e69063d82-96259e4370-332387901&mc_cid=96259e4370&mc_eid=f39565f470)
- [Daniel Thiger](https://www.artstation.com/dete)