Skip to content

Instantly share code, notes, and snippets.

@Head-on-a-Stick Head-on-a-Stick/box.md
Last active Nov 12, 2018

Embed
What would you like to do?
Cornell Box (+balls) for Mitsuba

This is the balls.xml scene file:

<scene version="0.6.0">

   <integrator type="volpath">
      <integer name="maxDepth" value="16"/>
   </integrator>

   <!-- stuff -->

   <shape type="sphere">
      <bsdf type="dielectric"/>
      <medium type="homogeneous" name="interior">
         <rgb name="sigmaS" value="0, 0, 0"/>
         <rgb name="sigmaA" value="0.5, 0.5, 0"/>
      </medium>
      <transform name="toWorld">
         <translate x="0" y="-3" z="1.25"/>
         <scale value="1.5"/>
      </transform>
   </shape>
   <shape type="sphere">
      <bsdf type="conductor">
         <string name="material" value="Cr"/>
      </bsdf>
      <transform name="toWorld">
         <translate x="1.5" y="0.75" z="1"/>
         <scale value="2.5"/>
      </transform>
   </shape>
   <shape type="sphere">
      <bsdf type="blendbsdf">
         <texture name="weight" type="bitmap">
            <string name="filename" value="swirl.png"/>
            <float name="uscale" value="2"/>
         </texture>
         <bsdf type="roughplastic">
            <srgb name="diffuseReflectance" value="#ff0000"/>
         </bsdf>
         <bsdf type="plastic"/>
      </bsdf>
      <transform name="toWorld">
         <translate x="-1.5" y="0" z="1"/>
         <scale value="2"/>
      </transform>
   </shape>
   
   <!-- box -->

   <shape type="rectangle">
      <bsdf type="diffuse">
         <texture name="reflectance" type="checkerboard">
            <float name="uvscale" value="4"/>
          </texture>
      </bsdf>
      <transform name="toWorld">
         <scale value="8"/>
      </transform>
   </shape>
   <shape type="rectangle">
      <bsdf type="diffuse">
         <srgb name="reflectance" value="#ffffff"/>
      </bsdf>
      <transform name="toWorld">
         <scale value="8"/>
         <rotate x="1" angle="180"/>
         <translate z="10"/>
      </transform>
   </shape>
   <shape type="rectangle">
      <bsdf type="diffuse">
         <srgb name="reflectance" value="#44ff44"/>
      </bsdf>
      <transform name="toWorld">
         <scale x="5" y="8"/>
         <rotate y="1" angle="270"/>
         <translate x="8" z="5"/>
      </transform>
   </shape>
   <shape type="rectangle">
      <bsdf type="diffuse">
         <srgb name="reflectance" value="#ff4444"/>
      </bsdf>
      <transform name="toWorld">
         <scale x="5" y="8"/>
         <rotate y="1" angle="90"/>
         <translate x="-8" z="5"/>
      </transform>
   </shape>
   <shape type="rectangle">
      <bsdf type="diffuse">
         <srgb name="reflectance" value="#ffffff"/>
      </bsdf>
      <transform name="toWorld">
         <scale x="8" y="5"/>
         <rotate x="1" angle="90"/>
         <translate y="8" z="5"/>
      </transform>
   </shape>

   <!-- light -->
   
   <shape type="rectangle">
      <transform name="toWorld">
         <scale z="-1"/>
         <translate z="10"/>
      </transform>
      <emitter type="area">
         <spectrum name="radiance" value="50"/>
      </emitter>
   </shape>

   <!-- camera -->
   
   <sensor type="perspective">
      <transform name="toWorld">
         <lookat origin="0,-29.5,5" target="0,0,5" up="0,0,1"/>
      </transform>
      <sampler type="sobol">
         <integer name="sampleCount" value="$s"/>
      </sampler>
      <film type="hdrfilm">
         <integer name="width" value="$w"/>
         <integer name="height" value="$h"/>
      </film>
   </sensor>

</scene>

Generate the scene with mitsuba -Ds=$sample -Dw=$width -Dh=$height balls.xml, replace $sample with the number of samples per pixel (always use a power of two), and replace $width & $height with the desired width & height of the balls.exr image.

Then use mtsutil tonemap balls.exr to generate a PNG image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.