Skip to content

Commit

Permalink
Merge branch 'temporal' of https://github.com/LuisaGroup/LuisaRender
Browse files Browse the repository at this point in the history
…into next
  • Loading branch information
Hercier committed Apr 12, 2024
2 parents 1d8e549 + 7c69bda commit bd5a74c
Show file tree
Hide file tree
Showing 11 changed files with 818 additions and 9 deletions.
19 changes: 12 additions & 7 deletions src/base/integrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Integrator::Integrator(Scene *scene, const SceneNodeDesc *desc) noexcept
"sampler", SceneNodeDesc::shared_default_sampler("independent")))},
_light_sampler{scene->load_light_sampler(desc->property_node_or_default(
"light_sampler", SceneNodeDesc::shared_default_light_sampler("uniform")))},
_video{desc->property_bool_or_default("video", false)} {}
_video{desc->property_bool_or_default("video", false)},
_save{desc->property_bool_or_default("save", true)} {}

Integrator::Instance::Instance(Pipeline &pipeline, CommandBuffer &command_buffer, const Integrator *integrator) noexcept
: _pipeline{pipeline}, _integrator{integrator},
Expand Down Expand Up @@ -45,7 +46,9 @@ void ProgressiveIntegrator::Instance::render(Stream &stream) noexcept {
command_buffer << compute::synchronize();
camera->film()->release();
auto film_path = camera->node()->file();
save_image(film_path, reinterpret_cast<const float *>(pixels.data()), resolution);
if (node()->save()) {
save_image(film_path, reinterpret_cast<const float *>(pixels.data()), resolution);
}
}
}

