-
Notifications
You must be signed in to change notification settings - Fork 264
Description
Summary
Number of hitting rays using an irradiancemeter attached to rectangular shape is too low. How can I ensure that there are hitting rays?
Description
I have a very simple example scene and use a path integrator to render a point emitter, a small scattering disc and a sensor of very small size. As I'm interested in the irradiance, I chose an irradiancemeter as sensor type. I used the depth_integrator.py example to write my own code in Python and count the number of hitting rays (see code below). Unfortunately, due to the setup the number of hitting rays is 0 even though I massively increased the number of pixels per sample.
Due to the desired application of mitsuba for my reasons, I'm interested in using a sensor with no preset sensitivity pattern. I want to determine the overall irradiance on the sensor area. Do you have any suggestions, how I might be able to render this scene in such a way that I can ensure a sufficient number of hitting rays? Should I change the type of sensor?
Code
ray_tracing_example.py
import os
import numpy as np
import enoki as ek
import mitsuba
# Set the desired mitsuba variant
mitsuba.set_variant('scalar_mono')
from mitsuba.core import Float, UInt32, UInt64, Vector2f, Vector3f
from mitsuba.core import Bitmap, Struct, Thread
from mitsuba.core.xml import load_file
from mitsuba.render import ImageBlock
# Relative path to the scene XML file, appended to FileResolvers's search path & loaded into mitsuba
filename = r'mitsuba_scenes/example_us_scene_3.xml'
Thread.thread().file_resolver().append(os.path.dirname(filename))
scene = load_file(filename)
# Instead of calling the scene's integrator, we build our own small integrator
# This integrator simply computes the depth values per pixel
integrator = scene.integrator()
sensors = scene.sensors()
film = sensors[0].film()
sampler = sensors[0].sampler()
film_size = film.crop_size()
spp = 100000000000
# Seed the sampler
total_sample_count = ek.hprod(film_size) * spp
print("total_sample_count: " + str(total_sample_count))
print("sampler.wavefront_size(): " + str(sampler.wavefront_size()))
diff_scale_factor = ek.rsqrt(sampler.sample_count())
if sampler.wavefront_size() != total_sample_count:
sampler.seed(0, total_sample_count)
pos = Vector2f(0,0)
#pos = ek.arange(UInt32, total_sample_count)
#pos //= spp
scale = Vector2f(1.0 / film_size[0], 1.0 / film_size[1])
#pos = Vector2f(float(pos % int(film_size[0])),
# float(pos // int(film_size[0])))
num_hitting_rays = 0
for i in np.linspace(1,total_sample_count):
pos += sampler.next_2d()
# Sample single ray starting from the camera sensor
ray, weight = sensors[0].sample_ray_differential(
time=0,
sample1=sampler.next_1d(),
sample2=pos * scale,
sample3=sampler.next_2d()
)
ray.scale_differential(diff_scale_factor)
(specta,active,aovs) = integrator.sample(scene,sampler,ray,active=True)
if active:
num_hitting_rays += 1
sampler.advance()
print("num_hitting_rays: " + str(num_hitting_rays))
example_us_scene.xml
<scene version="2.0.0">
<!-- Define basic path tracer modeling maximum of 7 scattering events -->
<integrator type="path">
<integer name="max_depth" value="3"/>
</integrator>
<!-- Define emitter-->
<emitter type="point">
<spectrum name="intensity" value="1"/>
<point name="position" x="-0.01" y="0" z="-0.04"/>
</emitter>
<!--emitter type="point">
<spectrum name="intensity" value="1"/>
<point name="position" x="0.01" y="0" z="-0.04"/>
</emitter -->
<!-- Define sensor type at same position as emitter which detects the incoming irradiance-->
<shape type="rectangle">
<!-- Transform sensor type to correct direction -->
<transform name="to_world">
<scale x="0.00001" y="0.00001" />
<translate x="0" y="0" z="-0.04" />
<!-- rotate y="1" angle="-180" /-->
</transform>
<sensor type="irradiancemeter">
<!-- Write to a portable float map containing all luminance values -->
<film type="hdrfilm">
<integer name="width" value="1"/>
<integer name="height" value="1"/>
<string name="pixel_format" value="luminance"/>
<string name="file_format" value="pfm" />
</film>
<!-- Define easiest sampler of sensor for ray tracing-->
<sampler type="independent">
<integer name = "sample_count" value = "100000000000"/>
</sampler>
</sensor>
</shape>
<!-- Add simple scattering disk in origin flipped towards emitter and detector -->
<shape type="disk">
<transform name="to_world">
<scale x="0.001" y="0.001" />
<translate x="0" y="0" z="0" />
</transform>
<boolean name="flip_normals" value="true"/>
<bsdf type="roughdielectric">
<float name="int_ior" value="1.5"/>
<float name="ext_ior" value="1"/>
</bsdf>
</shape>
</scene>