forked from blender/blender
WIP Make shadows visible for Storm delegate #80
@ -5,6 +5,7 @@
|
||||
|
||||
#include <bitset>
|
||||
|
||||
#include "DNA_light_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
|
||||
#include "BLI_set.hh"
|
||||
@ -238,6 +239,39 @@ void HydraSceneDelegate::clear()
|
||||
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
|
||||
{
|
||||
/* 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;
|
||||
float studiolight_rotation;
|
||||
float studiolight_intensity;
|
||||
bool use_storm_shadows = false;
|
||||
|
||||
bool operator==(const ShadingSettings &other);
|
||||
};
|
||||
@ -91,6 +90,7 @@ class HydraSceneDelegate : public pxr::HdSceneDelegate {
|
||||
|
||||
void populate(Depsgraph *depsgraph, View3D *v3d);
|
||||
void clear();
|
||||
bool has_shadows();
|
||||
|
||||
private:
|
||||
pxr::SdfPath prim_id(ID *id, const char *prefix) const;
|
||||
|
@ -148,32 +148,32 @@ void LightData::write_shadow_params()
|
||||
we verified if any of light's shadow is turned on, if yes shadow task will be added*/
|
||||
Light *light = (Light *)((Object *)id)->data;
|
||||
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;
|
||||
pxr::HdxShadowParams shadow_params = pxr::HdxShadowParams();
|
||||
|
||||
/* ShadowMatrix class is used to calculates shadow matrix from light frustum.*/
|
||||
ShadowMatrix *shadow_matrix = new ShadowMatrix();
|
||||
shadow_matrix->set_near_far(0.1, light->cascade_max_dist);
|
||||
shadow_matrix->set_transform(gf_matrix_from_transform(((Object *)id)->object_to_world));
|
||||
|
||||
/* SetWindow sets size of projected shadow texture texture in
|
||||
the approximate value is calculated using sun_angle property
|
||||
180 degrees is window size 1000 by 1000 */
|
||||
shadow_matrix->set_window(light->sun_angle * 0.5f / M_PI * 1000,
|
||||
light->sun_angle * 0.5f / M_PI * 1000);
|
||||
shadow_matrix->set_projection_type(pxr::GfFrustum::Orthographic);
|
||||
shadow_params.enabled = use_shadow;
|
||||
shadow_params.resolution = scene_delegate_->scene->eevee.shadow_cascade_size;
|
||||
shadow_params.shadowMatrix = pxr::HdxShadowMatrixComputationSharedPtr(shadow_matrix);
|
||||
shadow_params.bias = -1.0 * light->bias;
|
||||
shadow_params.blur = light->cascade_fade;
|
||||
|
||||
data_[pxr::HdLightTokens->shadowParams] = shadow_params;
|
||||
data_[pxr::HdLightTokens->shadowCollection] = pxr::HdRprimCollection(
|
||||
pxr::HdTokens->geometry, pxr::HdReprSelector(pxr::HdReprTokens->refined));
|
||||
data_[pxr::HdLightTokens->hasShadow] = use_shadow;
|
||||
if (!use_shadow) {
|
||||
return;
|
||||
}
|
||||
pxr::HdxShadowParams shadow_params = pxr::HdxShadowParams();
|
||||
|
||||
/* ShadowMatrix class is used to calculates shadow matrix from light frustum.*/
|
||||
ShadowMatrix *shadow_matrix = new ShadowMatrix();
|
||||
shadow_matrix->set_near_far(0.1, light->cascade_max_dist);
|
||||
shadow_matrix->set_transform(gf_matrix_from_transform(((Object *)id)->object_to_world));
|
||||
|
||||
/* SetWindow sets size of projected shadow texture texture in
|
||||
the approximate value is calculated using sun_angle property
|
||||
180 degrees is window size 1000 by 1000 */
|
||||
shadow_matrix->set_window(light->sun_angle * 0.5f / M_PI * 1000,
|
||||
light->sun_angle * 0.5f / M_PI * 1000);
|
||||
shadow_matrix->set_projection_type(pxr::GfFrustum::Orthographic);
|
||||
shadow_params.enabled = use_shadow;
|
||||
shadow_params.resolution = scene_delegate_->scene->eevee.shadow_cascade_size;
|
||||
shadow_params.shadowMatrix = pxr::HdxShadowMatrixComputationSharedPtr(shadow_matrix);
|
||||
shadow_params.bias = -1.0 * light->bias;
|
||||
shadow_params.blur = light->cascade_fade;
|
||||
|
||||
data_[pxr::HdLightTokens->shadowParams] = shadow_params;
|
||||
data_[pxr::HdLightTokens->shadowCollection] = pxr::HdRprimCollection(
|
||||
pxr::HdTokens->geometry, pxr::HdReprSelector(pxr::HdReprTokens->refined));
|
||||
}
|
||||
|
||||
void LightData::insert()
|
||||
|
@ -27,6 +27,7 @@ void FinalEngine::render(Depsgraph *depsgraph)
|
||||
{
|
||||
const Scene *scene = DEG_get_evaluated_scene(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];
|
||||
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]));
|
||||
if (light_tasks_delegate_) {
|
||||
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);
|
||||
@ -73,7 +74,7 @@ void FinalEngine::render(Depsgraph *depsgraph)
|
||||
tasks.push_back(light_tasks_delegate_->skydome_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());
|
||||
}
|
||||
}
|
||||
|
@ -219,6 +219,8 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
|
||||
{
|
||||
ViewSettings view_settings(context);
|
||||
const Scene *scene = DEG_get_evaluated_scene(depsgraph);
|
||||
bool has_shadows = hydra_scene_delegate_->has_shadows();
|
||||
|
||||
if (view_settings.width() * view_settings.height() == 0) {
|
||||
return;
|
||||
};
|
||||
@ -233,7 +235,7 @@ void ViewportEngine::render(Depsgraph *depsgraph, bContext *context)
|
||||
render_task_delegate_->set_viewport(viewport);
|
||||
if (light_tasks_delegate_) {
|
||||
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);
|
||||
@ -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_->simple_task());
|
||||
if (hydra_scene_delegate_->shading_settings.use_storm_shadows) {
|
||||
if (has_shadows) {
|
||||
tasks.push_back(light_tasks_delegate_->shadow_task());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user