{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Physically Based Rendering {#pbr_example}\n\nVTK 9 introduced Physically Based Rendering (PBR) and we have exposed\nthat functionality in PyVista. Read the [blog about\nPBR](https://blog.kitware.com/vtk-pbr/) for more details.\n\nPBR is only supported for `pyvista.PolyData`{.interpreted-text\nrole=\"class\"} and can be triggered via the `pbr` keyword argument of\n`add_mesh`. Also use the `metallic` and `roughness` arguments for\nfurther control.\n\nLet\\'s show off this functionality by rendering a high quality mesh of a\nstatue as though it were metallic.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "from itertools import product\n\nimport pyvista as pv\nfrom pyvista import examples\n\n# Load the statue mesh\nmesh = examples.download_nefertiti()\nmesh.rotate_x(-90.0, inplace=True)  # rotate to orient with the skybox\n\n# Download skybox\ncubemap = examples.download_sky_box_cube_map()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Let\\'s render the mesh with a base color of \\\"linen\\\" to give it a metal\nlooking finish.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "p = pv.Plotter()\np.add_actor(cubemap.to_skybox())\np.set_environment_texture(cubemap)  # For reflecting the environment off the mesh\np.add_mesh(mesh, color='linen', pbr=True, metallic=0.8, roughness=0.1, diffuse=1)\n\n# Define a nice camera perspective\ncpos = [(-313.40, 66.09, 1000.61), (0.0, 0.0, 0.0), (0.018, 0.99, -0.06)]\n\np.show(cpos=cpos)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Show the variation of the metallic and roughness parameters.\n\nPlot with metallic increasing from left to right and roughness\nincreasing from bottom to top.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "colors = ['red', 'teal', 'black', 'orange', 'silver']\n\np = pv.Plotter()\np.set_environment_texture(cubemap)\n\nfor i, j in product(range(5), range(6)):\n    sphere = pv.Sphere(radius=0.5, center=(0.0, 4 - i, j))\n    p.add_mesh(sphere, color=colors[i], pbr=True, metallic=i / 4, roughness=j / 5)\n\np.view_vector((-1, 0, 0), (0, 1, 0))\np.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Combine custom lighting and physically based rendering.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# download louis model\nmesh = examples.download_louis_louvre()\nmesh.rotate_z(140, inplace=True)\n\n\nplotter = pv.Plotter(lighting=None)\nplotter.set_background('black')\nplotter.add_mesh(mesh, color='linen', pbr=True, metallic=0.5, roughness=0.5, diffuse=1)\n\n\n# set up lighting\nlight = pv.Light((-2, 2, 0), (0, 0, 0), 'white')\nplotter.add_light(light)\n\nlight = pv.Light((2, 0, 0), (0, 0, 0), (0.7, 0.0862, 0.0549))\nplotter.add_light(light)\n\nlight = pv.Light((0, 0, 10), (0, 0, 0), 'white')\nplotter.add_light(light)\n\n\n# plot with a good camera position\nplotter.camera_position = [(9.51, 13.92, 15.81), (-2.836, -0.93, 10.2), (-0.22, -0.18, 0.959)]\ncpos = plotter.show()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.12.2"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}