Skip to content

Commit

Permalink
Added support for wireframe rendering
Browse files Browse the repository at this point in the history
* Highlight the currently selected mesh by drawing its wireframe representation
  • Loading branch information
Benjamin Glatzel committed Jun 5, 2017
1 parent 857eac9 commit 83d8ff6
Show file tree
Hide file tree
Showing 33 changed files with 231 additions and 21 deletions.
13 changes: 0 additions & 13 deletions IntrinsicCore/src/IntrinsicCoreComponentsMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,6 @@ struct PerInstanceDataUpdateParallelTaskSet : enki::ITaskSet
perInstanceDataFragment.data0.w = TaskManager::_totalTimePassed;
perInstanceDataFragment.colorTint =
Components::MeshManager::_descColorTint(meshCompRef);

// Modulate tint when entity is selected
if (GameStates::Manager::getActiveGameState() ==
GameStates::GameState::kEditing &&
GameStates::Editing::_currentlySelectedEntity == entityRef)
{
perInstanceDataFragment.colorTint = glm::mix(
perInstanceDataFragment.colorTint,
glm::vec4(51.0f / 255.0f, 187.0f / 255.0f, 1.0f, 1.0f),
glm::clamp(abs(sin(TaskManager::_totalTimePassed * 4.0f)) * 0.5f +
0.5f,
0.0f, 1.0f));
}
}
}
};
Expand Down
16 changes: 16 additions & 0 deletions IntrinsicEd/src/IntrinsicEd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ IntrinsicEd::IntrinsicEd(QWidget* parent) : QMainWindow(parent)
this, SLOT(onDebugGeometryChanged()));
QObject::connect(_ui.actionShow_Benchmark_Paths, SIGNAL(triggered()), this,
SLOT(onDebugGeometryChanged()));
QObject::connect(_ui.actionWireframe_Rendering, SIGNAL(triggered()), this,
SLOT(onDebugGeometryChanged()));

QObject::connect(_ui.actionShow_Create_Context_Menu, SIGNAL(triggered()),
this, SLOT(onShowCreateContextMenu()));
Expand Down Expand Up @@ -402,6 +404,7 @@ IntrinsicEd::IntrinsicEd(QWidget* parent) : QMainWindow(parent)
_createContextMenu.addAction(_ui.actionCreateRigidBody);
_createContextMenu.addAction(_ui.actionCreateRigidBody_Sphere);

_debugGeometryContextMenu.addAction(_ui.actionWireframe_Rendering);
_debugGeometryContextMenu.addAction(_ui.actionShow_World_Bounding_Spheres);
_debugGeometryContextMenu.addAction(_ui.actionShow_Benchmark_Paths);
_debugGeometryContextMenu.addSeparator();
Expand Down Expand Up @@ -875,6 +878,19 @@ void IntrinsicEd::onDebugGeometryChanged()
~Intrinsic::Renderer::Vulkan::RenderPass::DebugStageFlags::
kBenchmarkPaths;
}

if (_ui.actionWireframe_Rendering->isChecked())
{
Intrinsic::Renderer::Vulkan::RenderPass::Debug::_activeDebugStageFlags |=
Intrinsic::Renderer::Vulkan::RenderPass::DebugStageFlags::
kWireframeRendering;
}
else
{
Intrinsic::Renderer::Vulkan::RenderPass::Debug::_activeDebugStageFlags &=
~Intrinsic::Renderer::Vulkan::RenderPass::DebugStageFlags::
kWireframeRendering;
}
}

void IntrinsicEd::onCompileShaders()
Expand Down
15 changes: 15 additions & 0 deletions IntrinsicEd/src/IntrinsicEd.ui
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,21 @@
<string>Reload World</string>
</property>
</action>
<action name="actionWireframe_Rendering">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../IntrinsicEd.qrc">
<normaloff>:/Icons/icons/geometry/tetrahedron.png</normaloff>:/Icons/icons/geometry/tetrahedron.png</iconset>
</property>
<property name="text">
<string>Wireframe Rendering</string>
</property>
<property name="toolTip">
<string>Wireframe Rendering</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,9 @@ void Debug::init()
PipelineLayoutManager::resetToDefault(_debugLinePipelineLayout);

