##########################
Physically Based Rendering
##########################

Physically Based Rendering (PBR) is supported as of |HCTHEN| SP1, enabling application developers to provide enhanced rendering realism by calculating the natural interaction of light and materials. PBR materials are created automatically for glTF files converted using the underlying `HOOPS Exchange API <https://docs.techsoft3d.com/exchange/latest/build/classes.html>`_. Currently supported parameters include occlusion, color, alpha mode, metallness, roughness, emissive factor and image based lighting.

By default, image-based lighting is enabled and should be visible on any model converted from glTF. The source image must be a cube map in KTX2 format with a space-separated list of spherical harmonics cooefficients stored under the "sh" metadata key. You can determine whether image-based lighting is enabled for physically-based materials with :ref:`getImageBasedLightingEnabled()  <api_ref/viewing/classes/Communicator.View:getimagebasedlightingenabled>`.

You can load a model containing glTF occlusion maps into the Web Viewer. The additional shading and lighiting will be applied to the texture. When material has an occlusion map, the map will take priority over the screen ambient occlusion.

.. image:: images/occlusion_map_example.png


Metallic and roughness
======================

For a set of nodes, you can set a metallic and roughness factor using :ref:`Communicator.Model.setMetallicRoughness()  <api_ref/viewing/classes/communicator.model:setmetallicroughness>` and retrieve the values with :ref:`Communicator.Model.getMetallicRoughness()  <api_ref/viewing/classes/Communicator.Model:getmetallicroughness>`.


Set metallic and roughness factors
----------------------------------

.. literalinclude:: /../../applications/client/docs/PG_Material_PBR.ts
	   :start-after: //! [set_metallic_roughness]
	   :end-before: //! [set_metallic_roughness]

Providing the root node ID of a model will apply the metallic and roughness factor the the entire model.


Get metallic and roughness factors
----------------------------------

.. literalinclude:: /../../applications/client/docs/PG_Material_PBR.ts
	   :start-after: //! [get_metallic_roughness]
	   :end-before: //! [get_metallic_roughness]

If no values were set, then ``null`` will be returned.
