==========================
Physically based rendering
==========================

What is PBR?
============

Physically based rendering is a set of rendering techniques which simulate how light and surface materials interact in the natural world. The goal is to create images which are more realistic than traditional shading approaches. PBR relies on lighting - either from your scene, an environment map, or other sources. Visualize uses a preset environment map for rendering.

Since no two real-world materials are exactly alike, a PBR model will allow you to set values for certain characteristics of the model's materials in order to best simulate reality. The characteristics you can control are:

* base color
* metalness
* roughness
* alpha
* emission
* normals
* occlusion

In Visualize, PBR materials are distinct from :ref:`conventional materials <prog_guide/3dgs/05_1_materials_color:Material properties>` you would apply to a model using a color or a texture. PBR materials are set on the segment using ``Set_PBR_Material()``. This function accepts maps or masks for all PBR material parameters, although not all need to be specified. If you don't require a particular material component, simply pass a ``null`` argument.

PBR materials can be used with any model that can be loaded by Visualize. Additionally, Visualize's native HSF file format will save out PBR data if it is present. PBR materials inherit down the segment tree just like any other attribute.

.. only:: standard

	If you have access to HOOPS Exchange, GLTF files can be loaded using the Exchange importer on most platforms. However, on mobile platforms, GLTF data is not available through Exchange and must be loaded using an alternative method, such as HSF.


PBR base properties
===================

The main properties of PBR materials used in Visualize are base color, metalness, and roughness. These can be a general color or factor, and can also be specified with a texture map. Using these three properties you can better simulate plastics, metal, rubber, matte surfaces, and other materials. To truly produce realistic looking models you will need to use maps for the different channels available.

The metalness range runs from 0 (absolutely non-metal) to 1.0 (purely metallic). In reality there are very few materials which are purely 0 or 1.

.. image:: images/metalness.png

*Metalness*

Roughness represents the glossiness or roughness of a model. A value of 1 represents a very rough
object which will have little glossiness, while a value of 0 will represent a very shiny smooth object.

.. image:: images/roughness.png

*Roughness*

See the image below for how metalness and roughness affect the rendering of the object. In the image, metalness ranges from 0 to 1 on the X-axis, and roughness ranges from 0 to 1 on the Y-axis.

.. image:: images/metalx_roughy.png

*Metalness and roughness*


PBR channels and textures
=========================

In addition to these base properties you can add normal maps, emissive maps, and occlusion maps. All
of these combine and interact with your scene’s lighting and environment.

.. image:: images/rover.png

To maximize PBR's capabilities, you will want to use textures for mapping onto different properties.
These include alpha, base color, emissive, metalness, normal, occlusion, and roughness. Using a map
allows you to specify what values are represented on different areas of a model or shell.

.. image:: images/no_channels.png

*Model with base color, metalness, normal, and emissive channels turned off*

The base color map determines how material colors are applied on the surface. This is very similar to
textures used for diffuse colors in non-PBR mode.

.. image:: images/base_channels.png

*The model with only the base color map applied*

.. image:: images/no_base_channels.png

*The model with all channels on except base color map*

A normal map is used to change how light reflects off a surface. Rather than representing holes with
tessellated geometry a normal map can cause the shell to appear to have holes (from the way the light
bounces off the model). It is also used to strongly define edges.

.. image:: images/normals_channels.png

*The model with only the normal mapping turned on*

.. image:: images/no_normals_channels.png

*The model with all channels on except the normal map*

Emissive maps are used to define parts of a shell that give off light. This will be used in the PBRcalculations. They can also act as color channels (eg: they aren’t just used for emitting light). Note that ifthe base color map is unset and there is no base color factor the emissive map will have no effect.

.. image:: images/emissive_channels.png

*The model with only the emissive channel turned on*

.. image:: images/no_emissive_channels.png

*The model with all channels on except the emissive maps*
