forked from blender/blender
WIP Make shadows visible for Storm delegate #80
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
|
|
||||||
|
#include "DNA_light_types.h"
|
||||||
#include "DNA_scene_types.h"
|
#include "DNA_scene_types.h"
|
||||||
|
|
||||||
#include "BLI_set.hh"
|
#include "BLI_set.hh"
|
||||||
@ -238,6 +239,39 @@ void HydraSceneDelegate::clear()
|
|||||||
view3d = nullptr;
|
view3d = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool HydraSceneDelegate::has_shadows()
|
||||||
|
{
|
||||||
|
|
||||||
|
bool has_shadows = false;
|
||||||
|
|
||||||
|
DEGObjectIterSettings settings = {0};
|
||||||
|
settings.depsgraph = depsgraph;
|
||||||
|
settings.flags = DEG_OBJECT_ITER_FOR_RENDER_ENGINE_FLAGS;
|
||||||
|
DEGObjectIterData data = {0};
|
||||||
|
data.settings = &settings;
|
||||||
|
data.graph = settings.depsgraph;
|
||||||
|
data.flag = settings.flags;
|
||||||
|
|
||||||
|
ITER_BEGIN (DEG_iterator_objects_begin,
|
||||||
|
DEG_iterator_objects_next,
|
||||||
|
DEG_iterator_objects_end,
|
||||||
|
&data,
|
||||||
|
Object *,
|
||||||
|
object)
|
||||||
|
{
|
||||||
|
if (object->type == OB_LAMP) {
|
||||||
|
Light *light = (Light *)object->data;
|
||||||
|
has_shadows |= light->mode & LA_SHADOW;
|
||||||
|
if (has_shadows) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ITER_END;
|
||||||
|
|
||||||
|
return has_shadows;
|
||||||
|
}
|
||||||
|
|
||||||
pxr::SdfPath HydraSceneDelegate::prim_id(ID *id, const char *prefix) const
|
pxr::SdfPath HydraSceneDelegate::prim_id(ID *id, const char *prefix) const
|
||||||
{
|
{
|
||||||
/* Making id of object in form like <prefix>_<pointer in 16 hex digits format> */
|
/* Making id of object in form like <prefix>_<pointer in 16 hex digits format> */
|
||||||
|
@ -44,7 +44,6 @@ 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
|
|||||||
bool operator==(const ShadingSettings &other);
|
bool operator==(const ShadingSettings &other);
|
||||||
};
|
};
|
||||||
@ -91,6 +90,7 @@ class HydraSceneDelegate : public pxr::HdSceneDelegate {
|
|||||||
|
|
||||||
void populate(Depsgraph *depsgraph, View3D *v3d);
|
void populate(Depsgraph *depsgraph, View3D *v3d);
|
||||||
void clear();
|
void clear();
|
||||||
|
bool has_shadows();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
pxr::SdfPath prim_id(ID *id, const char *prefix) const;
|
pxr::SdfPath prim_id(ID *id, const char *prefix) const;
|
||||||
|
@ -148,9 +148,10 @@ void LightData::write_shadow_params()
|
|||||||
we verified if any of light's shadow is turned on, if yes shadow task will be added*/
|
we verified if any of light's shadow is turned on, if yes shadow task will be added*/
|
||||||
Light *light = (Light *)((Object *)id)->data;
|
Light *light = (Light *)((Object *)id)->data;
|
||||||
bool use_shadow = (light->mode & LA_SHADOW) && light->type == LA_SUN;
|
bool use_shadow = (light->mode & LA_SHADOW) && light->type == LA_SUN;
|
||||||
scene_delegate_->shading_settings.use_storm_shadows |= use_shadow;
|
|
||||||
if (use_shadow) {
|
|
||||||
data_[pxr::HdLightTokens->hasShadow] = use_shadow;
|
data_[pxr::HdLightTokens->hasShadow] = use_shadow;
|
||||||
|
if (!use_shadow) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
pxr::HdxShadowParams shadow_params = pxr::HdxShadowParams();
|
pxr::HdxShadowParams shadow_params = pxr::HdxShadowParams();
|
||||||
|
|
||||||
/* ShadowMatrix class is used to calculates shadow matrix from light frustum.*/
|
/* ShadowMatrix class is used to calculates shadow matrix from light frustum.*/
|
||||||
@ -174,7 +175,6 @@ void LightData::write_shadow_params()
|
|||||||
data_[pxr::HdLightTokens->shadowCollection] = pxr::HdRprimCollection(
|
data_[pxr::HdLightTokens->shadowCollection] = pxr::HdRprimCollection(
|
||||||
pxr::HdTokens->geometry, pxr::HdReprSelector(pxr::HdReprTokens->refined));
|
pxr::HdTokens->geometry, pxr::HdReprSelector(pxr::HdReprTokens->refined));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void LightData::insert()
|
void LightData::insert()
|
||||||
{
|
{
|
||||||
|
@ -27,6 +27,7 @@ void FinalEngine::render(Depsgraph *depsgraph)
|
|||||||
{
|
{
|
||||||
const Scene *scene = DEG_get_evaluated_scene(depsgraph);
|
const Scene *scene = DEG_get_evaluated_scene(depsgraph);
|
||||||
const ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
|
const ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
|
||||||
|
bool has_shadows = hydra_scene_delegate_->has_shadows();
|
||||||
|
|
||||||
char scene_name[MAX_ID_FULL_NAME];
|
char scene_name[MAX_ID_FULL_NAME];
|
||||||
BKE_id_full_name_get(scene_name, &scene->id, 0);
|
BKE_id_full_name_get(scene_name, &scene->id, 0);
|
||||||
@ -50,7 +51,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);
|
light_tasks_delegate_->set_shadows(has_shadows);
|
||||||
}
|
}
|
||||||
|
|
||||||
render_task_delegate_->add_aov(pxr::HdAovTokens->color);
|
render_task_delegate_->add_aov(pxr::HdAovTokens->color);
|
||||||
@ -73,7 +74,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());
|
||||||
if (hydra_scene_delegate_->shading_settings.use_storm_shadows) {
|
if (has_shadows) {
|
||||||
tasks.push_back(light_tasks_delegate_->shadow_task());
|
tasks.push_back(light_tasks_delegate_->shadow_task());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -219,6 +219,8 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
|
|||||||
{
|
{
|
||||||
ViewSettings view_settings(context);
|
ViewSettings view_settings(context);
|
||||||
const Scene *scene = DEG_get_evaluated_scene(depsgraph);
|
const Scene *scene = DEG_get_evaluated_scene(depsgraph);
|
||||||
|
bool has_shadows = hydra_scene_delegate_->has_shadows();
|
||||||
|
|
||||||
if (view_settings.width() * view_settings.height() == 0) {
|
if (view_settings.width() * view_settings.height() == 0) {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
@ -233,7 +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);
|
light_tasks_delegate_->set_shadows(has_shadows);
|
||||||
}
|
}
|
||||||
|
|
||||||
render_task_delegate_->add_aov(pxr::HdAovTokens->color);
|
render_task_delegate_->add_aov(pxr::HdAovTokens->color);
|
||||||
@ -245,7 +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());
|
||||||
if (hydra_scene_delegate_->shading_settings.use_storm_shadows) {
|
if (has_shadows) {
|
||||||
tasks.push_back(light_tasks_delegate_->shadow_task());
|
tasks.push_back(light_tasks_delegate_->shadow_task());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user
This parameter not needed, instead create function like
HydraSceneDelegate::has_shadows()