Skip to content

Commit 83d8ff6

Browse files
author
Benjamin Glatzel
committed
Added support for wireframe rendering
* Highlight the currently selected mesh by drawing its wireframe representation
1 parent 857eac9 commit 83d8ff6

33 files changed

+231
-21
lines changed

IntrinsicCore/src/IntrinsicCoreComponentsMesh.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,6 @@ struct PerInstanceDataUpdateParallelTaskSet : enki::ITaskSet
8585
perInstanceDataFragment.data0.w = TaskManager::_totalTimePassed;
8686
perInstanceDataFragment.colorTint =
8787
Components::MeshManager::_descColorTint(meshCompRef);
88-
89-
// Modulate tint when entity is selected
90-
if (GameStates::Manager::getActiveGameState() ==
91-
GameStates::GameState::kEditing &&
92-
GameStates::Editing::_currentlySelectedEntity == entityRef)
93-
{
94-
perInstanceDataFragment.colorTint = glm::mix(
95-
perInstanceDataFragment.colorTint,
96-
glm::vec4(51.0f / 255.0f, 187.0f / 255.0f, 1.0f, 1.0f),
97-
glm::clamp(abs(sin(TaskManager::_totalTimePassed * 4.0f)) * 0.5f +
98-
0.5f,
99-
0.0f, 1.0f));
100-
}
10188
}
10289
}
10390
};

IntrinsicEd/src/IntrinsicEd.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ IntrinsicEd::IntrinsicEd(QWidget* parent) : QMainWindow(parent)
236236
this, SLOT(onDebugGeometryChanged()));
237237
QObject::connect(_ui.actionShow_Benchmark_Paths, SIGNAL(triggered()), this,
238238
SLOT(onDebugGeometryChanged()));
239+
QObject::connect(_ui.actionWireframe_Rendering, SIGNAL(triggered()), this,
240+
SLOT(onDebugGeometryChanged()));
239241

240242
QObject::connect(_ui.actionShow_Create_Context_Menu, SIGNAL(triggered()),
241243
this, SLOT(onShowCreateContextMenu()));
@@ -402,6 +404,7 @@ IntrinsicEd::IntrinsicEd(QWidget* parent) : QMainWindow(parent)
402404
_createContextMenu.addAction(_ui.actionCreateRigidBody);
403405
_createContextMenu.addAction(_ui.actionCreateRigidBody_Sphere);
404406

407+
_debugGeometryContextMenu.addAction(_ui.actionWireframe_Rendering);
405408
_debugGeometryContextMenu.addAction(_ui.actionShow_World_Bounding_Spheres);
406409
_debugGeometryContextMenu.addAction(_ui.actionShow_Benchmark_Paths);
407410
_debugGeometryContextMenu.addSeparator();
@@ -875,6 +878,19 @@ void IntrinsicEd::onDebugGeometryChanged()
875878
~Intrinsic::Renderer::Vulkan::RenderPass::DebugStageFlags::
876879
kBenchmarkPaths;
877880
}
881+
882+
if (_ui.actionWireframe_Rendering->isChecked())
883+
{
884+
Intrinsic::Renderer::Vulkan::RenderPass::Debug::_activeDebugStageFlags |=
885+
Intrinsic::Renderer::Vulkan::RenderPass::DebugStageFlags::
886+
kWireframeRendering;
887+
}
888+
else
889+
{
890+
Intrinsic::Renderer::Vulkan::RenderPass::Debug::_activeDebugStageFlags &=
891+
~Intrinsic::Renderer::Vulkan::RenderPass::DebugStageFlags::
892+
kWireframeRendering;
893+
}
878894
}
879895

880896
void IntrinsicEd::onCompileShaders()

