WIP Make shadows visible for Storm delegate #80

Closed
Vasyl Pidhirskyi wants to merge 16 commits from Vasyl-Pidhirskyi/blender_bn:BLEN-469 into hydra-render

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
5 changed files with 37 additions and 0 deletions
Showing only changes of commit 832090903e - Show all commits

View File

@ -44,6 +44,7 @@ class HydraSceneDelegate : public pxr::HdSceneDelegate {
std::string studiolight_name; std::string studiolight_name;
float studiolight_rotation; float studiolight_rotation;
float studiolight_intensity; float studiolight_intensity;
bool use_storm_shadows = false;
Vasyl-Pidhirskyi marked this conversation as resolved Outdated

This parameter not needed, instead create function like HydraSceneDelegate::has_shadows()

This parameter not needed, instead create function like `HydraSceneDelegate::has_shadows()`
bool operator==(const ShadingSettings &other); bool operator==(const ShadingSettings &other);
}; };

View File

@ -52,6 +52,7 @@ void FinalEngine::render(Depsgraph *depsgraph)
render_task_delegate_->set_viewport(pxr::GfVec4d(0, 0, resolution_[0], resolution_[1])); render_task_delegate_->set_viewport(pxr::GfVec4d(0, 0, resolution_[0], resolution_[1]));
if (light_tasks_delegate_) { if (light_tasks_delegate_) {
light_tasks_delegate_->set_viewport(pxr::GfVec4d(0, 0, resolution_[0], resolution_[1])); light_tasks_delegate_->set_viewport(pxr::GfVec4d(0, 0, resolution_[0], resolution_[1]));
light_tasks_delegate_->set_shadows(hydra_scene_delegate_->shading_settings.use_storm_shadows);
} }
render_task_delegate_->add_aov(pxr::HdAovTokens->color); render_task_delegate_->add_aov(pxr::HdAovTokens->color);
@ -63,6 +64,7 @@ void FinalEngine::render(Depsgraph *depsgraph)
tasks.push_back(light_tasks_delegate_->skydome_task()); tasks.push_back(light_tasks_delegate_->skydome_task());
} }
tasks.push_back(light_tasks_delegate_->simple_task()); tasks.push_back(light_tasks_delegate_->simple_task());
tasks.push_back(light_tasks_delegate_->shadow_task());
} }
tasks.push_back(render_task_delegate_->task()); tasks.push_back(render_task_delegate_->task());

View File

