def test01_construct(variant_scalar_rgb): from mitsuba.core.xml import load_string from mitsuba.render import ImageBlock im = ImageBlock([33, 12], 4) assert im is not None assert ek.all(im.offset() == 0) im.set_offset([10, 20]) assert ek.all(im.offset() == [10, 20]) assert ek.all(im.size() == [33, 12]) assert im.warn_invalid() assert im.border_size() == 0 # Since there's no reconstruction filter assert im.channel_count() == 4 assert im.data() is not None rfilter = load_string("""<rfilter version="2.0.0" type="gaussian"> <float name="stddev" value="15"/> </rfilter>""") im = ImageBlock([10, 11], 2, filter=rfilter, warn_invalid=False) assert im.border_size() == rfilter.border_size() assert im.channel_count() == 2 assert not im.warn_invalid() im = ImageBlock([10, 11], 6) assert im is not None im.channel_count() == 6
sample3=0) # Intersect rays with the scene geometry surface_interaction = scene.ray_intersect(rays) # Given intersection, compute the final pixel values as the depth t # of the sampled surface interaction result = surface_interaction.t # Set to zero if no intersection was found result[~surface_interaction.is_valid()] = 0 block = ImageBlock(film.crop_size(), channel_count=5, filter=film.reconstruction_filter(), border=False) block.clear() # ImageBlock expects RGB values (Array of size (n, 3)) block.put(position_sample, rays.wavelengths, Vector3f(result, result, result), 1) # Write out the result from the ImageBlock # Internally, ImageBlock stores values in XYZAW format # (color XYZ, alpha value A and weight W) xyzaw_np = block.data().reshape([film_size[1], film_size[0], 5]) # We then create a Bitmap from these values and save it out as EXR file bmp = Bitmap(xyzaw_np, Bitmap.PixelFormat.XYZAW) bmp = bmp.convert(Bitmap.PixelFormat.Y, Struct.Type.Float32, srgb_gamma=False) bmp.write('depth.exr')
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)
dragon_c = scene.shapes()[6].bbox().center() c = Vector3f(dragon_c) d = c - surface_interaction.p result = ek.norm(d) max_dist = ek.hmax(result) result /= max_dist result = 0.3 * (1.0 - result**(2.0)) result[~surface_interaction.is_valid()] = 0 block = ImageBlock(film.crop_size(), channel_count=5, filter=film.reconstruction_filter(), border=False) block.clear() # ImageBlock expects RGB values (Array of size (n, 3)) block.put(pos, rays.wavelengths, Vector3f(result, result, result), 1) # Write out the result from the ImageBlock # Internally, ImageBlock stores values in XYZAW format # (color XYZ, alpha value A and weight W) xyzaw_np = np.array(block.data()).reshape([film_size[1], film_size[0], 5]) # We then create a Bitmap from these values and save it out as EXR file bmp = Bitmap(xyzaw_np, Bitmap.PixelFormat.XYZAW) bmp = bmp.convert(Bitmap.PixelFormat.RGBA, Struct.Type.Float32, srgb_gamma=False) bmp.write('distance.exr')