.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/13_shaders/viz_principled_spheres.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_auto_examples_13_shaders_viz_principled_spheres.py>`
        to download the full example code

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_13_shaders_viz_principled_spheres.py:


===============================================================================
Principled BRDF shader on spheres
===============================================================================

The Principled Bidirectional Reflectance Distribution Function ([BRDF]
(https://en.wikipedia.org/wiki/Bidirectional_reflectance_distribution_function)
) was introduced by Brent Burley as part of the [SIGGRAPH 2012 Physically Based
Shading course]
(https://blog.selfshadow.com/publications/s2012-shading-course/). Although it
is not strictly physically based, it was designed so the parameters included
could model materials in the [MERL 100](https://www.merl.com/brdf/) (Material
Exchange and Research Library) database. Moreover, each parameter was
carefully chosen and limited to be easy to use and understand, so that
blending multiple layers together would give intuitive results.

In this demo, we showcase our implementation of the Principled BRDF in FURY.

Let's start by importing the necessary modules:

.. GENERATED FROM PYTHON SOURCE LINES 21-26

.. code-block:: Python


    import numpy as np

    import fury








.. GENERATED FROM PYTHON SOURCE LINES 27-28

Now set up a new scene.

.. GENERATED FROM PYTHON SOURCE LINES 28-32

.. code-block:: Python


    scene = fury.window.Scene()
    scene.background((0.9, 0.9, 0.9))








.. GENERATED FROM PYTHON SOURCE LINES 33-37

Let's define the parameters needed for our demo. In this demo we will see the
effect of each one of the 10 parameters defined by the Principled shader.
For interpretability and usability purposes, each parameter is limited to
values between the range 0 to 1.

.. GENERATED FROM PYTHON SOURCE LINES 37-51

.. code-block:: Python


    material_params = [
        [(1, 1, 1), {"subsurface": 0}],
        [[1, 1, 0], {"metallic": 0}],
        [(1, 0, 0), {"specular": 0}],
        [(1, 0, 0), {"specular_tint": 0, "specular": 1}],
        [(0, 0, 1), {"roughness": 0}],
        [(1, 0, 1), {"anisotropic": 0, "metallic": 0.25, "roughness": 0.5}],
        [[0, 1, 0.5], {"sheen": 0}],
        [(0, 1, 0.5), {"sheen_tint": 0, "sheen": 1}],
        [(0, 1, 1), {"clearcoat": 0}],
        [(0, 1, 1), {"clearcoat_gloss": 0, "clearcoat": 1}],
    ]








.. GENERATED FROM PYTHON SOURCE LINES 52-54

We can start to add our actors to the scene and see how different values of
the parameters produce interesting effects.

.. GENERATED FROM PYTHON SOURCE LINES 54-67

.. code-block:: Python


    for i in range(10):
        center = np.array([[0, -5 * i, 0]])
        for j in range(11):
            center[0][0] = -25 + 5 * j
            sphere = fury.actor.sphere(
                center, colors=material_params[i][0], radii=2, theta=32, phi=32
            )
            keys = list(material_params[i][1])
            material_params[i][1][keys[0]] = np.round(0.1 * j, decimals=1)
            fury.material.manifest_principled(sphere, **material_params[i][1])
            scene.add(sphere)








.. GENERATED FROM PYTHON SOURCE LINES 68-69

Finally, let's add some labels to guide us through our visualization.

.. GENERATED FROM PYTHON SOURCE LINES 69-100

.. code-block:: Python


    labels = [
        "Subsurface",
        "Metallic",
        "Specular",
        "Specular Tint",
        "Roughness",
        "Anisotropic",
        "Sheen",
        "Sheen Tint",
        "Clearcoat",
        "Clearcoat Gloss",
    ]

    for i in range(10):
        pos = [-40, -5 * i, 0]
        label = fury.actor.vector_text(
            text=labels[i], pos=pos, scale=(0.8, 0.8, 0.8), color=(0, 0, 0)
        )
        scene.add(label)

    for j in range(11):
        pos = [-26 + 5 * j, 5, 0]
        label = fury.actor.vector_text(
            text=str(np.round(j * 0.1, decimals=1)),
            pos=pos,
            scale=(0.8, 0.8, 0.8),
            color=(0, 0, 0),
        )
        scene.add(label)








.. GENERATED FROM PYTHON SOURCE LINES 101-102

And visualize our demo.

.. GENERATED FROM PYTHON SOURCE LINES 102-108

.. code-block:: Python


    interactive = False
    if interactive:
        fury.window.show(scene)

    fury.window.record(scene=scene, size=(600, 600), out_path="viz_principled_spheres.png")



.. image-sg:: /auto_examples/13_shaders/images/sphx_glr_viz_principled_spheres_001.png
   :alt: viz principled spheres
   :srcset: /auto_examples/13_shaders/images/sphx_glr_viz_principled_spheres_001.png
   :class: sphx-glr-single-img






.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 0.205 seconds)


.. _sphx_glr_download_auto_examples_13_shaders_viz_principled_spheres.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: viz_principled_spheres.ipynb <viz_principled_spheres.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: viz_principled_spheres.py <viz_principled_spheres.py>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_