==========================
Physically-based Rendering
==========================

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. |HPSNOW| uses a preset environment map for rendering.

Since no two real-world materials are exactly alike, a segment with PBR attributes will allow you to set values for certain characteristics of the model's materials in order to best simulate reality. To this end, |HPSNOW| allows you to control the following properties:

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

In |HPSNOW|, PBR materials are distinct from :doc:`conventional materials <0501_materials_introduction>` you would apply to a model using a ``HPS::MaterialKit``. PBR materials are set on the segment using a ``HPS::PBRMaterialKit``, and they inherit just like any other attribute.

.. tabs::

	.. group-tab:: C++
	
		.. literalinclude:: ../../../internals/tests/docs/source/cpp/00700_pbr.cpp
		   :start-after: //! [pbrmaterialkit]
		   :end-before: //! [pbrmaterialkit]
		   
	.. group-tab:: C#

		.. literalinclude:: ../../../internals/tests/docs/source/cs/00700_pbr.cs
		   :start-after: //! [pbrmaterialkit]
		   :end-before: //! [pbrmaterialkit]
		   
PBR materials can be used with any model that can be loaded by |HPSNOW|. Additionally, the application's native HSF file format will save out PBR data if it is present.

.. only:: not spatial

	If you have access to HOOPS Exchange, GLTF files can be loaded using the Exchange importer.


.. _pbr_base_props:

PBR Base Properties
===================

The main properties of PBR materials used in |HPSNOW| 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:

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 PBR calculations. They can also act as color channels (eg: they aren’t just used for emitting light). Note that if the 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 all channels on except the normal map*

.. image:: images/no_emissive_channels.png

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


.. _pbr_highlighting:

PBR Highlighting
================

When using a model with PBR attributes, traditional highlighting doesn't always make sense. This is because traditional highlighting replaces the geometry color with a flat filled color. With a PBR model, that would degrade the data, since bump maps, texturing, etc. would no longer be visible. Thus, |HPSNOW| will automatically use "tinting" in place of traditional highlighting whenever the segment has an associated ``HPS::PBRMaterialKit``. The :doc:`highlight style <0604_highlighting>` itself is enabled the same way as traditional highlighting, and the face color will be used as the tinting color.

.. image:: images/pbr_tinting.png

*A normal wheel (top) and a wheel tinted with a PBR highlight (bottom)*
