Skip to content

Commit

Permalink
lightmap leak fixes; updated xatlas; ortho shader fixes; (#993)
Browse files Browse the repository at this point in the history
  • Loading branch information
turanszkij authored Dec 21, 2024
1 parent fa5fc4b commit 2fda798
Show file tree
Hide file tree
Showing 19 changed files with 2,359 additions and 2,322 deletions.
24 changes: 18 additions & 6 deletions Editor/MeshWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,14 @@ void MeshWindow::Create(EditorComponent* _editor)
flipCullingButton.SetPos(XMFLOAT2(mod_x, y += step));
flipCullingButton.OnClick([&](wi::gui::EventArgs args) {
wi::scene::Scene& scene = editor->GetCurrentScene();
wi::unordered_set<MeshComponent*> visited_meshes; // fix double visit (straight mesh + object->mesh)
for (auto& x : editor->translator.selected)
{
MeshComponent* mesh = get_mesh(scene, x);
if (mesh == nullptr)
if (mesh == nullptr || visited_meshes.count(mesh) > 0)
continue;
mesh->FlipCulling();
visited_meshes.insert(mesh);
}
SetEntity(entity, subset);
});
Expand All @@ -266,12 +268,14 @@ void MeshWindow::Create(EditorComponent* _editor)
flipNormalsButton.SetPos(XMFLOAT2(mod_x, y += step));
flipNormalsButton.OnClick([&](wi::gui::EventArgs args) {
wi::scene::Scene& scene = editor->GetCurrentScene();
wi::unordered_set<MeshComponent*> visited_meshes; // fix double visit (straight mesh + object->mesh)
for (auto& x : editor->translator.selected)
{
MeshComponent* mesh = get_mesh(scene, x);
if (mesh == nullptr)
if (mesh == nullptr || visited_meshes.count(mesh) > 0)
continue;
mesh->FlipNormals();
visited_meshes.insert(mesh);
}
SetEntity(entity, subset);
});
Expand All @@ -283,12 +287,14 @@ void MeshWindow::Create(EditorComponent* _editor)
computeNormalsSmoothButton.SetPos(XMFLOAT2(mod_x, y += step));
computeNormalsSmoothButton.OnClick([&](wi::gui::EventArgs args) {
wi::scene::Scene& scene = editor->GetCurrentScene();
wi::unordered_set<MeshComponent*> visited_meshes; // fix double visit (straight mesh + object->mesh)
for (auto& x : editor->translator.selected)
{
MeshComponent* mesh = get_mesh(scene, x);
if (mesh == nullptr)
if (mesh == nullptr || visited_meshes.count(mesh) > 0)
continue;
mesh->ComputeNormals(MeshComponent::COMPUTE_NORMALS_SMOOTH);
visited_meshes.insert(mesh);
}
SetEntity(entity, subset);
});
Expand All @@ -300,12 +306,14 @@ void MeshWindow::Create(EditorComponent* _editor)
computeNormalsHardButton.SetPos(XMFLOAT2(mod_x, y += step));
computeNormalsHardButton.OnClick([&](wi::gui::EventArgs args) {
wi::scene::Scene& scene = editor->GetCurrentScene();
wi::unordered_set<MeshComponent*> visited_meshes; // fix double visit (straight mesh + object->mesh)
for (auto& x : editor->translator.selected)
{
MeshComponent* mesh = get_mesh(scene, x);
if (mesh == nullptr)
if (mesh == nullptr || visited_meshes.count(mesh) > 0)
continue;
mesh->ComputeNormals(MeshComponent::COMPUTE_NORMALS_HARD);
visited_meshes.insert(mesh);
}
SetEntity(entity, subset);
});
Expand All @@ -317,12 +325,14 @@ void MeshWindow::Create(EditorComponent* _editor)
recenterButton.SetPos(XMFLOAT2(mod_x, y += step));
recenterButton.OnClick([&](wi::gui::EventArgs args) {
wi::scene::Scene& scene = editor->GetCurrentScene();
wi::unordered_set<MeshComponent*> visited_meshes; // fix double visit (straight mesh + object->mesh)
for (auto& x : editor->translator.selected)
{
MeshComponent* mesh = get_mesh(scene, x);
if (mesh == nullptr)
if (mesh == nullptr || visited_meshes.count(mesh) > 0)
continue;
mesh->Recenter();
visited_meshes.insert(mesh);
}
});
AddWidget(&recenterButton);
Expand All @@ -333,12 +343,14 @@ void MeshWindow::Create(EditorComponent* _editor)
recenterToBottomButton.SetPos(XMFLOAT2(mod_x, y += step));
recenterToBottomButton.OnClick([&](wi::gui::EventArgs args) {
wi::scene::Scene& scene = editor->GetCurrentScene();
wi::unordered_set<MeshComponent*> visited_meshes; // fix double visit (straight mesh + object->mesh)
for (auto& x : editor->translator.selected)
{
MeshComponent* mesh = get_mesh(scene, x);
if (mesh == nullptr)
if (mesh == nullptr || visited_meshes.count(mesh) > 0)
continue;
mesh->RecenterToBottom();
visited_meshes.insert(mesh);
}
});
AddWidget(&recenterToBottomButton);
Expand Down
14 changes: 7 additions & 7 deletions Editor/ObjectWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static Atlas_Dim GenerateMeshAtlas(MeshComponent& meshcomponent, uint32_t resolu
mesh.indexCount = (int)meshcomponent.indices.size();
mesh.indexData = meshcomponent.indices.data();
mesh.indexFormat = xatlas::IndexFormat::UInt32;
xatlas::AddMeshError::Enum error = xatlas::AddMesh(atlas, mesh);
xatlas::AddMeshError error = xatlas::AddMesh(atlas, mesh);
if (error != xatlas::AddMeshError::Success) {
wi::helper::messageBox(xatlas::StringForEnum(error), "Adding mesh to xatlas failed!");
return dim;
Expand All @@ -94,13 +94,15 @@ static Atlas_Dim GenerateMeshAtlas(MeshComponent& meshcomponent, uint32_t resolu
// Generate atlas:
{
xatlas::ChartOptions chartoptions;
xatlas::ParameterizeOptions parametrizeoptions;
xatlas::PackOptions packoptions;
chartoptions.useInputMeshUvs = true;
chartoptions.fixWinding = true;

xatlas::PackOptions packoptions;
packoptions.resolution = resolution;
packoptions.blockAlign = true;
packoptions.padding = 2;

xatlas::Generate(atlas, chartoptions, parametrizeoptions, packoptions);
xatlas::Generate(atlas, chartoptions, packoptions);
dim.width = atlas->width;
dim.height = atlas->height;

Expand Down Expand Up @@ -543,13 +545,11 @@ void ObjectWindow::Create(EditorComponent* _editor)
y += step;


lightmapResolutionSlider.Create(32, 1024, 128, 1024 - 32, "Lightmap resolution: ");
lightmapResolutionSlider.Create(32, 8192, 512, 8192 - 32, "Lightmap resolution: ");
lightmapResolutionSlider.SetTooltip("Set the approximate resolution for this object's lightmap. This will be packed into the larger global lightmap later.");
lightmapResolutionSlider.SetSize(XMFLOAT2(wid, hei));
lightmapResolutionSlider.SetPos(XMFLOAT2(x, y += step));
lightmapResolutionSlider.OnSlide([&](wi::gui::EventArgs args) {
// unfortunately, we must be pow2 with full float lightmap format, otherwise it could be unlimited (but accumulation blending would suffer then)
// or at least for me, downloading the lightmap was glitching out when non-pow 2 and RGBA32_FLOAT format
lightmapResolutionSlider.SetValue(float(wi::math::GetNextPowerOfTwo(uint32_t(args.fValue))));
});
AddWidget(&lightmapResolutionSlider);
Expand Down
Loading

0 comments on commit 2fda798

Please sign in to comment.