Skip to content

Commit f0e141f

Browse files
committed
WIP: shaders, imgui fix, materials, project render save
1 parent a5c0600 commit f0e141f

26 files changed

Lines changed: 912 additions & 207 deletions

Core/Source/Lux/Asset/MeshRuntimeSerializer.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@
1111

1212
namespace Lux
1313
{
14+
namespace
15+
{
16+
std::string NormalizeRuntimeMaterialShaderName(std::string shaderName)
17+
{
18+
if (shaderName == "LuxPBR_Static")
19+
return "HazelPBR_Static";
20+
21+
if (shaderName == "LuxPBR_Transparent")
22+
return "HazelPBR_Transparent";
23+
24+
return shaderName;
25+
}
26+
}
27+
1428
struct MeshMaterial
1529
{
1630
std::string MaterialName;
@@ -104,7 +118,7 @@ namespace Lux
104118

105119
material.MaterialName = sourceMaterial->GetName();
106120
if (Ref<Shader> shader = sourceMaterial->GetShader())
107-
material.ShaderName = shader->GetName();
121+
material.ShaderName = NormalizeRuntimeMaterialShaderName(shader->GetName());
108122
material.AlbedoColor = materialAsset->GetAlbedoColor();
109123
material.Emission = materialAsset->GetEmission();
110124
material.Metalness = materialAsset->GetMetalness();
@@ -183,9 +197,16 @@ namespace Lux
183197
if (Ref<ShaderLibrary> shaderLibrary = Renderer::GetShaderLibrary())
184198
{
185199
const auto& shaders = shaderLibrary->GetShaders();
186-
if (!meshMaterial.ShaderName.empty())
200+
const std::string shaderName = NormalizeRuntimeMaterialShaderName(meshMaterial.ShaderName);
201+
if (!shaderName.empty())
202+
{
203+
if (auto it = shaders.find(shaderName); it != shaders.end())
204+
shader = it->second;
205+
}
206+
207+
if (!shader)
187208
{
188-
if (auto it = shaders.find(meshMaterial.ShaderName); it != shaders.end())
209+
if (auto it = shaders.find("HazelPBR_Static"); it != shaders.end())
189210
shader = it->second;
190211
}
191212

Core/Source/Lux/ImGui/ImGuiEx.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,15 @@ namespace Lux::ImGuiEx {
135135
window->DC.CurrLineTextBaseOffset = 3.0f;
136136
const ImVec2 rowAreaMin = ImGui::TableGetCellBgRect(ImGui::GetCurrentTable(), 0).Min;
137137
const ImVec2 rowAreaMax = { ImGui::TableGetCellBgRect(ImGui::GetCurrentTable(), ImGui::TableGetColumnCount() - 1).Max.x, rowAreaMin.y + rowHeight };
138+
const ImRect rowArea(rowAreaMin, rowAreaMax);
139+
if (rowArea.Min.x > rowArea.Max.x || rowArea.Min.y > rowArea.Max.y)
140+
return false;
138141

139-
ImGui::PushClipRect(rowAreaMin, rowAreaMax, false);
142+
ImGui::PushClipRect(rowArea.Min, rowArea.Max, false);
140143
ImGui::SetNextItemAllowOverlap();
141144

142145
bool isRowHovered, held;
143-
bool isRowClicked = ImGui::ButtonBehavior(ImRect(rowAreaMin, rowAreaMax), ImGui::GetID(id),
146+
bool isRowClicked = ImGui::ButtonBehavior(rowArea, ImGui::GetID(id),
144147
&isRowHovered, &held, ImGuiButtonFlags_AllowOverlap);
145148

146149
ImGui::PopClipRect();

Core/Source/Lux/ImGui/ImGuiUtilities.cpp

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55

66
namespace Lux::ImGuiEx {
77

8+
namespace
9+
{
10+
bool IsValidClipRect(const ImRect& rect)
11+
{
12+
return rect.Min.x <= rect.Max.x && rect.Min.y <= rect.Max.y;
13+
}
14+
}
15+
816
ScopedDisable::ScopedDisable(bool disabled /*= true*/)
917
{
1018
ImGuiEx::BeginDisabled(disabled);
@@ -24,12 +32,15 @@ namespace Lux::ImGuiEx {
2432
// Fill background wiht nice gradient
2533
const float padding = ImGui::GetStyle().WindowBorderSize;
2634
const ImRect windowRect = ImGuiEx::RectExpanded(ImGui::GetCurrentWindow()->Rect(), -padding, -padding);
27-
ImGui::PushClipRect(windowRect.Min, windowRect.Max, false);
28-
const ImColor col1 = ImGui::GetStyleColorVec4(ImGuiCol_PopupBg);// Colors::Theme::backgroundPopup;
29-
const ImColor col2 = ImGuiEx::ColourWithMultipliedValue(col1, 0.8f);
30-
ImGui::GetWindowDrawList()->AddRectFilledMultiColor(windowRect.Min, windowRect.Max, col1, col1, col2, col2);
31-
ImGui::GetWindowDrawList()->AddRect(windowRect.Min, windowRect.Max, ImGuiEx::ColourWithMultipliedValue(col1, 1.1f));
32-
ImGui::PopClipRect();
35+
if (IsValidClipRect(windowRect))
36+
{
37+
ImGui::PushClipRect(windowRect.Min, windowRect.Max, false);
38+
const ImColor col1 = ImGui::GetStyleColorVec4(ImGuiCol_PopupBg);// Colors::Theme::backgroundPopup;
39+
const ImColor col2 = ImGuiEx::ColourWithMultipliedValue(col1, 0.8f);
40+
ImGui::GetWindowDrawList()->AddRectFilledMultiColor(windowRect.Min, windowRect.Max, col1, col1, col2, col2);
41+
ImGui::GetWindowDrawList()->AddRect(windowRect.Min, windowRect.Max, ImGuiEx::ColourWithMultipliedValue(col1, 1.1f));
42+
ImGui::PopClipRect();
43+
}
3344

3445
// Popped in EndPopup()
3546
ImGui::PushStyleColor(ImGuiCol_HeaderHovered, IM_COL32(0, 0, 0, 80));
@@ -68,6 +79,15 @@ namespace Lux::ImGuiEx {
6879
IM_ROUND(ImMax(bar_rect.Min.x + window->Pos.x, bar_rect.Max.x - ImMax(window->WindowRounding, window->WindowBorderSize))), IM_ROUND(bar_rect.Max.y + window->Pos.y));
6980

7081
clip_rect.ClipWith(window->OuterRectClipped);
82+
if (!IsValidClipRect(clip_rect))
83+
{
84+
ImGuiContext& g = *GImGui;
85+
ImGui::PopID();
86+
g.GroupStack.back().EmitItem = false;
87+
ImGui::EndGroup();
88+
return false;
89+
}
90+
7191
ImGui::PushClipRect(clip_rect.Min, clip_rect.Max, false);
7292

7393
// We overwrite CursorMaxPos because BeginGroup sets it to CursorPos (essentially the .EmitItem hack in EndMenuBar() would need something analogous here, maybe a BeginGroupEx() with flags).
@@ -681,6 +701,9 @@ namespace Lux::ImGuiEx {
681701
ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed,
682702
ImVec2 rectMin, ImVec2 rectMax, ImVec2 uv0, ImVec2 uv1)
683703
{
704+
if (rectMin.x > rectMax.x || rectMin.y > rectMax.y)
705+
return;
706+
684707
auto* drawList = ImGui::GetWindowDrawList();
685708
if (ImGui::IsItemActive())
686709
drawList->AddImage(GetTextureID(imagePressed), rectMin, rectMax, uv0, uv1, tintPressed);
@@ -694,6 +717,9 @@ namespace Lux::ImGuiEx {
694717
ImU32 tintNormal, ImU32 tintHovered, ImU32 tintPressed,
695718
ImVec2 rectMin, ImVec2 rectMax, ImVec2 uv0, ImVec2 uv1)
696719
{
720+
if (rectMin.x > rectMax.x || rectMin.y > rectMax.y)
721+
return;
722+
697723
auto* drawList = ImGui::GetWindowDrawList();
698724
if (ImGui::IsItemActive())
699725
drawList->AddImage(GetTextureID(imagePressed), rectMin, rectMax, uv0, uv1, tintPressed);

Core/Source/Lux/Platform/Vulkan/VulkanRenderer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ namespace Lux {
10961096
{
10971097
LUX_PROFILE_FUNC("VulkanRenderer::SetSceneEnvironment");
10981098

1099-
const auto shader = Renderer::GetShaderLibrary()->Get("LuxPBR_Static");
1099+
const auto shader = Renderer::GetShaderLibrary()->Get("HazelPBR_Static");
11001100
Ref<VulkanShader> pbrShader = shader.As<VulkanShader>();
11011101
const uint32_t bufferIndex = Renderer::RT_GetCurrentFrameIndex();
11021102

Core/Source/Lux/Project/Project.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,42 @@ namespace Lux
5050
std::vector<ProjectPhysicsLayer> Layers;
5151
};
5252

53+
struct ProjectSceneRendererSettings
54+
{
55+
bool EnableFrustumCulling = true;
56+
bool EnableGPUDrivenRendering = true;
57+
bool EnableGTAO = true;
58+
bool GTAOBentNormals = false;
59+
int GTAODenoisePasses = 4;
60+
float AOShadowTolerance = 1.0f;
61+
bool EnableSSR = false;
62+
bool EnableJumpFlood = true;
63+
64+
bool SoftShadows = true;
65+
float MaxShadowDistance = 200.0f;
66+
float ShadowFade = 25.0f;
67+
float ShadowCascadeSplitLambda = 0.92f;
68+
float ShadowCascadeNearPlaneOffset = 0.0f;
69+
float ShadowCascadeFarPlaneOffset = 50.0f;
70+
float ShadowCascadeTransitionFade = 1.0f;
71+
72+
bool BloomEnabled = true;
73+
float BloomThreshold = 1.0f;
74+
float BloomKnee = 0.1f;
75+
float BloomUpsampleScale = 1.0f;
76+
float BloomIntensity = 1.0f;
77+
float BloomDirtIntensity = 1.0f;
78+
79+
bool DOFEnabled = false;
80+
float DOFFocusDistance = 0.0f;
81+
float DOFBlurSize = 1.0f;
82+
83+
bool SSRHalfRes = true;
84+
int SSRMaxSteps = 70;
85+
float SSRBrightness = 0.7f;
86+
float SSRDepthTolerance = 0.8f;
87+
};
88+
5389
struct ProjectConfig
5490
{
5591
std::string Name = "Untitled";
@@ -76,6 +112,7 @@ namespace Lux
76112

77113
ProjectAudioSettings Audio;
78114
ProjectPhysicsSettings Physics;
115+
ProjectSceneRendererSettings SceneRenderer;
79116
};
80117

81118
class Project : public RefCounted

Core/Source/Lux/Project/ProjectRuntimeFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Lux
1111
struct FileHeader
1212
{
1313
char Header[4] = { 'L', 'P', 'R', 'J' };
14-
uint32_t Version = 1;
14+
uint32_t Version = 2;
1515
};
1616

1717
struct Audio

0 commit comments

Comments
 (0)