@ -13,6 +13,8 @@ LightTasksDelegate::LightTasksDelegate(pxr::HdRenderIndex *parent_index,
GetRenderIndex().InsertTask<pxr::HdxSimpleLightTask>(this, simple_task_id_); GetRenderIndex().InsertTask<pxr::HdxSimpleLightTask>(this, simple_task_id_);
skydome_task_id_ = GetDelegateID().AppendElementString("skydomeTask"); skydome_task_id_ = GetDelegateID().AppendElementString("skydomeTask");
GetRenderIndex().InsertTask<pxr::HdxSkydomeTask>(this, skydome_task_id_); GetRenderIndex().InsertTask<pxr::HdxSkydomeTask>(this, skydome_task_id_);
shadow_task_id_ = GetDelegateID().AppendElementString("shadowTask");
GetRenderIndex().InsertTask<pxr::HdxShadowTask>(this, shadow_task_id_);
} }
pxr::VtValue LightTasksDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key) pxr::VtValue LightTasksDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const &key)
@ -24,6 +26,9 @@ pxr::VtValue LightTasksDelegate::Get(pxr::SdfPath const &id, pxr::TfToken const
else if (id == skydome_task_id_) { else if (id == skydome_task_id_) {
return pxr::VtValue(skydome_task_params_); return pxr::VtValue(skydome_task_params_);
} }
else if (id == shadow_task_id_) {
return pxr::VtValue(shadow_task_params_);
}
} }
return pxr::VtValue(); return pxr::VtValue();
} }
@ -33,6 +38,11 @@ pxr::HdTaskSharedPtr LightTasksDelegate::simple_task()
return GetRenderIndex().GetTask(simple_task_id_); return GetRenderIndex().GetTask(simple_task_id_);
} }
pxr::HdTaskSharedPtr LightTasksDelegate::shadow_task()
{
return GetRenderIndex().GetTask(shadow_task_id_);
}
pxr::HdTaskSharedPtr LightTasksDelegate::skydome_task() pxr::HdTaskSharedPtr LightTasksDelegate::skydome_task()
{ {
/* Note that this task is intended to be the first "Render Task", /* Note that this task is intended to be the first "Render Task",
@ -52,6 +62,23 @@ void LightTasksDelegate::set_camera(pxr::SdfPath const &camera_id)
skydome_task_params_.camera = camera_id; skydome_task_params_.camera = camera_id;
GetRenderIndex().GetChangeTracker().MarkTaskDirty(skydome_task_id_, GetRenderIndex().GetChangeTracker().MarkTaskDirty(skydome_task_id_,
pxr::HdChangeTracker::DirtyParams); pxr::HdChangeTracker::DirtyParams);
GetRenderIndex().GetChangeTracker().MarkTaskDirty(shadow_task_id_,
pxr::HdChangeTracker::DirtyParams);
}
void LightTasksDelegate::set_shadows(bool const &enable_shadows)
{
if (simple_task_params_.enableShadows == enable_shadows) {
return;
}
shadow_task_params_.depthBiasEnable = true;
simple_task_params_.enableShadows = enable_shadows;
GetRenderIndex().GetChangeTracker().MarkTaskDirty(simple_task_id_,
pxr::HdChangeTracker::DirtyParams);
GetRenderIndex().GetChangeTracker().MarkTaskDirty(shadow_task_id_,
pxr::HdChangeTracker::DirtyParams);
} }
void LightTasksDelegate::set_viewport(pxr::GfVec4d const &viewport) void LightTasksDelegate::set_viewport(pxr::GfVec4d const &viewport)

View File

@ -4,6 +4,7 @@
#pragma once #pragma once
#include <pxr/imaging/hd/sceneDelegate.h> #include <pxr/imaging/hd/sceneDelegate.h>
#include <pxr/imaging/hdx/shadowTask.h>
#include <pxr/imaging/hdx/simpleLightTask.h> #include <pxr/imaging/hdx/simpleLightTask.h>
#include <pxr/imaging/hdx/skydomeTask.h> #include <pxr/imaging/hdx/skydomeTask.h>
@ -19,14 +20,18 @@ class LightTasksDelegate : public pxr::HdSceneDelegate {
pxr::HdTaskSharedPtr simple_task(); pxr::HdTaskSharedPtr simple_task();
pxr::HdTaskSharedPtr skydome_task(); pxr::HdTaskSharedPtr skydome_task();
pxr::HdTaskSharedPtr shadow_task();
void set_camera(pxr::SdfPath const &camera_id); void set_camera(pxr::SdfPath const &camera_id);
void set_viewport(pxr::GfVec4d const &viewport); void set_viewport(pxr::GfVec4d const &viewport);
void set_shadows(bool const &enable_shadows);
private: private:
pxr::SdfPath simple_task_id_; pxr::SdfPath simple_task_id_;
pxr::SdfPath skydome_task_id_; pxr::SdfPath skydome_task_id_;
pxr::SdfPath shadow_task_id_;
pxr::HdxSimpleLightTaskParams simple_task_params_; pxr::HdxSimpleLightTaskParams simple_task_params_;
pxr::HdxRenderTaskParams skydome_task_params_; pxr::HdxRenderTaskParams skydome_task_params_;
pxr::HdxShadowTaskParams shadow_task_params_;
}; };
} // namespace blender::render::hydra } // namespace blender::render::hydra

View File

@ -235,6 +235,7 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
render_task_delegate_->set_viewport(viewport); render_task_delegate_->set_viewport(viewport);
if (light_tasks_delegate_) { if (light_tasks_delegate_) {
light_tasks_delegate_->set_viewport(viewport); light_tasks_delegate_->set_viewport(viewport);
light_tasks_delegate_->set_shadows(hydra_scene_delegate_->shading_settings.use_storm_shadows);
} }
render_task_delegate_->add_aov(pxr::HdAovTokens->color); render_task_delegate_->add_aov(pxr::HdAovTokens->color);
@ -246,6 +247,7 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
tasks.push_back(light_tasks_delegate_->skydome_task()); tasks.push_back(light_tasks_delegate_->skydome_task());
} }
tasks.push_back(light_tasks_delegate_->simple_task()); tasks.push_back(light_tasks_delegate_->simple_task());
tasks.push_back(light_tasks_delegate_->shadow_task());
} }
tasks.push_back(render_task_delegate_->task()); tasks.push_back(render_task_delegate_->task());