mirror of
https://github.com/barkeser2002/flower.git
synced 2026-09-25 20:17:06 +03:00
202 lines
7.8 KiB
C++
202 lines
7.8 KiB
C++
#include "component_draw.h"
|
|
#include <imgui/ui.h>
|
|
#include <scene/scene.h>
|
|
#include "../editor/editor.h"
|
|
#include "../editor/widgets/project_content.h"
|
|
#include <scene/component/sky.h>
|
|
|
|
using namespace engine;
|
|
using namespace engine::ui;
|
|
|
|
void drawCascadeConfig(CascadeShadowConfig& inout)
|
|
{
|
|
auto copyValue = inout;
|
|
|
|
if (ImGui::CollapsingHeader("Shadow Setting"))
|
|
{
|
|
ui::beginGroupPanel("Cascade Config");
|
|
ImGui::PushItemWidth(100.0f);
|
|
ImGui::DragInt("Count", ©Value.cascadeCount, 1.0f, 1, kMaxCascadeNum);
|
|
ImGui::DragInt("ShadowMap Size", ©Value.percascadeDimXY, 512, kMinCascadeDimSize, kMaxCascadeDimSize);
|
|
ImGui::DragFloat("Split Lambda", ©Value.cascadeSplitLambda, 0.01f, 0.0f, 2.0f);
|
|
ImGui::DragFloat("Border Adopt", ©Value.cascadeBorderAdopt, 0.00001f, 0.0f, 0.001f);
|
|
ImGui::DragFloat("Edge Lerp Threshold", ©Value.cascadeEdgeLerpThreshold, 0.01f, 0.0f, 1.0f);
|
|
ImGui::DragFloat("Max Draw Distance", ©Value.maxDrawDepthDistance, 10.0f, 50.0f, 800.0f);
|
|
ImGui::PopItemWidth();
|
|
ui::endGroupPanel();
|
|
|
|
ui::beginGroupPanel("Filter Config");
|
|
ImGui::PushItemWidth(100.0f);
|
|
ImGui::DragFloat("Size", ©Value.shadowFilterSize, 0.01f, 0.0f, 2.0f);
|
|
ImGui::DragFloat("Max Size", ©Value.maxFilterSize, 0.01f, 0.0f, 10.0f);
|
|
ImGui::DragFloat("Depth Bias Const", ©Value.shadowBiasConst, 0.01f, -5.0f, 5.0f);
|
|
ImGui::DragFloat("Depth Bias Slope", ©Value.shadowBiasSlope, 0.01f, -5.0f, 5.0f);
|
|
ImGui::PopItemWidth();
|
|
ui::endGroupPanel();
|
|
}
|
|
|
|
copyValue.percascadeDimXY = glm::clamp(getNextPOT(copyValue.percascadeDimXY), kMinCascadeDimSize, kMaxCascadeDimSize);
|
|
copyValue.cascadeCount = glm::clamp(copyValue.cascadeCount, 1, kMaxCascadeNum);
|
|
|
|
if (copyValue != inout)
|
|
{
|
|
inout = copyValue;
|
|
}
|
|
}
|
|
|
|
void drawAtmosphereConfig(AtmosphereConfig& inout)
|
|
{
|
|
if (ImGui::CollapsingHeader("Atmosphere Config"))
|
|
{
|
|
ImGui::Spacing();
|
|
if (ImGui::Button("Reset Atmosphere"))
|
|
{
|
|
inout.resetAtmosphere();
|
|
}
|
|
ImGui::Spacing();
|
|
auto copyValue = inout;
|
|
|
|
float atmosphereHeight = copyValue.topRadius - copyValue.bottomRadius;
|
|
|
|
ui::beginGroupPanel("Size Config");
|
|
ImGui::PushItemWidth(100.0f);
|
|
{
|
|
|
|
ImGui::DragFloat("Pre Exposure", ©Value.atmospherePreExposure, 0.01f, 0.01f, 1.0f);
|
|
ImGui::DragFloat("Mie Phase", ©Value.miePhaseFunctionG, 0.0f, 0.01f, 0.99f);
|
|
ImGui::DragFloat("Multi Scatter", ©Value.multipleScatteringFactor, 0.01f, 0.01f, 1.0f, "%.6f");
|
|
ImGui::SliderInt("Min SPP", ©Value.viewRayMarchMinSPP, 1, 30);
|
|
ImGui::SliderInt("Max SPP", ©Value.viewRayMarchMaxSPP, 2, 31);
|
|
ImGui::DragFloat("Planet Radius(km)", ©Value.bottomRadius, 100.0f, 8000.0f);
|
|
ImGui::DragFloat("Atmosphere Height(km)", &atmosphereHeight, 10.0f, 150.0f);
|
|
}
|
|
ImGui::PopItemWidth();
|
|
ui::endGroupPanel();
|
|
|
|
ui::beginGroupPanel("Render Config");
|
|
ImGui::PushItemWidth(150.0f);
|
|
{
|
|
ImGui::ColorEdit3("Ground Albedo", ©Value.groundAlbedo.x);
|
|
|
|
ImGui::ColorEdit3("Mie Scatter Color", ©Value.mieScatteringColor.x);
|
|
ImGui::DragFloat("Mie Scatter Scale", ©Value.mieScatteringLength, 0.00001f, 0.1f, 10.0f, "%.6f");
|
|
|
|
ImGui::ColorEdit3("Mie Absorb Color", ©Value.mieAbsColor.x);
|
|
ImGui::DragFloat("Mie Absorb Scale", ©Value.mieAbsLength, 0.00001f, 10.0f, 1000.0f, "%.6f");
|
|
|
|
ImGui::ColorEdit3("Ray Scatter Color", ©Value.rayleighScatteringColor.x);
|
|
ImGui::DragFloat("Ray Scatter Scale", ©Value.rayleighScatterLength, 0.00001f, 10.0f, 1000.0f, "%.6f");
|
|
|
|
ImGui::ColorEdit3("Ozone Absorb Color", ©Value.absorptionColor.x);
|
|
ImGui::DragFloat("Ozone Absorb Scale", ©Value.absorptionLength, 0.00001f, 10.0f, 1000.0f, "%.6f");
|
|
|
|
// Additional info.
|
|
float earthAtmosphereMieScaleHeight = -1.0f / copyValue.mieDensity[7];
|
|
float earthAtmosphereRayleighScaleHeight = -1.0f / copyValue.rayleighDensity[7];
|
|
|
|
ImGui::DragFloat("Mie Scale Height", &earthAtmosphereMieScaleHeight, 0.5f, 20.0f, 1000.0f, "%.6f");
|
|
ImGui::DragFloat("Ray Scale Height", &earthAtmosphereRayleighScaleHeight, 0.5f, 20.0f, 1000.0f, "%.6f");
|
|
}
|
|
ImGui::PopItemWidth();
|
|
ui::endGroupPanel();
|
|
|
|
copyValue.topRadius = copyValue.bottomRadius + atmosphereHeight;
|
|
|
|
if (copyValue != inout)
|
|
{
|
|
inout = copyValue;
|
|
}
|
|
}
|
|
|
|
if (ImGui::CollapsingHeader("Cloud Setting"))
|
|
{
|
|
ImGui::PushItemWidth(150.0f);
|
|
ImGui::Spacing();
|
|
if (ImGui::Button("Reset Cloud"))
|
|
{
|
|
inout.resetCloud();
|
|
}
|
|
ImGui::Spacing();
|
|
auto copyValue = inout;
|
|
|
|
float cloudBottomAltitude = copyValue.cloudAreaStartHeight - copyValue.bottomRadius;
|
|
|
|
ImGui::DragFloat("start height(km)", &cloudBottomAltitude, 0.1f, 0.0f, 20.0f);
|
|
ImGui::DragFloat("thickness(km)", ©Value.cloudAreaThickness, 0.1f, 0.1f, 20.0f);
|
|
|
|
|
|
ImGui::DragFloat("coverage", ©Value.cloudCoverage, 0.1f, 0.0f, 2.0f);
|
|
ImGui::DragFloat("density", ©Value.cloudDensity, 0.1f, 0.0f, 5.0f);
|
|
|
|
ImGui::DragFloat("sun light scale", ©Value.cloudShadingSunLightScale, 0.1f, 0.1f, 10.0f);
|
|
ImGui::DragFloat3("wind dir", ©Value.cloudDirection.x, 0.01f, 0.0f);
|
|
ImGui::DragFloat("wind speed", ©Value.cloudSpeed, 0.1f, 0.0f, 1.0f);
|
|
ImGui::DragFloat("multi scatter", ©Value.cloudMultiScatterScatter, 0.1f, 0.0f, 1.0f);
|
|
ImGui::DragFloat("multi extinction", ©Value.cloudMultiScatterExtinction, 0.1f, 0.0f, 1.0f);
|
|
ImGui::DragFloat("phase forward", ©Value.cloudPhaseForward, 0.01f, 0.01f, 0.99f);
|
|
ImGui::DragFloat("phase backward", ©Value.cloudPhaseBackward, 0.01f, -0.99f, -0.01f);
|
|
ImGui::DragFloat("phase mix factor", ©Value.cloudPhaseMixFactor, 0.01f, 0.01f, 0.99f);
|
|
|
|
ImGui::ColorEdit3("cloud albedo", ©Value.cloudAlbedo.x);
|
|
ImGui::DragFloat("light step mul", ©Value.cloudLightStepMul, 0.01f, 1.01f, 1.5f);
|
|
ImGui::DragFloat("light basic step", ©Value.cloudLightBasicStep, 0.01f, 0.10f, 0.5f);
|
|
ImGui::DragInt("light step num", ©Value.cloudLightStepNum, 1, 6, 24);
|
|
|
|
ImGui::DragInt("light marching step", ©Value.cloudMarchingStepNum, 1, 24, 512);
|
|
|
|
#if 0
|
|
ImGui::DragInt("noise octaves", ©Value.cloudSunLitMapOctave, 1, 2, 8);
|
|
|
|
#endif
|
|
|
|
ImGui::DragFloat("ground mix sky", ©Value.cloudNoiseScale, 0.01f, 0.01f, 5.0f);
|
|
|
|
ImGui::DragFloat("max tracing distance", ©Value.cloudMaxTraceingDistance, 1.0f, 10.0f, 100.0f);
|
|
ImGui::DragFloat("max tracing start distance", ©Value.cloudTracingStartMaxDistance, 1.0f, 300.0f, 500.0f);
|
|
|
|
ImGui::DragFloat2("Wether UV scale", ©Value.cloudWeatherUVScale.x, 0.0f, 0.01f);
|
|
ImGui::DragFloat("basic noise scale", ©Value.cloudBasicNoiseScale, 0.01f, 0.0f, 1.0f);
|
|
ImGui::DragFloat("detail noise scale", ©Value.cloudDetailNoiseScale, 0.01f, 0.0f, 1.0f);
|
|
|
|
ImGui::DragFloat("shadow extent(km)", ©Value.cloudShadowExtent, 0.1f, 1.0f, 50.0f);
|
|
bool bEnableGroundContribution = copyValue.cloudEnableGroundContribution != 0;
|
|
ImGui::Checkbox("enable ambient contribution", &bEnableGroundContribution);
|
|
copyValue.cloudEnableGroundContribution = bEnableGroundContribution ? 1 : 0;
|
|
ImGui::DragFloat("ground contribution", ©Value.cloudFogFade, 0.01f, 0.0f, 1.0f);
|
|
ImGui::DragFloat("cloud powder scale", ©Value.cloudPowderScale, 0.1f, 0.01f, 100.0f);
|
|
ImGui::DragFloat("cloud powder pow", ©Value.cloudPowderPow, 0.1f, 0.01f, 10.0f);
|
|
|
|
bool bEnableGodRay = copyValue.cloudGodRay != 0;
|
|
ImGui::Checkbox("enable cloud godray", &bEnableGodRay);
|
|
copyValue.cloudGodRay = bEnableGodRay ? 1 : 0;
|
|
|
|
ImGui::DragFloat("cloud godray scale", ©Value.cloudGodRayScale, 1.0f, 1.0f, 100.0f);
|
|
|
|
ImGui::Spacing();
|
|
ImGui::PopItemWidth();
|
|
|
|
copyValue.cloudAreaStartHeight = cloudBottomAltitude + copyValue.bottomRadius;
|
|
|
|
if (copyValue != inout)
|
|
{
|
|
inout = copyValue;
|
|
}
|
|
}
|
|
}
|
|
|
|
void ComponentDrawer::drawSky(std::shared_ptr<SceneNode> node)
|
|
{
|
|
auto comp = node->getComponent<SkyComponent>();
|
|
|
|
drawLight(comp);
|
|
|
|
ImGui::Separator();
|
|
ImGui::Spacing();
|
|
|
|
if (!comp->isRayTraceShadow())
|
|
{
|
|
drawCascadeConfig(comp->getCacsadeConfig());
|
|
}
|
|
|
|
drawAtmosphereConfig(comp->getAtmosphereConfig());
|
|
} |