Skip to content

Commit

Permalink
Fix high quality edges and python integrators
Browse files Browse the repository at this point in the history
  • Loading branch information
Speierers committed Nov 11, 2021
1 parent f0ce53e commit 545157b
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 26 deletions.
4 changes: 0 additions & 4 deletions include/mitsuba/render/spiral.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ class MTS_EXPORT_RENDER Spiral : public Object {
/// Create a new spiral generator for the given size, offset into a larger frame, and block size
Spiral(Vector2i size, Vector2i offset, size_t block_size, size_t passes = 1);

template <typename Film>
Spiral(const Film &film, size_t block_size, size_t passes = 1)
: Spiral(film->crop_size(), film->crop_offset(), block_size, passes) {}

/// Return the maximum block size
size_t max_block_size() const { return m_block_size; }

Expand Down
30 changes: 18 additions & 12 deletions src/librender/integrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ SamplingIntegrator<Float, Spectrum>::render(Scene *scene,

ref<Film> film = sensor->film();
ScalarVector2i film_size = film->crop_size();
if (film->has_high_quality_edges())
film_size += 2 * film->reconstruction_filter()->border_size();

size_t total_spp = sensor->sampler()->sample_count();
size_t samples_per_pass = (m_samples_per_pass == (size_t) -1)
Expand Down Expand Up @@ -115,7 +117,7 @@ SamplingIntegrator<Float, Spectrum>::render(Scene *scene,
m_block_size = block_size;
}

Spiral spiral(film, m_block_size, n_passes);
Spiral spiral(film_size, film->crop_offset(), m_block_size, n_passes);

ThreadEnvironment env;
ref<ProgressReporter> progress = new ProgressReporter("Rendering");
Expand All @@ -135,13 +137,20 @@ SamplingIntegrator<Float, Spectrum>::render(Scene *scene,
ref<ImageBlock> block = new ImageBlock(
m_block_size, channels.size(),
film->reconstruction_filter(),
/* warn_negative */ !has_aovs && !is_spectral_v<Spectrum>);
!has_aovs && !is_spectral_v<Spectrum> /* warn_negative */,
std::is_scalar_v<Float> /* warn_invalid */,
true /* border */,
false /* normalize */);
std::unique_ptr<Float[]> aovs(new Float[channels.size()]);

// For each block
for (auto i = range.begin(); i != range.end() && !should_stop(); ++i) {
auto [offset, size, block_id] = spiral.next_block();
Assert(ek::hprod(size) != 0);

if (film->has_high_quality_edges())
offset -= film->reconstruction_filter()->border_size();

block->set_size(size);
block->set_offset(offset);

Expand Down Expand Up @@ -175,7 +184,8 @@ SamplingIntegrator<Float, Spectrum>::render(Scene *scene,
if (samples_per_pass != 1)
idx /= (uint32_t) samples_per_pass;

ref<ImageBlock> block = new ImageBlock(film_size, channels.size(),
ref<ImageBlock> block = new ImageBlock(film->crop_size(),
channels.size(),
film->reconstruction_filter(),
false /* warn_negative */,
false /* warn_invalid */,
Expand All @@ -187,6 +197,9 @@ SamplingIntegrator<Float, Spectrum>::render(Scene *scene,
Float(idx / uint32_t(film_size[0])));
std::vector<Float> aovs(channels.size());

if (film->has_high_quality_edges())
pos -= film->reconstruction_filter()->border_size();

Timer timer;
for (size_t i = 0; i < n_passes; i++) {
render_sample(scene, sensor, sampler, block, aovs.data(),
Expand Down Expand Up @@ -321,16 +334,9 @@ SamplingIntegrator<Float, Spectrum>::render_sample(const Scene *scene,
Float wavelength_sample = sampler->next_1d(active);

const Film *film = sensor->film();
ScalarVector2i size = film->crop_size();
ScalarVector2i offset = film->crop_offset();

if (film->has_high_quality_edges()) {
uint32_t border_size = film->reconstruction_filter()->border_size();
position_sample -= border_size;
position_sample *= Vector2f(size + 2 * border_size) / size;
}

Vector2f adjusted_position = (position_sample - offset) / size;
Vector2f adjusted_position =
(position_sample - film->crop_offset()) / film->crop_size();

auto [ray, ray_weight] = sensor->sample_ray_differential(
time, wavelength_sample, adjusted_position, aperture_sample);
Expand Down
15 changes: 9 additions & 6 deletions src/python/python/ad/integrators/integrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,12 @@ def sample_sensor_rays(sensor):
film = sensor.film()
sampler = sensor.sampler()
film_size = film.crop_size()
spp = sampler.sample_count()
border_size = film.reconstruction_filter().border_size()

if film.has_high_quality_edges():
film_size += 2 * border_size

spp = sampler.sample_count()
total_sample_count = ek.hprod(film_size) * spp

assert sampler.wavefront_size() == total_sample_count
Expand All @@ -116,15 +120,14 @@ def sample_sensor_rays(sensor):
pos_idx //= ek.opaque(UInt32, spp)
pos = Vector2f(Float(pos_idx % int(film_size[0])),
Float(pos_idx // int(film_size[0])))
pos += film.crop_offset()
pos += sampler.next_2d()

if film.has_high_quality_edges():
border_size = film.reconstruction_filter().border_size()
pos -= border_size
pos *= Vector2f(film_size + 2 * border_size) / Vector2f(film_size)

adjusted_pos = (pos - film.crop_offset()) / Vector2f(film_size)
pos += film.crop_offset()
pos += sampler.next_2d()

adjusted_pos = (pos - film.crop_offset()) / Vector2f(film.crop_size())

rays, weights = sensor.sample_ray_differential(
time=0.0,
Expand Down
8 changes: 6 additions & 2 deletions src/python/python/ad/integrators/prb.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ def render_backward(self: mitsuba.render.SamplingIntegrator,
seed: int,
sensor_index: int = 0,
spp: int = 0) -> None:

sensor = scene.sensors()[sensor_index]
rfilter = sensor.film().reconstruction_filter()
sampler = sensor.sampler()
if spp > 0:
sampler.set_sample_count(spp)
spp = sampler.sample_count()
sampler.seed(seed, ek.hprod(sensor.film().crop_size()) * spp)

film_size = sensor.film().crop_size()
if sensor.film().has_high_quality_edges():
film_size += 2 * rfilter.border_size()

sampler.seed(seed, ek.hprod(film_size) * spp)

ray, weight, pos, _ = sample_sensor_rays(sensor)

Expand Down
7 changes: 6 additions & 1 deletion src/python/python/ad/integrators/prbvolpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ def render_backward(self: mitsuba.render.SamplingIntegrator,
if spp > 0:
sampler.set_sample_count(spp)
spp = sampler.sample_count()
sampler.seed(seed, ek.hprod(sensor.film().crop_size()) * spp)

film_size = sensor.film().crop_size()
if sensor.film().has_high_quality_edges():
film_size += 2 * rfilter.border_size()

sampler.seed(seed, ek.hprod(film_size) * spp)

ray, weight, pos, _ = sample_sensor_rays(sensor)

Expand Down
7 changes: 6 additions & 1 deletion src/python/python/ad/integrators/rb.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ def render_backward(self: mitsuba.render.SamplingIntegrator,
if spp > 0:
sampler.set_sample_count(spp)
spp = sampler.sample_count()
sampler.seed(seed, ek.hprod(sensor.film().crop_size()) * spp)

film_size = sensor.film().crop_size()
if sensor.film().has_high_quality_edges():
film_size += 2 * rfilter.border_size()

sampler.seed(seed, ek.hprod(film_size) * spp)

ray, weight, pos, _ = sample_sensor_rays(sensor)

Expand Down

0 comments on commit 545157b

Please sign in to comment.