Skip to content

Commit

Permalink
paint tool fixes; translator jitter removed when temporal AA enabled;
Browse files Browse the repository at this point in the history
  • Loading branch information
turanszkij committed Apr 28, 2022
1 parent d0b3f63 commit d2985ab
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 124 deletions.
6 changes: 3 additions & 3 deletions Editor/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,8 @@ void EditorComponent::Load()
////////////////////////////////////////////////////////////////////////////////////


translatorCheckBox.Create("Translator: ");
translatorCheckBox.SetTooltip("Enable the translator tool");
translatorCheckBox.Create("Transform: ");
translatorCheckBox.SetTooltip("Enable the transform tool");
translatorCheckBox.OnClick([&](wi::gui::EventArgs args) {
translator.enabled = args.bValue;
});
Expand Down Expand Up @@ -706,7 +706,7 @@ void EditorComponent::Load()
isRotatorCheckBox.SetCheck(translator.isRotator);
GetGUI().AddWidget(&isRotatorCheckBox);

isTranslatorCheckBox.SetTooltip("Translate");
isTranslatorCheckBox.SetTooltip("Translate (Move)");
isTranslatorCheckBox.OnClick([&](wi::gui::EventArgs args) {
translator.isTranslator = args.bValue;
translator.isScalator = false;
Expand Down
266 changes: 147 additions & 119 deletions Editor/PaintToolWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,39 +477,46 @@ void PaintToolWindow::Update(float dt)

if (wireframe)
{
for (size_t j = 0; j < mesh->indices.size(); j += 3)
uint32_t first_subset = 0;
uint32_t last_subset = 0;
mesh->GetLODSubsetRange(0, first_subset, last_subset);
for (uint32_t subsetIndex = first_subset; subsetIndex < last_subset; ++subsetIndex)
{
const uint32_t triangle[] = {
mesh->indices[j + 0],
mesh->indices[j + 1],
mesh->indices[j + 2],
};
if (subset >= 0 && (mesh->vertex_subsets[triangle[0]] != subset|| mesh->vertex_subsets[triangle[1]] != subset|| mesh->vertex_subsets[triangle[2]] != subset))
continue;

const XMVECTOR P[arraysize(triangle)] = {
XMVector3Transform(armature == nullptr ? XMLoadFloat3(&mesh->vertex_positions[triangle[0]]) : wi::scene::SkinVertex(*mesh, *armature, triangle[0]), W),
XMVector3Transform(armature == nullptr ? XMLoadFloat3(&mesh->vertex_positions[triangle[1]]) : wi::scene::SkinVertex(*mesh, *armature, triangle[1]), W),
XMVector3Transform(armature == nullptr ? XMLoadFloat3(&mesh->vertex_positions[triangle[2]]) : wi::scene::SkinVertex(*mesh, *armature, triangle[2]), W),
};

wi::renderer::RenderableTriangle tri;
XMStoreFloat3(&tri.positionA, P[0]);
XMStoreFloat3(&tri.positionB, P[1]);
XMStoreFloat3(&tri.positionC, P[2]);
if (mode == MODE_WIND)
const MeshComponent::MeshSubset& subset = mesh->subsets[subsetIndex];
for (size_t j = 0; j < subset.indexCount; j += 3)
{
tri.colorA = wi::Color(mesh->vertex_windweights[triangle[0]], 0, 0, 255);
tri.colorB = wi::Color(mesh->vertex_windweights[triangle[1]], 0, 0, 255);
tri.colorC = wi::Color(mesh->vertex_windweights[triangle[2]], 0, 0, 255);
}
else
{
tri.colorA.w = 0.8f;
tri.colorB.w = 0.8f;
tri.colorC.w = 0.8f;
const uint32_t triangle[] = {
mesh->indices[j + 0],
mesh->indices[j + 1],
mesh->indices[j + 2],
};
if (this->subset >= 0 && (mesh->vertex_subsets[triangle[0]] != this->subset || mesh->vertex_subsets[triangle[1]] != this->subset || mesh->vertex_subsets[triangle[2]] != this->subset))
continue;

const XMVECTOR P[arraysize(triangle)] = {
XMVector3Transform(armature == nullptr ? XMLoadFloat3(&mesh->vertex_positions[triangle[0]]) : wi::scene::SkinVertex(*mesh, *armature, triangle[0]), W),
XMVector3Transform(armature == nullptr ? XMLoadFloat3(&mesh->vertex_positions[triangle[1]]) : wi::scene::SkinVertex(*mesh, *armature, triangle[1]), W),
XMVector3Transform(armature == nullptr ? XMLoadFloat3(&mesh->vertex_positions[triangle[2]]) : wi::scene::SkinVertex(*mesh, *armature, triangle[2]), W),
};

wi::renderer::RenderableTriangle tri;
XMStoreFloat3(&tri.positionA, P[0]);
XMStoreFloat3(&tri.positionB, P[1]);
XMStoreFloat3(&tri.positionC, P[2]);
if (mode == MODE_WIND)
{
tri.colorA = wi::Color(mesh->vertex_windweights[triangle[0]], 0, 0, 255);
tri.colorB = wi::Color(mesh->vertex_windweights[triangle[1]], 0, 0, 255);
tri.colorC = wi::Color(mesh->vertex_windweights[triangle[2]], 0, 0, 255);
}
else
{
tri.colorA.w = 0.8f;
tri.colorB.w = 0.8f;
tri.colorC.w = 0.8f;
}
wi::renderer::DrawTriangle(tri, true);
}
wi::renderer::DrawTriangle(tri, true);
}
}

Expand Down Expand Up @@ -607,39 +614,46 @@ void PaintToolWindow::Update(float dt)

if (wireframe)
{
for (size_t j = 0; j < mesh->indices.size(); j += 3)
uint32_t first_subset = 0;
uint32_t last_subset = 0;
mesh->GetLODSubsetRange(0, first_subset, last_subset);
for (uint32_t subsetIndex = first_subset; subsetIndex < last_subset; ++subsetIndex)
{
const uint32_t triangle[] = {
mesh->indices[j + 0],
mesh->indices[j + 1],
mesh->indices[j + 2],
};
const XMVECTOR P[arraysize(triangle)] = {
XMVector3Transform(armature == nullptr ? XMLoadFloat3(&mesh->vertex_positions[triangle[0]]) : wi::scene::SkinVertex(*mesh, *armature, triangle[0]), W),
XMVector3Transform(armature == nullptr ? XMLoadFloat3(&mesh->vertex_positions[triangle[1]]) : wi::scene::SkinVertex(*mesh, *armature, triangle[1]), W),
XMVector3Transform(armature == nullptr ? XMLoadFloat3(&mesh->vertex_positions[triangle[2]]) : wi::scene::SkinVertex(*mesh, *armature, triangle[2]), W),
};
const MeshComponent::MeshSubset& subset = mesh->subsets[subsetIndex];
for (size_t j = 0; j < subset.indexCount; j += 3)
{
const uint32_t triangle[] = {
mesh->indices[j + 0],
mesh->indices[j + 1],
mesh->indices[j + 2],
};
const XMVECTOR P[arraysize(triangle)] = {
XMVector3Transform(armature == nullptr ? XMLoadFloat3(&mesh->vertex_positions[triangle[0]]) : wi::scene::SkinVertex(*mesh, *armature, triangle[0]), W),
XMVector3Transform(armature == nullptr ? XMLoadFloat3(&mesh->vertex_positions[triangle[1]]) : wi::scene::SkinVertex(*mesh, *armature, triangle[1]), W),
XMVector3Transform(armature == nullptr ? XMLoadFloat3(&mesh->vertex_positions[triangle[2]]) : wi::scene::SkinVertex(*mesh, *armature, triangle[2]), W),
};

wi::renderer::RenderableTriangle tri;
XMStoreFloat3(&tri.positionA, P[0]);
XMStoreFloat3(&tri.positionB, P[1]);
XMStoreFloat3(&tri.positionC, P[2]);
tri.colorA.w = 0.8f;
tri.colorB.w = 0.8f;
tri.colorC.w = 0.8f;
wi::renderer::DrawTriangle(tri, true);
}

wi::renderer::RenderableTriangle tri;
XMStoreFloat3(&tri.positionA, P[0]);
XMStoreFloat3(&tri.positionB, P[1]);
XMStoreFloat3(&tri.positionC, P[2]);
tri.colorA.w = 0.8f;
tri.colorB.w = 0.8f;
tri.colorC.w = 0.8f;
wi::renderer::DrawTriangle(tri, true);
wi::renderer::RenderableLine sculpt_dir_line;
sculpt_dir_line.color_start = XMFLOAT4(0, 1, 0, 1);
sculpt_dir_line.color_end = XMFLOAT4(0, 1, 0, 1);
sculpt_dir_line.start = editor->hovered.position;
XMStoreFloat3(
&sculpt_dir_line.end,
XMLoadFloat3(&sculpt_dir_line.start) +
XMVector3Normalize(XMLoadFloat3(&sculpting_normal))
);
wi::renderer::DrawLine(sculpt_dir_line);
}

wi::renderer::RenderableLine sculpt_dir_line;
sculpt_dir_line.color_start = XMFLOAT4(0, 1, 0, 1);
sculpt_dir_line.color_end = XMFLOAT4(0, 1, 0, 1);
sculpt_dir_line.start = editor->hovered.position;
XMStoreFloat3(
&sculpt_dir_line.end,
XMLoadFloat3(&sculpt_dir_line.start) +
XMVector3Normalize(XMLoadFloat3(&sculpting_normal))
);
wi::renderer::DrawLine(sculpt_dir_line);
}

if (rebuild)
Expand Down Expand Up @@ -687,50 +701,57 @@ void PaintToolWindow::Update(float dt)

// Visualizing:
const XMMATRIX W = XMLoadFloat4x4(&softbody->worldMatrix);
for (size_t j = 0; j < mesh->indices.size(); j += 3)
uint32_t first_subset = 0;
uint32_t last_subset = 0;
mesh->GetLODSubsetRange(0, first_subset, last_subset);
for (uint32_t subsetIndex = first_subset; subsetIndex < last_subset; ++subsetIndex)
{
const uint32_t graphicsIndex0 = mesh->indices[j + 0];
const uint32_t graphicsIndex1 = mesh->indices[j + 1];
const uint32_t graphicsIndex2 = mesh->indices[j + 2];
const uint32_t physicsIndex0 = softbody->graphicsToPhysicsVertexMapping[graphicsIndex0];
const uint32_t physicsIndex1 = softbody->graphicsToPhysicsVertexMapping[graphicsIndex1];
const uint32_t physicsIndex2 = softbody->graphicsToPhysicsVertexMapping[graphicsIndex2];
const float weight0 = softbody->weights[physicsIndex0];
const float weight1 = softbody->weights[physicsIndex1];
const float weight2 = softbody->weights[physicsIndex2];
wi::renderer::RenderableTriangle tri;
if (softbody->vertex_positions_simulation.empty())
{
XMStoreFloat3(&tri.positionA, XMVector3Transform(XMLoadFloat3(&mesh->vertex_positions[graphicsIndex0]), W));
XMStoreFloat3(&tri.positionB, XMVector3Transform(XMLoadFloat3(&mesh->vertex_positions[graphicsIndex1]), W));
XMStoreFloat3(&tri.positionC, XMVector3Transform(XMLoadFloat3(&mesh->vertex_positions[graphicsIndex2]), W));
}
else
{
tri.positionA = softbody->vertex_positions_simulation[graphicsIndex0].pos;
tri.positionB = softbody->vertex_positions_simulation[graphicsIndex1].pos;
tri.positionC = softbody->vertex_positions_simulation[graphicsIndex2].pos;
}
if (weight0 == 0)
tri.colorA = XMFLOAT4(1, 1, 0, 1);
else
tri.colorA = XMFLOAT4(1, 1, 1, 1);
if (weight1 == 0)
tri.colorB = XMFLOAT4(1, 1, 0, 1);
else
tri.colorB = XMFLOAT4(1, 1, 1, 1);
if (weight2 == 0)
tri.colorC = XMFLOAT4(1, 1, 0, 1);
else
tri.colorC = XMFLOAT4(1, 1, 1, 1);
if (wireframe)
{
wi::renderer::DrawTriangle(tri, true);
}
if (weight0 == 0 && weight1 == 0 && weight2 == 0)
const MeshComponent::MeshSubset& subset = mesh->subsets[subsetIndex];
for (size_t j = 0; j < subset.indexCount; j += 3)
{
tri.colorA = tri.colorB = tri.colorC = XMFLOAT4(1, 0, 0, 0.8f);
wi::renderer::DrawTriangle(tri);
const uint32_t graphicsIndex0 = mesh->indices[j + 0];
const uint32_t graphicsIndex1 = mesh->indices[j + 1];
const uint32_t graphicsIndex2 = mesh->indices[j + 2];
const uint32_t physicsIndex0 = softbody->graphicsToPhysicsVertexMapping[graphicsIndex0];
const uint32_t physicsIndex1 = softbody->graphicsToPhysicsVertexMapping[graphicsIndex1];
const uint32_t physicsIndex2 = softbody->graphicsToPhysicsVertexMapping[graphicsIndex2];
const float weight0 = softbody->weights[physicsIndex0];
const float weight1 = softbody->weights[physicsIndex1];
const float weight2 = softbody->weights[physicsIndex2];
wi::renderer::RenderableTriangle tri;
if (softbody->vertex_positions_simulation.empty())
{
XMStoreFloat3(&tri.positionA, XMVector3Transform(XMLoadFloat3(&mesh->vertex_positions[graphicsIndex0]), W));
XMStoreFloat3(&tri.positionB, XMVector3Transform(XMLoadFloat3(&mesh->vertex_positions[graphicsIndex1]), W));
XMStoreFloat3(&tri.positionC, XMVector3Transform(XMLoadFloat3(&mesh->vertex_positions[graphicsIndex2]), W));
}
else
{
tri.positionA = softbody->vertex_positions_simulation[graphicsIndex0].pos;
tri.positionB = softbody->vertex_positions_simulation[graphicsIndex1].pos;
tri.positionC = softbody->vertex_positions_simulation[graphicsIndex2].pos;
}
if (weight0 == 0)
tri.colorA = XMFLOAT4(1, 1, 0, 1);
else
tri.colorA = XMFLOAT4(1, 1, 1, 1);
if (weight1 == 0)
tri.colorB = XMFLOAT4(1, 1, 0, 1);
else
tri.colorB = XMFLOAT4(1, 1, 1, 1);
if (weight2 == 0)
tri.colorC = XMFLOAT4(1, 1, 0, 1);
else
tri.colorC = XMFLOAT4(1, 1, 1, 1);
if (wireframe)
{
wi::renderer::DrawTriangle(tri, true);
}
if (weight0 == 0 && weight1 == 0 && weight2 == 0)
{
tri.colorA = tri.colorB = tri.colorC = XMFLOAT4(1, 0, 0, 0.8f);
wi::renderer::DrawTriangle(tri);
}
}
}
}
Expand Down Expand Up @@ -811,24 +832,31 @@ void PaintToolWindow::Update(float dt)

if (wireframe)
{
for (size_t j = 0; j < mesh->indices.size(); j += 3)
uint32_t first_subset = 0;
uint32_t last_subset = 0;
mesh->GetLODSubsetRange(0, first_subset, last_subset);
for (uint32_t subsetIndex = first_subset; subsetIndex < last_subset; ++subsetIndex)
{
const uint32_t triangle[] = {
mesh->indices[j + 0],
mesh->indices[j + 1],
mesh->indices[j + 2],
};
const XMVECTOR P[arraysize(triangle)] = {
XMVector3Transform(armature == nullptr ? XMLoadFloat3(&mesh->vertex_positions[triangle[0]]) : wi::scene::SkinVertex(*mesh, *armature, triangle[0]), W),
XMVector3Transform(armature == nullptr ? XMLoadFloat3(&mesh->vertex_positions[triangle[1]]) : wi::scene::SkinVertex(*mesh, *armature, triangle[1]), W),
XMVector3Transform(armature == nullptr ? XMLoadFloat3(&mesh->vertex_positions[triangle[2]]) : wi::scene::SkinVertex(*mesh, *armature, triangle[2]), W),
};

wi::renderer::RenderableTriangle tri;
XMStoreFloat3(&tri.positionA, P[0]);
XMStoreFloat3(&tri.positionB, P[1]);
XMStoreFloat3(&tri.positionC, P[2]);
wi::renderer::DrawTriangle(tri, true);
const MeshComponent::MeshSubset& subset = mesh->subsets[subsetIndex];
for (size_t j = 0; j < subset.indexCount; j += 3)
{
const uint32_t triangle[] = {
mesh->indices[j + 0],
mesh->indices[j + 1],
mesh->indices[j + 2],
};
const XMVECTOR P[arraysize(triangle)] = {
XMVector3Transform(armature == nullptr ? XMLoadFloat3(&mesh->vertex_positions[triangle[0]]) : wi::scene::SkinVertex(*mesh, *armature, triangle[0]), W),
XMVector3Transform(armature == nullptr ? XMLoadFloat3(&mesh->vertex_positions[triangle[1]]) : wi::scene::SkinVertex(*mesh, *armature, triangle[1]), W),
XMVector3Transform(armature == nullptr ? XMLoadFloat3(&mesh->vertex_positions[triangle[2]]) : wi::scene::SkinVertex(*mesh, *armature, triangle[2]), W),
};

wi::renderer::RenderableTriangle tri;
XMStoreFloat3(&tri.positionA, P[0]);
XMStoreFloat3(&tri.positionB, P[1]);
XMStoreFloat3(&tri.positionC, P[2]);
wi::renderer::DrawTriangle(tri, true);
}
}

for (size_t j = 0; j < hair->indices.size() && wireframe; j += 3)
Expand Down
5 changes: 4 additions & 1 deletion Editor/Translator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,10 @@ void Translator::Draw(const CameraComponent& camera, CommandList cmd) const

device->EventBegin("Editor - Translator", cmd);

XMMATRIX VP = camera.GetViewProjection();
CameraComponent cam_tmp = camera;
cam_tmp.jitter = XMFLOAT2(0, 0); // remove temporal jitter
cam_tmp.UpdateCamera();
XMMATRIX VP = cam_tmp.GetViewProjection();

MiscCB sb;

Expand Down
1 change: 1 addition & 0 deletions WickedEngine/wiRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5906,6 +5906,7 @@ void DrawDebugWorld(
ShaderMeshInstancePointer poi;
poi.init();
poi.instanceIndex = (uint)scene.objects.GetIndex(x.objectEntity);
std::memcpy(mem.data, &poi, sizeof(poi));

device->BindIndexBuffer(&mesh.generalBuffer, mesh.GetIndexFormat(), mesh.ib.offset, cmd);

Expand Down
2 changes: 1 addition & 1 deletion WickedEngine/wiVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace wi::version
// minor features, major updates, breaking compatibility changes
const int minor = 60;
// minor bug fixes, alterations, refactors, updates
const int revision = 60;
const int revision = 61;

const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);

Expand Down

0 comments on commit d2985ab

Please sign in to comment.