GpuProgramManager::reflectPipelineLayout(
8u, {Resources::GpuProgramManager::getResourceByName("debug_line.vert"),
GpuProgramManager::getResourceByName("debug_line.frag")},
8u,
{Resources::GpuProgramManager::getResourceByName("debug_line.vert"),
GpuProgramManager::getResourceByName("debug_line.frag")},
_debugLinePipelineLayout);

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

DrawCallRefArray visibleDrawCalls;
static DrawCallRefArray visibleDrawCalls;
static DrawCallRefArray visibleMeshDrawCalls;
visibleMeshDrawCalls.clear();
visibleDrawCalls.clear();

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

if ((_activeDebugStageFlags & DebugStageFlags::kWireframeRendering) > 0u ||
GameStates::Editing::_currentlySelectedEntity.isValid())
{
RenderProcess::Default::getVisibleDrawCalls(
p_CameraRef, 0u,
MaterialManager::getMaterialPassId(_N(GBufferWireframe)))
.copy(visibleMeshDrawCalls);
// Update per mesh uniform data
Core::Components::MeshManager::updateUniformData(visibleMeshDrawCalls);

if ((_activeDebugStageFlags & DebugStageFlags::kWireframeRendering) > 0u)
{
visibleDrawCalls.insert(visibleDrawCalls.end(),
visibleMeshDrawCalls.begin(),
visibleMeshDrawCalls.end());
}
else
{
for (uint32_t i = 0u; i < visibleMeshDrawCalls.size(); ++i)
{
DrawCallRef dcRef = visibleMeshDrawCalls[i];
Entity::EntityRef dcEntity = Components::MeshManager::_entity(
DrawCallManager::_descMeshComponent(dcRef));

if (dcEntity == GameStates::Editing::_currentlySelectedEntity)
{
visibleDrawCalls.push_back(dcRef);
}
}
}
}

RenderSystem::beginRenderPass(_renderPassRef, _framebufferRef,
VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ struct DebugStageFlags
{
kWorldBoundingSpheres = 0x01u,
kBenchmarkPaths = 0x02u,

kSelectedObject = 0x04u
kSelectedObject = 0x04u,
kWireframeRendering = 0x08u
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,24 @@ void initRasterizationStates()
rs.depthBiasSlopeFactor = 0.0f;
rs.lineWidth = 1.0f;
}

{
VkPipelineRasterizationStateCreateInfo& rs =
RenderStates::rasterizationStates[RasterizationStates::kWireframe];
rs.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
rs.pNext = nullptr;
rs.flags = 0;
rs.polygonMode = VK_POLYGON_MODE_LINE;
rs.cullMode = VK_CULL_MODE_BACK_BIT;
rs.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
rs.depthClampEnable = VK_FALSE;
rs.rasterizerDiscardEnable = VK_FALSE;
rs.depthBiasEnable = VK_TRUE;
rs.depthBiasConstantFactor = -2.0f;
rs.depthBiasClamp = 0.0f;
rs.depthBiasSlopeFactor = 0.0f;
rs.lineWidth = 3.0f;
}
}

void initBlendStates()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum Enum
kDefault,
kInvertedCulling,
kDoubleSided,
kWireframe,

kCount
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,11 @@ void MaterialManager::loadMaterialPassConfig()
PipelineManager::_descRasterizationState(pipelineRef) =
RasterizationStates::kDoubleSided;
}
else if (materialPassDesc["rasterizationState"] == "Wireframe")
{
PipelineManager::_descRasterizationState(pipelineRef) =
RasterizationStates::kWireframe;
}
}

if (materialPassDesc.HasMember("depthStencilState"))
Expand Down
49 changes: 49 additions & 0 deletions app/assets/shaders/wireframe.frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2016 Benjamin Glatzel
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#version 450

#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
#extension GL_GOOGLE_include_directive : enable

#include "lib_math.glsl"
#include "gbuffer.inc.glsl"

// Ubos
PER_MATERIAL_UBO;
PER_INSTANCE_UBO;

// Bindings
BINDINGS_GBUFFER;
layout (binding = 6) uniform sampler2D emissiveTex;

// Output
OUTPUT

