def test06_put_values_basic(variant_scalar_spectral): from mitsuba.core import spectrum_to_xyz, MTS_WAVELENGTH_SAMPLES from mitsuba.core.xml import load_string from mitsuba.render import ImageBlock # Recall that we must pass a reconstruction filter to use the `put` methods. rfilter = load_string("""<rfilter version="2.0.0" type="box"> <float name="radius" value="0.4"/> </rfilter>""") im = ImageBlock([10, 8], 5, filter=rfilter) im.clear() # From a spectrum & alpha value border = im.border_size() ref = np.zeros(shape=(im.height() + 2 * border, im.width() + 2 * border, 3 + 1 + 1)) for i in range(border, im.height() + border): for j in range(border, im.width() + border): wavelengths = np.random.uniform(size=(MTS_WAVELENGTH_SAMPLES, ), low=350, high=750) spectrum = np.random.uniform(size=(MTS_WAVELENGTH_SAMPLES, )) ref[i, j, :3] = spectrum_to_xyz(spectrum, wavelengths) ref[i, j, 3] = 1 # Alpha ref[i, j, 4] = 1 # Weight # To avoid the effects of the reconstruction filter (simpler test), # we'll just add one sample right in the center of each pixel. im.put([j + 0.5, i + 0.5], wavelengths, spectrum, alpha=1.0) check_value(im, ref, atol=1e-6)
def _render_helper(scene, spp=None, sensor_index=0): """ Internally used function: render the specified Mitsuba scene and return a floating point array containing RGB values and AOVs, if applicable """ from mitsuba.core import (Float, UInt32, UInt64, Vector2f, is_monochromatic, is_rgb, is_polarized) from mitsuba.render import ImageBlock sensor = scene.sensors()[sensor_index] film = sensor.film() sampler = sensor.sampler() film_size = film.crop_size() if spp is None: spp = sampler.sample_count() total_sample_count = ek.hprod(film_size) * spp if sampler.wavefront_size() != total_sample_count: sampler.seed(ek.arange(UInt64, total_sample_count)) 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]))) pos += sampler.next_2d() rays, weights = sensor.sample_ray_differential( time=0, sample1=sampler.next_1d(), sample2=pos * scale, sample3=0 ) spec, mask, aovs = scene.integrator().sample(scene, sampler, rays) spec *= weights del mask if is_polarized: from mitsuba.core import depolarize spec = depolarize(spec) if is_monochromatic: rgb = [spec[0]] elif is_rgb: rgb = spec else: from mitsuba.core import spectrum_to_xyz, xyz_to_srgb xyz = spectrum_to_xyz(spec, rays.wavelengths) rgb = xyz_to_srgb(xyz) del xyz aovs.insert(0, Float(1.0)) for i in range(len(rgb)): aovs.insert(i + 1, rgb[i]) del rgb, spec, weights, rays block = ImageBlock( size=film.crop_size(), channel_count=len(aovs), filter=film.reconstruction_filter(), warn_negative=False, warn_invalid=False, border=False ) block.clear() block.put(pos, aovs) del pos del aovs data = block.data() ch = block.channel_count() i = UInt32.arange(ek.hprod(block.size()) * (ch - 1)) weight_idx = i // (ch - 1) * ch values_idx = (i * ch) // (ch - 1) + 1 weight = ek.gather(data, weight_idx) values = ek.gather(data, values_idx) return values / (weight + 1e-8)