
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "tutorial/03_figures/bonus/d_pbr.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

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

        :ref:`Go to the end <sphx_glr_download_tutorial_03_figures_bonus_d_pbr.py>`
        to download the full example code. or to run this example in your browser via Binder

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

.. _sphx_glr_tutorial_03_figures_bonus_d_pbr.py:


.. _pbr_example:

Physically Based Rendering
~~~~~~~~~~~~~~~~~~~~~~~~~~

VTK 9 introduced Physically Based Rendering (PBR) and we have exposed
that functionality in PyVista. Read the `blog about PBR
<https://blog.kitware.com/vtk-pbr/>`_ for more details.

PBR is only supported for :class:`pyvista.PolyData` and can be
triggered via the ``pbr`` keyword argument of ``add_mesh``. Also use
the ``metallic`` and ``roughness`` arguments for further control.

Let's show off this functionality by rendering a high quality mesh of
a statue as though it were metallic.

.. GENERATED FROM PYTHON SOURCE LINES 19-33

.. code-block:: Python


    from itertools import product

    import pyvista as pv
    from pyvista import examples

    # Load the statue mesh
    mesh = examples.download_nefertiti()
    mesh.rotate_x(-90.0, inplace=True)  # rotate to orient with the skybox

    # Download skybox
    cubemap = examples.download_sky_box_cube_map()









.. GENERATED FROM PYTHON SOURCE LINES 34-36

Let's render the mesh with a base color of "linen" to give it a metal looking
finish.

.. GENERATED FROM PYTHON SOURCE LINES 36-47

.. code-block:: Python

    pl = pv.Plotter()
    pl.add_actor(cubemap.to_skybox())
    pl.set_environment_texture(cubemap)  # For reflecting the environment off the mesh
    pl.add_mesh(mesh, color="linen", pbr=True, metallic=0.8, roughness=0.1, diffuse=1)

    # Define a nice camera perspective
    cpos = [(-313.40, 66.09, 1000.61), (0.0, 0.0, 0.0), (0.018, 0.99, -0.06)]

    pl.show(cpos=cpos)









.. tab-set::



   .. tab-item:: Static Scene



            
     .. image-sg:: /tutorial/03_figures/bonus/images/sphx_glr_d_pbr_001.png
        :alt: d pbr
        :srcset: /tutorial/03_figures/bonus/images/sphx_glr_d_pbr_001.png
        :class: sphx-glr-single-img
     


   .. tab-item:: Interactive Scene



       .. offlineviewer:: /home/runner/work/pyvista-tutorial/pyvista-tutorial/doc/source/tutorial/03_figures/bonus/images/sphx_glr_d_pbr_001.vtksz






.. GENERATED FROM PYTHON SOURCE LINES 48-52

Show the variation of the metallic and roughness parameters.

Plot with metallic increasing from left to right and roughness
increasing from bottom to top.

.. GENERATED FROM PYTHON SOURCE LINES 52-66

.. code-block:: Python


    colors = ["red", "teal", "black", "orange", "silver"]

    pl = pv.Plotter()
    pl.set_environment_texture(cubemap)

    for i, j in product(range(5), range(6)):
        sphere = pv.Sphere(radius=0.5, center=(0.0, 4 - i, j))
        pl.add_mesh(sphere, color=colors[i], pbr=True, metallic=i / 4, roughness=j / 5)

    pl.view_vector((-1, 0, 0), (0, 1, 0))
    pl.show()









.. tab-set::



   .. tab-item:: Static Scene



            
     .. image-sg:: /tutorial/03_figures/bonus/images/sphx_glr_d_pbr_002.png
        :alt: d pbr
        :srcset: /tutorial/03_figures/bonus/images/sphx_glr_d_pbr_002.png
        :class: sphx-glr-single-img
     


   .. tab-item:: Interactive Scene



       .. offlineviewer:: /home/runner/work/pyvista-tutorial/pyvista-tutorial/doc/source/tutorial/03_figures/bonus/images/sphx_glr_d_pbr_002.vtksz






.. GENERATED FROM PYTHON SOURCE LINES 67-68

Combine custom lighting and physically based rendering.

.. GENERATED FROM PYTHON SOURCE LINES 68-94

.. code-block:: Python


    # download louis model
    mesh = examples.download_louis_louvre()
    mesh.rotate_z(140, inplace=True)


    plotter = pv.Plotter(lighting=None)
    plotter.set_background("black")
    plotter.add_mesh(mesh, color="linen", pbr=True, metallic=0.5, roughness=0.5, diffuse=1)


    # set up lighting
    light = pv.Light((-2, 2, 0), (0, 0, 0), "white")
    plotter.add_light(light)

    light = pv.Light((2, 0, 0), (0, 0, 0), (0.7, 0.0862, 0.0549))
    plotter.add_light(light)

    light = pv.Light((0, 0, 10), (0, 0, 0), "white")
    plotter.add_light(light)


    # plot with a good camera position
    plotter.camera_position = [(9.51, 13.92, 15.81), (-2.836, -0.93, 10.2), (-0.22, -0.18, 0.959)]
    cpos = plotter.show()








.. tab-set::



   .. tab-item:: Static Scene



            
     .. image-sg:: /tutorial/03_figures/bonus/images/sphx_glr_d_pbr_003.png
        :alt: d pbr
        :srcset: /tutorial/03_figures/bonus/images/sphx_glr_d_pbr_003.png
        :class: sphx-glr-single-img
     


   .. tab-item:: Interactive Scene



       .. offlineviewer:: /home/runner/work/pyvista-tutorial/pyvista-tutorial/doc/source/tutorial/03_figures/bonus/images/sphx_glr_d_pbr_003.vtksz



.. rst-class:: sphx-glr-script-out

 .. code-block:: none

    /opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/pyvista/core/utilities/misc.py:289: PyVistaDeprecationWarning: 
    ../../../../../../../../opt/hostedtoolcache/Python/3.12.13/x64/lib/python3.12/site-packages/pyvista/core/utilities/misc.py:289: Arguments 'position', 'focal_point', 'color' must be passed as keyword arguments to function 'Light.__init__'.
    From version 0.50, passing these as positional arguments will result in a TypeError.
      obj = super().__call__(*args, **kwargs)  # type: ignore[misc]




.. GENERATED FROM PYTHON SOURCE LINES 95-102

.. raw:: html

    <center>
      <a target="_blank" href="https://colab.research.google.com/github/pyvista/pyvista-tutorial/blob/gh-pages/notebooks/tutorial/03_figures/bonus/d_pbr.ipynb">
        <img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/ width="150px">
      </a>
    </center>


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

   **Total running time of the script:** (1 minutes 21.652 seconds)


.. _sphx_glr_download_tutorial_03_figures_bonus_d_pbr.py:

.. only:: html

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

    .. container:: binder-badge

      .. image:: images/binder_badge_logo.svg
        :target: https://mybinder.org/v2/gh/pyvista/pyvista-tutorial/gh-pages?urlpath=lab/tree/notebooks/tutorial/03_figures/bonus/d_pbr.ipynb
        :alt: Launch binder
        :width: 150 px

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

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

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

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

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: d_pbr.zip <d_pbr.zip>`


.. only:: html

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

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