Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 29 additions & 11 deletions src/PrepareLightsPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,25 +208,43 @@ static bool ConvertLight(const donut::engine::Light& light, PolymorphicLightInfo
polymorphic.scalars = fp32ToFp16(halfAngularSizeRad) | (fp32ToFp16(solidAngle) << 16);
return true;
}
case LightType_Spot: {
auto& spot = static_cast<const SpotLightWithProfile&>(light);
float projectedArea = dm::PI_f * square(spot.radius);
float3 radiance = spot.color * spot.intensity / projectedArea;
case LightType_Spot:
case LightType_SpotProfile: {
auto& spot = static_cast<const SpotLight&>(light);
if (spot.radius == 0.f)
{
float3 flux = spot.color * spot.intensity;

polymorphic.colorTypeAndFlags = (uint32_t)PolymorphicLightType::kPoint << kPolymorphicLightTypeShift;
packLightColor(flux, polymorphic);
polymorphic.center = float3(spot.GetPosition());
}
else
{
float projectedArea = dm::PI_f * square(spot.radius);
float3 radiance = spot.color * spot.intensity / projectedArea;

polymorphic.colorTypeAndFlags = (uint32_t)PolymorphicLightType::kSphere << kPolymorphicLightTypeShift;
packLightColor(radiance, polymorphic);
polymorphic.center = float3(spot.GetPosition());
polymorphic.scalars = fp32ToFp16(spot.radius);
}

float softness = saturate(1.f - spot.innerAngle / spot.outerAngle);

polymorphic.colorTypeAndFlags = (uint32_t)PolymorphicLightType::kSphere << kPolymorphicLightTypeShift;
polymorphic.colorTypeAndFlags |= kPolymorphicLightShapingEnableBit;
packLightColor(radiance, polymorphic);
polymorphic.center = float3(spot.GetPosition());
polymorphic.scalars = fp32ToFp16(spot.radius);
polymorphic.primaryAxis = packNormalizedVector(float3(normalize(spot.GetDirection())));
polymorphic.cosConeAngleAndSoftness = fp32ToFp16(cosf(dm::radians(spot.outerAngle)));
polymorphic.cosConeAngleAndSoftness |= fp32ToFp16(softness) << 16;

if (spot.profileTextureIndex >= 0)
if (spot.GetLightType() == LightType_SpotProfile)
{
polymorphic.iesProfileIndex = spot.profileTextureIndex;
polymorphic.colorTypeAndFlags |= kPolymorphicLightIesProfileEnableBit;
auto& spotWithProfile = static_cast<const SpotLightWithProfile&>(light);
if (spotWithProfile.profileTextureIndex >= 0)
{
polymorphic.iesProfileIndex = spotWithProfile.profileTextureIndex;
polymorphic.colorTypeAndFlags |= kPolymorphicLightIesProfileEnableBit;
}
}

return true;
Expand Down
2 changes: 2 additions & 0 deletions src/SampleScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ constexpr int LightType_Environment = 1000;
constexpr int LightType_Cylinder = 1001;
constexpr int LightType_Disk = 1002;
constexpr int LightType_Rect = 1003;
constexpr int LightType_SpotProfile = 1004;

class SpotLightWithProfile : public donut::engine::SpotLight
{
Expand All @@ -26,6 +27,7 @@ class SpotLightWithProfile : public donut::engine::SpotLight

void Load(const Json::Value& node) override;
void Store(Json::Value& node) const override;
[[nodiscard]] int GetLightType() const override { return LightType_SpotProfile; }
[[nodiscard]] std::shared_ptr<SceneGraphLeaf> Clone() override;
};

Expand Down
45 changes: 25 additions & 20 deletions src/UserInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1121,38 +1121,43 @@ void UserInterface::SceneSettings()
break;
}
case LightType_Spot:
case LightType_SpotProfile:
{
SpotLightWithProfile& spotLight = static_cast<SpotLightWithProfile&>(*m_SelectedLight);
engine::SpotLight& spotLight = static_cast<engine::SpotLight&>(*m_SelectedLight);
app::LightEditor_Spot(spotLight);

ImGui::PushItemWidth(150.f);
if (ImGui::BeginCombo("IES Profile", spotLight.profileName.empty() ? "(none)" : spotLight.profileName.c_str()))
if (spotLight.GetLightType() == LightType_SpotProfile)
{
bool selected = spotLight.profileName.empty();
if (ImGui::Selectable("(none)", &selected) && selected)
{
spotLight.profileName = "";
spotLight.profileTextureIndex = -1;
}

for (auto profile : m_ui.resources->iesProfiles)
SpotLightWithProfile& spotLightProfile = static_cast<SpotLightWithProfile&>(*m_SelectedLight);
ImGui::PushItemWidth(150.f);
if (ImGui::BeginCombo("IES Profile", spotLightProfile.profileName.empty() ? "(none)" : spotLightProfile.profileName.c_str()))
{
selected = profile->name == spotLight.profileName;
if (ImGui::Selectable(profile->name.c_str(), &selected) && selected)
bool selected = spotLightProfile.profileName.empty();
if (ImGui::Selectable("(none)", &selected) && selected)
{
spotLight.profileName = profile->name;
spotLight.profileTextureIndex = -1;
spotLightProfile.profileName = "";
spotLightProfile.profileTextureIndex = -1;
}

if (selected)
for (auto profile : m_ui.resources->iesProfiles)
{
ImGui::SetItemDefaultFocus();
selected = profile->name == spotLightProfile.profileName;
if (ImGui::Selectable(profile->name.c_str(), &selected) && selected)
{
spotLightProfile.profileName = profile->name;
spotLightProfile.profileTextureIndex = -1;
}

if (selected)
{
ImGui::SetItemDefaultFocus();
}
}
}

ImGui::EndCombo();
ImGui::EndCombo();
}
ImGui::PopItemWidth();
}
ImGui::PopItemWidth();

if (ImGui::Button("Place Here"))
{
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ class SceneRenderer : public app::ApplicationBase
{
for (const auto& light : m_Scene->GetSceneGraph()->GetLights())
{
if (light->GetLightType() == LightType_Spot)
if (light->GetLightType() == LightType_SpotProfile)
{
SpotLightWithProfile& spotLight = static_cast<SpotLightWithProfile&>(*light);

Expand Down