void main()
{
GBuffer gbuffer;
{
gbuffer.albedo = vec4(0.0, 0.5, 0.5, 1.0);
gbuffer.normal = normalize(vec3(0.0, 1.0, 0.0));
gbuffer.metalMask = 0.0;
gbuffer.specular = 0.5;
gbuffer.roughness = 1.0;
gbuffer.materialBufferIdx = 0;
gbuffer.emissive = 0.0;
gbuffer.occlusion = 1.0;
}
writeGBuffer(gbuffer, outAlbedo, outNormal, outParameter0);
}
34 changes: 34 additions & 0 deletions app/assets/shaders/wireframe.vert.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2016 Benjamin Glatzel
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#version 450

#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
#extension GL_GOOGLE_include_directive : enable

#include "gbuffer_vertex.inc.glsl"

out gl_PerVertex
{
vec4 gl_Position;
};

PER_INSTANCE_UBO;
INPUT();

void main()
{
gl_Position = uboPerInstance.worldViewProjMatrix * vec4(inPosition.xyz, 1.0);
}
9 changes: 9 additions & 0 deletions app/config/material_pass_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@
"blendStates" : ["Default", "Default", "Default"],
"boundResources" : "GBuffer"
},
{
"name" : "GBufferWireframe",
"baseVertexGpuProgram" : "wireframe.vert",
"baseFragmentGpuProgram" : "wireframe.frag",
"renderPass" : "GBuffer",
"blendStates" : ["Default", "Default", "Default"],
"boundResources" : "GBuffer",
"rasterizationState" : "Wireframe"
},
{
"name" : "Shadow",
"baseVertexGpuProgram" : "shadow.vert",
Expand Down
10 changes: 10 additions & 0 deletions app/managers/gpu_programs/wireframe.frag.gpu_program.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "wireframe.frag",
"properties": {
"name": "wireframe.frag",
"gpuProgramName": "wireframe.frag.glsl",
"entryPoint": "main",
"preprocessorDefines": "",
"gpuProgramType": 1
}
}
10 changes: 10 additions & 0 deletions app/managers/gpu_programs/wireframe.vert.gpu_program.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "wireframe.vert",
"properties": {
"name": "wireframe.vert",
"gpuProgramName": "wireframe.vert.glsl",
"entryPoint": "main",
"preprocessorDefines": "",
"gpuProgramType": 0
}
}
1 change: 1 addition & 0 deletions app/managers/materials/Prop_Atlas_01.material.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "Prop_Atlas_01",
"materialPassMask": [
"GBufferDefault",
"GBufferWireframe",
"Shadow",
"PerPixelPicking"
],
Expand Down
5 changes: 3 additions & 2 deletions app/managers/materials/Tree_Atlas_01.material.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"properties": {
"name": "Tree_Atlas_01",
"materialPassMask": [
"GBufferWireframe",
"GBufferFoliage",
"ShadowFoliage",
"GBufferFoliagePrePass",
"PerPixelPicking"
"PerPixelPicking",
"GBufferFoliagePrePass"
],
"albedoTextureName": "Tree_Atlas_01",
"emissiveTextureName": "white",
Expand Down
1 change: 1 addition & 0 deletions app/managers/materials/barrel.material.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "barrel",
"materialPassMask": [
"GBufferDefault",
"GBufferWireframe",
"Shadow",
"PerPixelPicking"
],
Expand Down
1 change: 1 addition & 0 deletions app/managers/materials/default.material.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "default",
"materialPassMask": [
"GBufferDefault",
"GBufferWireframe",
"Shadow",
"PerPixelPicking"
],
Expand Down
1 change: 1 addition & 0 deletions app/managers/materials/default_effect.material.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"materialPassMask": [
"GBufferEffect",
"GBufferDefault",
"GBufferDefaultWireframe",
"Shadow",
"PerPixelPicking"
],
Expand Down
1 change: 1 addition & 0 deletions app/managers/materials/default_emissive.material.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "default_emissive",
"materialPassMask": [
"GBufferDefault",
"GBufferWireframe",
"Shadow",
"PerPixelPicking"
],
Expand Down
1 change: 1 addition & 0 deletions app/managers/materials/default_large.material.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "default_large",
"materialPassMask": [
"GBufferDefault",
"GBufferWireframe",
"Shadow",
"PerPixelPicking"
],
Expand Down
1 change: 1 addition & 0 deletions app/managers/materials/default_metal.material.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"name": "default_metal",
"materialPassMask": [
"GBufferDefault",
"GBufferWireframe",
"Shadow",
"PerPixelPicking"
],
Expand Down
Loading

0 comments on commit 83d8ff6

Please sign in to comment.