IntrinsicEd/src/IntrinsicEd.ui

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,21 @@
731731
<string>Reload World</string>
732732
</property>
733733
</action>
734+
<action name="actionWireframe_Rendering">
735+
<property name="checkable">
736+
<bool>true</bool>
737+
</property>
738+
<property name="icon">
739+
<iconset resource="../IntrinsicEd.qrc">
740+
<normaloff>:/Icons/icons/geometry/tetrahedron.png</normaloff>:/Icons/icons/geometry/tetrahedron.png</iconset>
741+
</property>
742+
<property name="text">
743+
<string>Wireframe Rendering</string>
744+
</property>
745+
<property name="toolTip">
746+
<string>Wireframe Rendering</string>
747+
</property>
748+
</action>
734749
</widget>
735750
<layoutdefault spacing="6" margin="11"/>
736751
<customwidgets>

IntrinsicRendererVulkan/src/IntrinsicRendererVulkanRenderPassDebug.cpp

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,9 @@ void Debug::init()
193193
PipelineLayoutManager::resetToDefault(_debugLinePipelineLayout);
194194

195195
GpuProgramManager::reflectPipelineLayout(
196-
8u, {Resources::GpuProgramManager::getResourceByName("debug_line.vert"),
197-
GpuProgramManager::getResourceByName("debug_line.frag")},
196+
8u,
197+
{Resources::GpuProgramManager::getResourceByName("debug_line.vert"),
198+
GpuProgramManager::getResourceByName("debug_line.frag")},
198199
_debugLinePipelineLayout);
199200

200201
pipelineLayoutsToCreate.push_back(_debugLinePipelineLayout);
@@ -446,7 +447,10 @@ void Debug::render(float p_DeltaT, Components::CameraRef p_CameraRef)
446447
_INTR_PROFILE_CPU("Render Pass", "Render Debug Geometry");
447448
_INTR_PROFILE_GPU("Render Debug Geometry");
448449

449-
DrawCallRefArray visibleDrawCalls;
450+
static DrawCallRefArray visibleDrawCalls;
451+
static DrawCallRefArray visibleMeshDrawCalls;
452+
visibleMeshDrawCalls.clear();
453+
visibleDrawCalls.clear();
450454

451455
if (GameStates::Manager::getActiveGameState() !=
452456
GameStates::GameState::kEditing)
@@ -504,6 +508,38 @@ void Debug::render(float p_DeltaT, Components::CameraRef p_CameraRef)
504508
visibleDrawCalls.push_back(_debugLineDrawCallRef);
505509
}
506510

511+
if ((_activeDebugStageFlags & DebugStageFlags::kWireframeRendering) > 0u ||
512+
GameStates::Editing::_currentlySelectedEntity.isValid())
513+
{
514+
RenderProcess::Default::getVisibleDrawCalls(
515+
p_CameraRef, 0u,
516+
MaterialManager::getMaterialPassId(_N(GBufferWireframe)))
517+
.copy(visibleMeshDrawCalls);
518+
// Update per mesh uniform data
519+
Core::Components::MeshManager::updateUniformData(visibleMeshDrawCalls);
520+
521+
if ((_activeDebugStageFlags & DebugStageFlags::kWireframeRendering) > 0u)
522+
{
523+
visibleDrawCalls.insert(visibleDrawCalls.end(),
524+
visibleMeshDrawCalls.begin(),
525+
visibleMeshDrawCalls.end());
526+
}
527+
else
528+
{
529+
for (uint32_t i = 0u; i < visibleMeshDrawCalls.size(); ++i)
530+
{
531+
DrawCallRef dcRef = visibleMeshDrawCalls[i];
532+
Entity::EntityRef dcEntity = Components::MeshManager::_entity(
533+
DrawCallManager::_descMeshComponent(dcRef));
534+
535+
if (dcEntity == GameStates::Editing::_currentlySelectedEntity)
536+
{
537+
visibleDrawCalls.push_back(dcRef);
538+
}
539+
}
540+
}
541+
}
542+
507543
RenderSystem::beginRenderPass(_renderPassRef, _framebufferRef,
508544
VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
509545
{

IntrinsicRendererVulkan/src/IntrinsicRendererVulkanRenderPassDebug.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ struct DebugStageFlags
2828
{
2929
kWorldBoundingSpheres = 0x01u,
3030
kBenchmarkPaths = 0x02u,
31-
32-
kSelectedObject = 0x04u
31+
kSelectedObject = 0x04u,
32+
kWireframeRendering = 0x08u
3333
};
3434
};
3535

IntrinsicRendererVulkan/src/IntrinsicRendererVulkanRenderStates.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,24 @@ void initRasterizationStates()
151151
rs.depthBiasSlopeFactor = 0.0f;
152152
rs.lineWidth = 1.0f;
153153
}
154+
155+
{
156+
VkPipelineRasterizationStateCreateInfo& rs =
157+
RenderStates::rasterizationStates[RasterizationStates::kWireframe];
158+
rs.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
159+
rs.pNext = nullptr;
160+
rs.flags = 0;
161+
rs.polygonMode = VK_POLYGON_MODE_LINE;
162+
rs.cullMode = VK_CULL_MODE_BACK_BIT;
163+
rs.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
164+
rs.depthClampEnable = VK_FALSE;
165+
rs.rasterizerDiscardEnable = VK_FALSE;
166+
rs.depthBiasEnable = VK_TRUE;
167+
rs.depthBiasConstantFactor = -2.0f;
168+
rs.depthBiasClamp = 0.0f;
169+
rs.depthBiasSlopeFactor = 0.0f;
170+
rs.lineWidth = 3.0f;
171+
}
154172
}
155173