Expand Down Expand Up @@ -117,11 +120,13 @@ void ProgressiveIntegrator::Instance::_render_one_camera(
camera->film()->download(command_buffer, local_pixels.data());
command_buffer << compute::synchronize();
camera->film()->clear(command_buffer);
auto film_path = camera->node()->file();
//film_path is a std::filesystem::path, add number to its name
auto new_name = film_path.stem().string() + std::format("{:05}", shutter_id) + film_path.extension().string();
auto new_film_path = film_path.replace_filename(new_name);
save_image(new_film_path, reinterpret_cast<const float *>(local_pixels.data()), resolution);
if (node()->save()) {
auto film_path = camera->node()->file();
//film_path is a std::filesystem::path, add number to its name
auto new_name = film_path.stem().string() + std::format("{:05}", shutter_id) + film_path.extension().string();
auto new_film_path = film_path.replace_filename(new_name);
save_image(new_film_path, reinterpret_cast<const float *>(local_pixels.data()), resolution);
}
shutter_id++;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/base/integrator.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ class Integrator : public SceneNode {
const Sampler *_sampler;
const LightSampler *_light_sampler;
const bool _video;
const bool _save;
public:
Integrator(Scene *scene, const SceneNodeDesc *desc) noexcept;
[[nodiscard]] auto sampler() const noexcept { return _sampler; }
[[nodiscard]] auto light_sampler() const noexcept { return _light_sampler; }
[[nodiscard]] auto video() const noexcept { return _video; }
[[nodiscard]] auto save() const noexcept { return _save; }
[[nodiscard]] virtual luisa::unique_ptr<Instance> build(
Pipeline &pipeline, CommandBuffer &command_buffer) const noexcept = 0;
};
Expand Down
3 changes: 3 additions & 0 deletions src/base/light.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,15 @@ class Light : public SceneNode {
requires std::is_base_of_v<Light, T>
[[nodiscard]] auto node() const noexcept { return static_cast<const T *>(_light); }
[[nodiscard]] auto &pipeline() const noexcept { return _pipeline; }
[[nodiscard]] virtual float emission_power() const noexcept = 0;
[[nodiscard]] virtual luisa::unique_ptr<Closure> closure(
const SampledWavelengths &swl, Expr<float> time) const noexcept = 0;
};

public:
Light(Scene *scene, const SceneNodeDesc *desc) noexcept;
[[nodiscard]] virtual float scale() const noexcept { return 1.f; }
[[nodiscard]] virtual bool two_sided() const noexcept { return false; }
[[nodiscard]] virtual bool is_null() const noexcept { return false; }
[[nodiscard]] virtual luisa::unique_ptr<Instance> build(
Pipeline &pipeline, CommandBuffer &command_buffer) const noexcept = 0;
Expand Down
1 change: 1 addition & 0 deletions src/base/light_sampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class LightSampler : public SceneNode {
requires std::is_base_of_v<LightSampler, T>
[[nodiscard]] auto node() const noexcept { return static_cast<const T *>(_sampler); }
[[nodiscard]] auto &pipeline() const noexcept { return _pipeline; }
virtual void update(CommandBuffer &command_buffer) noexcept = 0;
[[nodiscard]] virtual Evaluation evaluate_hit(
const Interaction &it, Expr<float3> p_from,
const SampledWavelengths &swl, Expr<float> time) const noexcept = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/base/pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ bool Pipeline::update(CommandBuffer &command_buffer, float time) noexcept {
command_buffer << _transform_matrix_buffer.view(0u, _transforms.size())
.copy_from(_transform_matrices.data());
}
if (updated) {
_integrator->light_sampler()->update(command_buffer);
}
return updated;
}

Expand Down
6 changes: 6 additions & 0 deletions src/films/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ class DisplayInstance final : public Film::Instance {
void release() noexcept override {
while (_window && !_window->should_close()) {
_window->poll_events();
if (_window->is_key_down(Key::KEY_ESCAPE)) {
_window->set_should_close();
}
}
_framebuffer = {};
_swapchain = {};
Expand All @@ -194,6 +197,9 @@ class DisplayInstance final : public Film::Instance {
current_time - _last_frame_time >= interval) {
_last_frame_time = current_time;
_window->poll_events();
if (_window->is_key_down(Key::KEY_ESCAPE)) {
_window->set_should_close();
}
if (_window->should_close()) {
command_buffer << synchronize();
exit(0);// FIXME: exit gracefully
Expand Down
11 changes: 9 additions & 2 deletions src/lights/diffuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class DiffuseLight final : public Light {
"emission", SceneNodeDesc::shared_default_texture("Constant")))},
_scale{std::max(desc->property_float_or_default("scale", 1.0f), 0.0f)},
_two_sided{desc->property_bool_or_default("two_sided", false)} {}
[[nodiscard]] auto scale() const noexcept { return _scale; }
[[nodiscard]] auto two_sided() const noexcept { return _two_sided; }
[[nodiscard]] float scale() const noexcept override { return _scale; }
[[nodiscard]] bool two_sided() const noexcept override { return _two_sided; }
[[nodiscard]] bool is_null() const noexcept override { return _scale == 0.0f || _emission->is_black(); }
[[nodiscard]] luisa::string_view impl_type() const noexcept override { return LUISA_RENDER_PLUGIN_NAME; }
[[nodiscard]] luisa::unique_ptr<Instance> build(
Expand All @@ -43,6 +43,13 @@ class DiffuseLightInstance final : public Light::Instance {
const Texture::Instance *texture) noexcept
: Light::Instance{ppl, light}, _texture{texture} {}
[[nodiscard]] auto texture() const noexcept { return _texture; }
[[nodiscard]] float emission_power() const noexcept override {
auto emission_power = node<DiffuseLight>()->scale();
$if(node<DiffuseLight>()->two_sided()) {
emission_power *= 2.0f;
};
return emission_power;
}
[[nodiscard]] luisa::unique_ptr<Light::Closure> closure(
const SampledWavelengths &swl, Expr<float> time) const noexcept override;
};
Expand Down
2 changes: 2 additions & 0 deletions src/lightsamplers/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
add_library(luisa-render-lightsamplers INTERFACE)
luisa_render_add_plugin(uniform CATEGORY lightsampler SOURCES uniform.cpp)
luisa_render_add_plugin(power CATEGORY lightsampler SOURCES power.cpp)
luisa_render_add_plugin(bvh CATEGORY lightsampler SOURCES bvh.cpp)
Loading

0 comments on commit bd5a74c

Please sign in to comment.