From d1afd6c90244bad0e6d938bea67be593dbadccc3 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 27 Apr 2023 15:38:43 +0300 Subject: [PATCH 01/10] fix light update --- source/blender/render/hydra/scene_delegate/light.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/blender/render/hydra/scene_delegate/light.cc b/source/blender/render/hydra/scene_delegate/light.cc index ab4642f86389..301fb64109a9 100644 --- a/source/blender/render/hydra/scene_delegate/light.cc +++ b/source/blender/render/hydra/scene_delegate/light.cc @@ -121,6 +121,10 @@ void LightData::update() write_transform(); bits = pxr::HdLight::DirtyTransform; } + else if (id->recalc & ID_RECALC_COPY_ON_WRITE) { + init(); + bits = pxr::HdLight::AllDirty; + } scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id, bits); } -- 2.30.2 From dc140c903242cff34ae047e5d6957f072750012d Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 28 Apr 2023 15:23:35 +0300 Subject: [PATCH 02/10] fixed spotlight pxr::HdLightTokens->exposure 1.0f -> 0.0f --- source/blender/render/hydra/scene_delegate/light.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/light.cc b/source/blender/render/hydra/scene_delegate/light.cc index 301fb64109a9..38d2191c793d 100644 --- a/source/blender/render/hydra/scene_delegate/light.cc +++ b/source/blender/render/hydra/scene_delegate/light.cc @@ -44,13 +44,13 @@ void LightData::init() case LA_SUN: data_[pxr::HdLightTokens->angle] = light->sun_angle * 180.0 / M_PI; break; - + case LA_SPOT: - data_[pxr::HdLightTokens->shapingConeAngle] = light->spotsize / 2; - data_[pxr::HdLightTokens->shapingConeSoftness] = light->spotblend; + data_[pxr::UsdLuxTokens->inputsShapingConeAngle] = (float)(light->spotsize / 2.0f * 180.0f / M_PI); + data_[pxr::UsdLuxTokens->inputsShapingConeSoftness] = light->spotblend; data_[pxr::UsdLuxTokens->treatAsPoint] = true; break; - + case LA_AREA: switch (light->area_shape) { case LA_AREA_SQUARE: @@ -83,7 +83,7 @@ void LightData::init() prim_type_ = prim_type(light); /* TODO: temporary value, it should be delivered through Python UI */ - data_[pxr::HdLightTokens->exposure] = 1.0f; + data_[pxr::HdLightTokens->exposure] = 0.0f; write_transform(); } -- 2.30.2 From 0bd2c69cbc869ea9618bf6a0c00cc0202aeb4710 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 28 Apr 2023 19:27:35 +0300 Subject: [PATCH 03/10] to save code --- .../render/hydra/scene_delegate/light.cc | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/light.cc b/source/blender/render/hydra/scene_delegate/light.cc index 38d2191c793d..2152815e7100 100644 --- a/source/blender/render/hydra/scene_delegate/light.cc +++ b/source/blender/render/hydra/scene_delegate/light.cc @@ -30,23 +30,24 @@ void LightData::init() float intensity = light->energy; if (scene_delegate_->engine_type == BlenderSceneDelegate::EngineType::PREVIEW) { - intensity *= 0.001; + intensity *= 0.001f; } - data_[pxr::HdLightTokens->intensity] = intensity; + //intensity *= 0.001f; data_[pxr::HdLightTokens->color] = pxr::GfVec3f(light->r, light->g, light->b); switch (light->type) { case LA_LOCAL: - data_[pxr::HdLightTokens->radius] = light->area_size / 2; + data_[pxr::HdLightTokens->radius] = light->radius; + data_[pxr::HdLightTokens->normalize] = true; break; case LA_SUN: - data_[pxr::HdLightTokens->angle] = light->sun_angle * 180.0 / M_PI; + data_[pxr::HdLightTokens->angle] = light->sun_angle * 180.0f / float(M_PI); break; case LA_SPOT: - data_[pxr::UsdLuxTokens->inputsShapingConeAngle] = (float)(light->spotsize / 2.0f * 180.0f / M_PI); + data_[pxr::UsdLuxTokens->inputsShapingConeAngle] = light->spotsize / 2.0f * 180.0f / float(M_PI); data_[pxr::UsdLuxTokens->inputsShapingConeSoftness] = light->spotblend; data_[pxr::UsdLuxTokens->treatAsPoint] = true; break; @@ -63,11 +64,13 @@ void LightData::init() break; case LA_AREA_DISK: - data_[pxr::HdLightTokens->radius] = light->area_size / 2; + data_[pxr::HdLightTokens->radius] = light->area_size / 2.0f; + intensity /= 2.0f; break; case LA_AREA_ELLIPSE: - data_[pxr::HdLightTokens->radius] = (light->area_size + light->area_sizey) / 4; + data_[pxr::HdLightTokens->radius] = (light->area_size + light->area_sizey) / 4.0f; + intensity /= 2.0f; break; default: @@ -79,6 +82,8 @@ void LightData::init() default: break; } + + data_[pxr::HdLightTokens->intensity] = intensity; prim_type_ = prim_type(light); @@ -146,6 +151,7 @@ pxr::VtValue LightData::get_data(pxr::TfToken const &key) const } } } + std::cout << key.GetString() << " " << ret << " " << ret.IsHolding() << "\n"; return ret; } -- 2.30.2 From 212434497f71a156c5e4e899ebe35a2d8fec7e5a Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Fri, 28 Apr 2023 20:03:41 +0300 Subject: [PATCH 04/10] added correction for point light --- source/blender/render/hydra/scene_delegate/light.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/light.cc b/source/blender/render/hydra/scene_delegate/light.cc index 2152815e7100..465f98f18f0a 100644 --- a/source/blender/render/hydra/scene_delegate/light.cc +++ b/source/blender/render/hydra/scene_delegate/light.cc @@ -32,14 +32,14 @@ void LightData::init() if (scene_delegate_->engine_type == BlenderSceneDelegate::EngineType::PREVIEW) { intensity *= 0.001f; } - //intensity *= 0.001f; data_[pxr::HdLightTokens->color] = pxr::GfVec3f(light->r, light->g, light->b); switch (light->type) { case LA_LOCAL: - data_[pxr::HdLightTokens->radius] = light->radius; + data_[pxr::HdLightTokens->radius] = std::max(light->radius, 0.000001f); data_[pxr::HdLightTokens->normalize] = true; + intensity /= 40.0f; break; case LA_SUN: -- 2.30.2 From 97331cf080c9b496f42fea4ac1fbcbf127615615 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 2 May 2023 15:34:44 +0300 Subject: [PATCH 05/10] adjusted intensity for area and spot lights --- source/blender/render/hydra/scene_delegate/light.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/light.cc b/source/blender/render/hydra/scene_delegate/light.cc index 465f98f18f0a..2d73b320d514 100644 --- a/source/blender/render/hydra/scene_delegate/light.cc +++ b/source/blender/render/hydra/scene_delegate/light.cc @@ -50,6 +50,7 @@ void LightData::init() data_[pxr::UsdLuxTokens->inputsShapingConeAngle] = light->spotsize / 2.0f * 180.0f / float(M_PI); data_[pxr::UsdLuxTokens->inputsShapingConeSoftness] = light->spotblend; data_[pxr::UsdLuxTokens->treatAsPoint] = true; + intensity /= 10.0f; break; case LA_AREA: @@ -57,20 +58,22 @@ void LightData::init() case LA_AREA_SQUARE: data_[pxr::HdLightTokens->width] = light->area_size; data_[pxr::HdLightTokens->height] = light->area_size; + intensity /= 4.0f; break; case LA_AREA_RECT: data_[pxr::HdLightTokens->width] = light->area_size; data_[pxr::HdLightTokens->height] = light->area_sizey; + intensity /= 4.0f; break; case LA_AREA_DISK: data_[pxr::HdLightTokens->radius] = light->area_size / 2.0f; - intensity /= 2.0f; + intensity /= 16.0f; break; case LA_AREA_ELLIPSE: data_[pxr::HdLightTokens->radius] = (light->area_size + light->area_sizey) / 4.0f; - intensity /= 2.0f; + intensity /= 16.0f; break; default: -- 2.30.2 From 40c976a81c573fa705403b5f3be371eeec12c023 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 2 May 2023 15:43:42 +0300 Subject: [PATCH 06/10] make format --- source/blender/render/hydra/scene_delegate/light.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/light.cc b/source/blender/render/hydra/scene_delegate/light.cc index 2d73b320d514..f9f29c161aa9 100644 --- a/source/blender/render/hydra/scene_delegate/light.cc +++ b/source/blender/render/hydra/scene_delegate/light.cc @@ -45,14 +45,15 @@ void LightData::init() case LA_SUN: data_[pxr::HdLightTokens->angle] = light->sun_angle * 180.0f / float(M_PI); break; - + case LA_SPOT: - data_[pxr::UsdLuxTokens->inputsShapingConeAngle] = light->spotsize / 2.0f * 180.0f / float(M_PI); + data_[pxr::UsdLuxTokens->inputsShapingConeAngle] = light->spotsize / 2.0f * 180.0f / + float(M_PI); data_[pxr::UsdLuxTokens->inputsShapingConeSoftness] = light->spotblend; data_[pxr::UsdLuxTokens->treatAsPoint] = true; intensity /= 10.0f; break; - + case LA_AREA: switch (light->area_shape) { case LA_AREA_SQUARE: @@ -85,7 +86,7 @@ void LightData::init() default: break; } - + data_[pxr::HdLightTokens->intensity] = intensity; prim_type_ = prim_type(light); -- 2.30.2 From b2edcb1618617f5353c6f41ed0de86a75f89ca3e Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Tue, 2 May 2023 16:06:49 +0300 Subject: [PATCH 07/10] removed debug line --- source/blender/render/hydra/scene_delegate/light.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/source/blender/render/hydra/scene_delegate/light.cc b/source/blender/render/hydra/scene_delegate/light.cc index f9f29c161aa9..73b6d1565053 100644 --- a/source/blender/render/hydra/scene_delegate/light.cc +++ b/source/blender/render/hydra/scene_delegate/light.cc @@ -155,7 +155,6 @@ pxr::VtValue LightData::get_data(pxr::TfToken const &key) const } } } - std::cout << key.GetString() << " " << ret << " " << ret.IsHolding() << "\n"; return ret; } -- 2.30.2 From 0b5e6c9d54556933de6f6eed658df0754ab1dfc9 Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Wed, 3 May 2023 18:07:00 +0300 Subject: [PATCH 08/10] fix review comments --- .../render/hydra/scene_delegate/light.cc | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/light.cc b/source/blender/render/hydra/scene_delegate/light.cc index 73b6d1565053..bf0e81688f81 100644 --- a/source/blender/render/hydra/scene_delegate/light.cc +++ b/source/blender/render/hydra/scene_delegate/light.cc @@ -25,20 +25,23 @@ void LightData::init() { ID_LOG(2, ""); + const float round_tolerance = 0.00001f; + Light *light = (Light *)((Object *)id)->data; data_.clear(); float intensity = light->energy; - if (scene_delegate_->engine_type == BlenderSceneDelegate::EngineType::PREVIEW) { - intensity *= 0.001f; - } - data_[pxr::HdLightTokens->color] = pxr::GfVec3f(light->r, light->g, light->b); switch (light->type) { case LA_LOCAL: - data_[pxr::HdLightTokens->radius] = std::max(light->radius, 0.000001f); - data_[pxr::HdLightTokens->normalize] = true; + if (light->radius > round_tolerance) { + data_[pxr::HdLightTokens->radius] = light->radius; + data_[pxr::HdLightTokens->normalize] = true; + } + else { + data_[pxr::UsdLuxTokens->treatAsPoint] = true; + } intensity /= 40.0f; break; @@ -88,12 +91,10 @@ void LightData::init() } data_[pxr::HdLightTokens->intensity] = intensity; + data_[pxr::HdLightTokens->exposure] = 0.0f; prim_type_ = prim_type(light); - /* TODO: temporary value, it should be delivered through Python UI */ - data_[pxr::HdLightTokens->exposure] = 0.0f; - write_transform(); } @@ -122,7 +123,7 @@ void LightData::update() } pxr::HdDirtyBits bits = pxr::HdLight::Clean; - if (id->recalc & ID_RECALC_GEOMETRY) { + if (id->recalc & ID_RECALC_GEOMETRY || light->id.recalc & ID_RECALC_GEOMETRY) { init(); bits = pxr::HdLight::AllDirty; } @@ -130,10 +131,6 @@ void LightData::update() write_transform(); bits = pxr::HdLight::DirtyTransform; } - else if (id->recalc & ID_RECALC_COPY_ON_WRITE) { - init(); - bits = pxr::HdLight::AllDirty; - } scene_delegate_->GetRenderIndex().GetChangeTracker().MarkSprimDirty(prim_id, bits); } -- 2.30.2 From 57bcfce620cbe3156fcf645949dc538baea02a2a Mon Sep 17 00:00:00 2001 From: "georgiy.m.markelov@gmail.com" Date: Thu, 4 May 2023 11:11:14 +0300 Subject: [PATCH 09/10] changed round_tolerance -> FLT_EPSILON added comments --- .../blender/render/hydra/scene_delegate/light.cc | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/light.cc b/source/blender/render/hydra/scene_delegate/light.cc index bf0e81688f81..02a9ecb15291 100644 --- a/source/blender/render/hydra/scene_delegate/light.cc +++ b/source/blender/render/hydra/scene_delegate/light.cc @@ -25,8 +25,6 @@ void LightData::init() { ID_LOG(2, ""); - const float round_tolerance = 0.00001f; - Light *light = (Light *)((Object *)id)->data; data_.clear(); @@ -35,14 +33,14 @@ void LightData::init() switch (light->type) { case LA_LOCAL: - if (light->radius > round_tolerance) { + if (light->radius > FLT_EPSILON) { /* extremely small object should be considered as point */ data_[pxr::HdLightTokens->radius] = light->radius; data_[pxr::HdLightTokens->normalize] = true; } else { data_[pxr::UsdLuxTokens->treatAsPoint] = true; } - intensity /= 40.0f; + intensity /= 40.0f; /* coefficient approximated to follow RPR results */ break; case LA_SUN: @@ -54,7 +52,7 @@ void LightData::init() float(M_PI); data_[pxr::UsdLuxTokens->inputsShapingConeSoftness] = light->spotblend; data_[pxr::UsdLuxTokens->treatAsPoint] = true; - intensity /= 10.0f; + intensity /= 10.0f; /* coefficient approximated to follow RPR results */ break; case LA_AREA: @@ -62,22 +60,22 @@ void LightData::init() case LA_AREA_SQUARE: data_[pxr::HdLightTokens->width] = light->area_size; data_[pxr::HdLightTokens->height] = light->area_size; - intensity /= 4.0f; + intensity /= 4.0f; /* coefficient approximated to follow RPR results */ break; case LA_AREA_RECT: data_[pxr::HdLightTokens->width] = light->area_size; data_[pxr::HdLightTokens->height] = light->area_sizey; - intensity /= 4.0f; + intensity /= 4.0f; /* coefficient approximated to follow RPR results */ break; case LA_AREA_DISK: data_[pxr::HdLightTokens->radius] = light->area_size / 2.0f; - intensity /= 16.0f; + intensity /= 16.0f; /* coefficient approximated to follow RPR results */ break; case LA_AREA_ELLIPSE: data_[pxr::HdLightTokens->radius] = (light->area_size + light->area_sizey) / 4.0f; - intensity /= 16.0f; + intensity /= 16.0f; /* coefficient approximated to follow RPR results */ break; default: -- 2.30.2 From 4896990eacfd1fe5039a47b60c6a5846fb6a0bcc Mon Sep 17 00:00:00 2001 From: Bogdan Nagirniak Date: Thu, 4 May 2023 13:14:10 +0300 Subject: [PATCH 10/10] Fixed comments, fixed sun_angle usage --- .../render/hydra/scene_delegate/light.cc | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/source/blender/render/hydra/scene_delegate/light.cc b/source/blender/render/hydra/scene_delegate/light.cc index 02a9ecb15291..4cf93e38d4b1 100644 --- a/source/blender/render/hydra/scene_delegate/light.cc +++ b/source/blender/render/hydra/scene_delegate/light.cc @@ -7,6 +7,7 @@ #include #include +#include "BLI_math_rotation.h" #include "DNA_light_types.h" #include "blender_scene_delegate.h" @@ -33,26 +34,26 @@ void LightData::init() switch (light->type) { case LA_LOCAL: - if (light->radius > FLT_EPSILON) { /* extremely small object should be considered as point */ + if (light->radius <= FLT_EPSILON) { + /* extremely small object should be considered as point */ + data_[pxr::UsdLuxTokens->treatAsPoint] = true; + } + else { data_[pxr::HdLightTokens->radius] = light->radius; data_[pxr::HdLightTokens->normalize] = true; } - else { - data_[pxr::UsdLuxTokens->treatAsPoint] = true; - } - intensity /= 40.0f; /* coefficient approximated to follow RPR results */ + intensity /= 40.0f; /* coefficient approximated to follow Cycles results */ break; case LA_SUN: - data_[pxr::HdLightTokens->angle] = light->sun_angle * 180.0f / float(M_PI); + data_[pxr::HdLightTokens->angle] = RAD2DEGF(light->sun_angle * 0.5f); break; case LA_SPOT: - data_[pxr::UsdLuxTokens->inputsShapingConeAngle] = light->spotsize / 2.0f * 180.0f / - float(M_PI); + data_[pxr::UsdLuxTokens->inputsShapingConeAngle] = RAD2DEGF(light->spotsize * 0.5f); data_[pxr::UsdLuxTokens->inputsShapingConeSoftness] = light->spotblend; data_[pxr::UsdLuxTokens->treatAsPoint] = true; - intensity /= 10.0f; /* coefficient approximated to follow RPR results */ + intensity /= 10.0f; /* coefficient approximated to follow Cycles results */ break; case LA_AREA: @@ -60,22 +61,22 @@ void LightData::init() case LA_AREA_SQUARE: data_[pxr::HdLightTokens->width] = light->area_size; data_[pxr::HdLightTokens->height] = light->area_size; - intensity /= 4.0f; /* coefficient approximated to follow RPR results */ + intensity /= 4.0f; /* coefficient approximated to follow Cycles results */ break; case LA_AREA_RECT: data_[pxr::HdLightTokens->width] = light->area_size; data_[pxr::HdLightTokens->height] = light->area_sizey; - intensity /= 4.0f; /* coefficient approximated to follow RPR results */ + intensity /= 4.0f; /* coefficient approximated to follow Cycles results */ break; case LA_AREA_DISK: data_[pxr::HdLightTokens->radius] = light->area_size / 2.0f; - intensity /= 16.0f; /* coefficient approximated to follow RPR results */ + intensity /= 16.0f; /* coefficient approximated to follow Cycles results */ break; case LA_AREA_ELLIPSE: data_[pxr::HdLightTokens->radius] = (light->area_size + light->area_sizey) / 4.0f; - intensity /= 16.0f; /* coefficient approximated to follow RPR results */ + intensity /= 16.0f; /* coefficient approximated to follow Cycles results */ break; default: -- 2.30.2