156174
void initBlendStates()

IntrinsicRendererVulkan/src/IntrinsicRendererVulkanRenderStates.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ enum Enum
3838
kDefault,
3939
kInvertedCulling,
4040
kDoubleSided,
41+
kWireframe,
4142

4243
kCount
4344
};

IntrinsicRendererVulkan/src/IntrinsicRendererVulkanResourcesMaterial.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,11 @@ void MaterialManager::loadMaterialPassConfig()
447447
PipelineManager::_descRasterizationState(pipelineRef) =
448448
RasterizationStates::kDoubleSided;
449449
}
450+
else if (materialPassDesc["rasterizationState"] == "Wireframe")
451+
{
452+
PipelineManager::_descRasterizationState(pipelineRef) =
453+
RasterizationStates::kWireframe;
454+
}
450455
}
451456

452457
if (materialPassDesc.HasMember("depthStencilState"))
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2016 Benjamin Glatzel
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#version 450
16+
17+
#extension GL_ARB_separate_shader_objects : enable
18+
#extension GL_ARB_shading_language_420pack : enable
19+
#extension GL_GOOGLE_include_directive : enable
20+
21+
#include "lib_math.glsl"
22+
#include "gbuffer.inc.glsl"
23+
24+
// Ubos
25+
PER_MATERIAL_UBO;
26+
PER_INSTANCE_UBO;
27+
28+
// Bindings
29+
BINDINGS_GBUFFER;
30+
layout (binding = 6) uniform sampler2D emissiveTex;
31+
32+
// Output
33+
OUTPUT
34+
35+
void main()
36+
{
37+
GBuffer gbuffer;
38+
{
39+
gbuffer.albedo = vec4(0.0, 0.5, 0.5, 1.0);
40+
gbuffer.normal = normalize(vec3(0.0, 1.0, 0.0));
41+
gbuffer.metalMask = 0.0;
42+
gbuffer.specular = 0.5;
43+
gbuffer.roughness = 1.0;
44+
gbuffer.materialBufferIdx = 0;
45+
gbuffer.emissive = 0.0;
46+
gbuffer.occlusion = 1.0;
47+
}
48+
writeGBuffer(gbuffer, outAlbedo, outNormal, outParameter0);
49+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2016 Benjamin Glatzel
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#version 450
16+
17+
#extension GL_ARB_separate_shader_objects : enable
18+
#extension GL_ARB_shading_language_420pack : enable
19+
#extension GL_GOOGLE_include_directive : enable
20+
21+
#include "gbuffer_vertex.inc.glsl"
22+
23+
out gl_PerVertex
24+
{
25+
vec4 gl_Position;
26+
};
27+
28+
PER_INSTANCE_UBO;
29+
INPUT();
30+
31+
void main()
32+
{
33+
gl_Position = uboPerInstance.worldViewProjMatrix * vec4(inPosition.xyz, 1.0);
34+
}

0 commit comments

Comments
 (0)