{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Polarized rendering" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Overview\n", "\n", "In spirit, this example is similar to [Mitsuba quickstart][1] but we'll highlight a few things to keep in mind regarding polarization-aware rendering in Mitsuba 3. 🕶\n", "\n", "\n", "
stokes
][1] integrator which means the renderer will output a multichannel image that includes the complete polarization state of the light arriving at the camera, encoded as a Stokes vector.\n",
"\n",
"```\n",
"stokes
][1] integrator outputs many extra channels including the complete polarization state of the light arriving at the camera. This is the reason why the rendered tensorial image contains so many channels. In the following, we construct a [Bitmap
][2] object with the proper channel names in order to write it to a EXR file on disk.\n",
"\n",
"[1]: https://mitsuba.readthedocs.io/en/latest/src/generated/plugins_integrators.html#stokes-vector-integrator-stokes\n",
"[2]: https://mitsuba.readthedocs.io/en/latest/src/api_reference.html#bitmap"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"ExecuteTime": {
"end_time": "2021-09-17T08:31:20.930718Z",
"start_time": "2021-09-17T08:31:20.908971Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"Bitmap[\n",
" pixel_format = multichannel,\n",
" component_format = float32,\n",
" size = [256, 256],\n",
" srgb_gamma = 0,\n",
" struct = Struct<60>[\n",
" float32 R; // @0, premultiplied alpha\n",
" float32 G; // @4, premultiplied alpha\n",
" float32 B; // @8, premultiplied alpha\n",
" float32 S0.R; // @12, premultiplied alpha\n",
" float32 S0.G; // @16, premultiplied alpha\n",
" float32 S0.B; // @20, premultiplied alpha\n",
" float32 S1.R; // @24, premultiplied alpha\n",
" float32 S1.G; // @28, premultiplied alpha\n",
" float32 S1.B; // @32, premultiplied alpha\n",
" float32 S2.R; // @36, premultiplied alpha\n",
" float32 S2.G; // @40, premultiplied alpha\n",
" float32 S2.B; // @44, premultiplied alpha\n",
" float32 S3.R; // @48, premultiplied alpha\n",
" float32 S3.G; // @52, premultiplied alpha\n",
" float32 S3.B; // @56, premultiplied alpha\n",
" ],\n",
" data = [ 3.75 MiB of image data ]\n",
"]"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bitmap = mi.Bitmap(image, channel_names=['R', 'G', 'B'] + scene.integrator().aov_names())\n",
"bitmap.write('cbox_pol_output.exr')\n",
"bitmap"
]
},
{
"cell_type": "markdown",
"metadata": {
"ExecuteTime": {
"end_time": "2021-06-09T09:43:33.169757Z",
"start_time": "2021-06-09T09:43:33.168029Z"
}
},
"source": [
"Note that we could have produced the exact same file by running Mitsuba directly from the command line:\n",
"```\n",
"mitsuba cbox_pol.xml -m \"scalar_spectral_polarized\" -o \"cbox_pol_output.exr\"\n",
"```\n",
"\n",
"This particular Bitmap has 15 (!) channels with the following meanings:\n",
"\n",
"* (**0-3**): The normal color (RGB) (optional alpha (A) channel if requested).\n",
"* (**4-6**): Stokes vector component \"0\", encoding the intensity of the image, i.e. copy of channels 0-2.\n",
"* (**7-9**): Stokes vector component \"1\", encoding horizontal vs. vertical linear polarization as an RGB image.\n",
"* (**10-12**): Stokes vector component \"2\", encoding diagonal linear polarization as an RGB image.\n",
"* (**13-15**): Stokes vector component \"3\", encoding right vs. left circular polarization as an RGB image.\n",
"\n",
"Note that the R, G, and B channels will always be copies of each other in this example as we chose uniform spectra for all materials."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Visualization\n",
"\n",
"A suitable image viewer, such as [TEV][1], can be used to inspect the written .exr file. To read the file in again using the Mitsuba Python bindings, we can split the multichannel bitmap image into a list of 3-channel `Bitmap`s using the [split()
][2] method.\n",
"\n",
"[1]: https://github.com/Tom94/tev\n",
"[2]: https://mitsuba.readthedocs.io/en/latest/src/api_reference.html#mitsuba.Bitmap.split"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"ExecuteTime": {
"end_time": "2021-09-17T08:35:59.935173Z",
"start_time": "2021-09-17T08:35:59.924589Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"dict_keys(['