Skip to content

Commit 9fd3805

Browse files
author
Adrien GIVRY
committed
Light 3D icons has been added to the scene view
Some texture has been added to the RawTexture.h file and are now registered has editor resources. These texture are drawn as billboard (Billboard raw shader has been added to the editor). We also render lights as non-textured plane for actor picking using the color matching with the actor ID as the diffuse.
1 parent e3249b8 commit 9fd3805

10 files changed

Lines changed: 207 additions & 8 deletions

File tree

30.3 KB
Binary file not shown.

Sources/Overload/OvEditor/include/OvEditor/Core/EditorRenderer.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ namespace OvEditor::Core
4242
/**
4343
* Prepare the picking material by send it the color corresponding to the given actor
4444
* @param p_actor
45+
* @param p_material
4546
*/
46-
void PreparePickingMaterial(OvCore::ECS::Actor& p_actor);
47+
void PreparePickingMaterial(OvCore::ECS::Actor& p_actor, OvCore::Resources::Material& p_material);
4748

4849
/**
4950
* Calculate the model matrix for a camera attached to the given actor
@@ -73,6 +74,11 @@ namespace OvEditor::Core
7374
*/
7475
void RenderCameras();
7576

77+
/**
78+
* Render every scene lights as billboards
79+
*/
80+
void RenderLights();
81+
7682
/**
7783
* Render a gizmo at position
7884
* @param p_position
@@ -171,6 +177,7 @@ namespace OvEditor::Core
171177
OvCore::Resources::Material m_emptyMaterial;
172178
OvCore::Resources::Material m_defaultMaterial;
173179
OvCore::Resources::Material m_cameraMaterial;
180+
OvCore::Resources::Material m_lightMaterial;
174181
OvCore::Resources::Material m_gizmoArrowMaterial;
175182
OvCore::Resources::Material m_gizmoBallMaterial;
176183
OvCore::Resources::Material m_gizmoPickingMaterial;

Sources/Overload/OvEditor/include/OvEditor/Resources/RawShaders.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,10 @@ namespace OvEditor::Resources
2525
* Returns the gizmo shader
2626
*/
2727
static std::pair<std::string, std::string> GetGizmo();
28+
29+
/**
30+
* Returns the billboard shader
31+
*/
32+
static std::pair<std::string, std::string> GetBillboard();
2833
};
2934
}

Sources/Overload/OvEditor/include/OvEditor/Resources/RawTextures.h

Lines changed: 5 additions & 0 deletions
Large diffs are not rendered by default.

Sources/Overload/OvEditor/include/OvEditor/Settings/EditorSettings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,6 @@ namespace OvEditor::Settings
7777
inline static Property<bool> ShowLightBounds = { false };
7878
inline static Property<bool> ShowGeometryFrustumCullingInSceneView = { false };
7979
inline static Property<bool> ShowLightFrustumCullingInSceneView = { false };
80+
inline static Property<float> LightBillboardScale = { 0.5f };
8081
};
8182
}

Sources/Overload/OvEditor/src/OvEditor/Core/EditorRenderer.cpp

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ void OvEditor::Core::EditorRenderer::InitMaterials()
8888
m_cameraMaterial.Set("u_Diffuse", FVector4(0.0f, 0.3f, 0.7f, 1.0f));
8989
m_cameraMaterial.Set<OvRendering::Resources::Texture*>("u_DiffuseMap", nullptr);
9090

91+
/* Light Material */
92+
m_lightMaterial.SetShader(m_context.editorResources->GetShader("Billboard"));
93+
m_lightMaterial.Set("u_Diffuse", FVector4(1.f, 1.f, 0.5f, 0.5f));
94+
m_lightMaterial.SetBackfaceCulling(false);
95+
m_lightMaterial.SetBlendable(true);
96+
m_lightMaterial.SetDepthTest(false);
97+
9198
/* Stencil Fill Material */
9299
m_stencilFillMaterial.SetShader(m_context.shaderManager[":Shaders\\Unlit.glsl"]);
93100
m_stencilFillMaterial.SetBackfaceCulling(true);
@@ -133,14 +140,14 @@ void OvEditor::Core::EditorRenderer::InitMaterials()
133140
m_actorPickingMaterial.SetBackfaceCulling(false);
134141
}
135142

136-
void OvEditor::Core::EditorRenderer::PreparePickingMaterial(OvCore::ECS::Actor& p_actor)
143+
void OvEditor::Core::EditorRenderer::PreparePickingMaterial(OvCore::ECS::Actor& p_actor, OvCore::Resources::Material& p_material)
137144
{
138145
uint32_t actorID = static_cast<uint32_t>(p_actor.GetID());
139146

140147
auto bytes = reinterpret_cast<uint8_t*>(&actorID);
141148
auto color = FVector4{ bytes[0] / 255.0f, bytes[1] / 255.0f, bytes[2] / 255.0f, 1.0f };
142149

143-
m_actorPickingMaterial.Set("u_Diffuse", color);
150+
p_material.Set("u_Diffuse", color);
144151
}
145152

146153
OvMaths::FMatrix4 OvEditor::Core::EditorRenderer::CalculateCameraModelMatrix(OvCore::ECS::Actor& p_actor)
@@ -178,7 +185,7 @@ void OvEditor::Core::EditorRenderer::RenderSceneForActorPicking()
178185
const OvCore::ECS::Components::CMaterialRenderer::MaterialList& materials = materialRenderer->GetMaterials();
179186
const auto& modelMatrix = actor.transform.GetWorldMatrix();
180187

181-
PreparePickingMaterial(actor);
188+
PreparePickingMaterial(actor, m_actorPickingMaterial);
182189

183190
for (auto mesh : model->GetMeshes())
184191
{
@@ -214,13 +221,36 @@ void OvEditor::Core::EditorRenderer::RenderSceneForActorPicking()
214221

215222
if (actor.IsActive())
216223
{
217-
PreparePickingMaterial(actor);
224+
PreparePickingMaterial(actor, m_actorPickingMaterial);
218225
auto& model = *m_context.editorResources->GetModel("Camera");
219226
auto modelMatrix = CalculateCameraModelMatrix(actor);
220227

221228
m_context.renderer->DrawModelWithSingleMaterial(model, m_actorPickingMaterial, &modelMatrix);
222229
}
223230
}
231+
232+
/* Render lights */
233+
if (Settings::EditorSettings::LightBillboardScale > 0.001f)
234+
{
235+
m_context.renderer->Clear(false, true, false);
236+
237+
m_lightMaterial.SetDepthTest(true);
238+
m_lightMaterial.Set<float>("u_Scale", Settings::EditorSettings::LightBillboardScale * 0.1f);
239+
m_lightMaterial.Set<OvRendering::Resources::Texture*>("u_DiffuseMap", nullptr);
240+
241+
for (auto light : m_context.sceneManager.GetCurrentScene()->GetFastAccessComponents().lights)
242+
{
243+
auto& actor = light->owner;
244+
245+
if (actor.IsActive())
246+
{
247+
PreparePickingMaterial(actor, m_lightMaterial);
248+
auto& model = *m_context.editorResources->GetModel("Vertical_Plane");
249+
auto modelMatrix = FMatrix4::Translation(actor.transform.GetWorldPosition());
250+
m_context.renderer->DrawModelWithSingleMaterial(model, m_lightMaterial, &modelMatrix);
251+
}
252+
}
253+
}
224254
}
225255

226256
void OvEditor::Core::EditorRenderer::RenderUI()
@@ -246,6 +276,41 @@ void OvEditor::Core::EditorRenderer::RenderCameras()
246276
}
247277
}
248278

279+
void OvEditor::Core::EditorRenderer::RenderLights()
280+
{
281+
using namespace OvMaths;
282+
283+
m_lightMaterial.SetDepthTest(false);
284+
m_lightMaterial.Set<float>("u_Scale", Settings::EditorSettings::LightBillboardScale * 0.1f);
285+
286+
for (auto light : m_context.sceneManager.GetCurrentScene()->GetFastAccessComponents().lights)
287+
{
288+
auto& actor = light->owner;
289+
290+
if (actor.IsActive())
291+
{
292+
auto& model = *m_context.editorResources->GetModel("Vertical_Plane");
293+
auto modelMatrix = FMatrix4::Translation(actor.transform.GetWorldPosition());
294+
295+
OvRendering::Resources::Texture* texture = nullptr;
296+
297+
switch (static_cast<OvRendering::Entities::Light::Type>(static_cast<int>(light->GetData().type)))
298+
{
299+
case OvRendering::Entities::Light::Type::POINT: texture = m_context.editorResources->GetTexture("Bill_Point_Light"); break;
300+
case OvRendering::Entities::Light::Type::SPOT: texture = m_context.editorResources->GetTexture("Bill_Spot_Light"); break;
301+
case OvRendering::Entities::Light::Type::DIRECTIONAL: texture = m_context.editorResources->GetTexture("Bill_Directional_Light"); break;
302+
case OvRendering::Entities::Light::Type::AMBIENT_BOX: texture = m_context.editorResources->GetTexture("Bill_Ambient_Box_Light"); break;
303+
case OvRendering::Entities::Light::Type::AMBIENT_SPHERE: texture = m_context.editorResources->GetTexture("Bill_Ambient_Sphere_Light"); break;
304+
}
305+
306+
const auto& lightColor = light->GetColor();
307+
m_lightMaterial.Set<OvRendering::Resources::Texture*>("u_DiffuseMap", texture);
308+
m_lightMaterial.Set<OvMaths::FVector4>("u_Diffuse", OvMaths::FVector4(lightColor.x, lightColor.y, lightColor.z, 0.75f));
309+
m_context.renderer->DrawModelWithSingleMaterial(model, m_lightMaterial, &modelMatrix);
310+
}
311+
}
312+
}
313+
249314
void OvEditor::Core::EditorRenderer::RenderGizmo(const OvMaths::FVector3& p_position, const OvMaths::FQuaternion& p_rotation, OvEditor::Core::EGizmoOperation p_operation, bool p_pickable)
250315
{
251316
using namespace OvMaths;

Sources/Overload/OvEditor/src/OvEditor/Core/EditorResources.cpp

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ OvEditor::Core::EditorResources::EditorResources(const std::string& p_editorAsse
4141
OvRendering::Settings::ETextureFilteringMode firstFilterEditor = OvRendering::Settings::ETextureFilteringMode::LINEAR;
4242
OvRendering::Settings::ETextureFilteringMode secondFilterEditor = OvRendering::Settings::ETextureFilteringMode::LINEAR;
4343

44+
OvRendering::Settings::ETextureFilteringMode firstFilterBillboard = OvRendering::Settings::ETextureFilteringMode::NEAREST;
45+
OvRendering::Settings::ETextureFilteringMode secondFilterBillboard = OvRendering::Settings::ETextureFilteringMode::NEAREST;
46+
4447
/* Buttons */
4548

4649
{
@@ -119,10 +122,36 @@ OvEditor::Core::EditorResources::EditorResources(const std::string& p_editorAsse
119122
m_textures["Icon_Font"] = TextureLoader::CreateFromMemory(reinterpret_cast<uint8_t*>(raw.data()), 16, 16, firstFilterEditor, secondFilterEditor, false);
120123
}
121124

125+
{
126+
std::vector<uint64_t> raw = BILL_PLIGHT;
127+
m_textures["Bill_Point_Light"] = TextureLoader::CreateFromMemory(reinterpret_cast<uint8_t*>(raw.data()), 128, 128, firstFilterBillboard, secondFilterBillboard, false);
128+
}
129+
130+
{
131+
std::vector<uint64_t> raw = BILL_SLIGHT;
132+
m_textures["Bill_Spot_Light"] = TextureLoader::CreateFromMemory(reinterpret_cast<uint8_t*>(raw.data()), 128, 128, firstFilterBillboard, secondFilterBillboard, false);
133+
}
134+
135+
{
136+
std::vector<uint64_t> raw = BILL_DLIGHT;
137+
m_textures["Bill_Directional_Light"] = TextureLoader::CreateFromMemory(reinterpret_cast<uint8_t*>(raw.data()), 128, 128, firstFilterBillboard, secondFilterBillboard, false);
138+
}
139+
140+
{
141+
std::vector<uint64_t> raw = BILL_ABLIGHT;
142+
m_textures["Bill_Ambient_Box_Light"] = TextureLoader::CreateFromMemory(reinterpret_cast<uint8_t*>(raw.data()), 128, 128, firstFilterBillboard, secondFilterBillboard, false);
143+
}
144+
145+
{
146+
std::vector<uint64_t> raw = BILL_ASLIGHT;
147+
m_textures["Bill_Ambient_Sphere_Light"] = TextureLoader::CreateFromMemory(reinterpret_cast<uint8_t*>(raw.data()), 128, 128, firstFilterBillboard, secondFilterBillboard, false);
148+
}
149+
122150
/* Models */
123151
m_models["Cube"] = ModelLoader::Create(modelsFolder + "Cube.fbx", modelParserFlags);
124152
m_models["Cylinder"] = ModelLoader::Create(modelsFolder + "Cylinder.fbx", modelParserFlags);
125153
m_models["Plane"] = ModelLoader::Create(modelsFolder + "Plane.fbx", modelParserFlags);
154+
m_models["Vertical_Plane"] = ModelLoader::Create(modelsFolder + "Vertical_Plane.fbx", modelParserFlags);
126155
m_models["Roll"] = ModelLoader::Create(modelsFolder + "Roll.fbx", modelParserFlags);
127156
m_models["Sphere"] = ModelLoader::Create(modelsFolder + "Sphere.fbx", modelParserFlags);
128157
m_models["Arrow_Translate"] = ModelLoader::Create(modelsFolder + "Arrow_Translate.fbx", modelParserFlags);
@@ -131,10 +160,12 @@ OvEditor::Core::EditorResources::EditorResources(const std::string& p_editorAsse
131160
m_models["Camera"] = ModelLoader::Create(modelsFolder + "Camera.fbx", modelParserFlags);
132161

133162
/* Shaders */
134-
auto gridSource = OvEditor::Resources::RawShaders::GetGrid();
135-
auto gizmoSource = OvEditor::Resources::RawShaders::GetGizmo();
163+
auto gridSource = OvEditor::Resources::RawShaders::GetGrid();
164+
auto gizmoSource = OvEditor::Resources::RawShaders::GetGizmo();
165+
auto billboardSource = OvEditor::Resources::RawShaders::GetBillboard();
136166
m_shaders["Grid"] = ShaderLoader::CreateFromSource(gridSource.first, gridSource.second);
137167
m_shaders["Gizmo"] = ShaderLoader::CreateFromSource(gizmoSource.first, gizmoSource.second);
168+
m_shaders["Billboard"] = ShaderLoader::CreateFromSource(billboardSource.first, billboardSource.second);
138169

139170
/* From memory */
140171
{

Sources/Overload/OvEditor/src/OvEditor/Panels/MenuBar.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <OvUI/Widgets/Visual/Separator.h>
2222
#include <OvUI/Widgets/Sliders/SliderInt.h>
23+
#include <OvUI/Widgets/Sliders/SliderFloat.h>
2324
#include <OvUI/Widgets/Selection/ColorEdit.h>
2425

2526
#include "OvEditor/Panels/MenuBar.h"
@@ -200,6 +201,11 @@ void OvEditor::Panels::MenuBar::CreateSettingsMenu()
200201
assetViewGridPicker.color = OvUI::Types::Color::White;
201202
};
202203

204+
auto& sceneViewBillboardScaleMenu = settingsMenu.CreateWidget<MenuList>("3D Icons Scales");
205+
auto& lightBillboardScaleSlider = sceneViewBillboardScaleMenu.CreateWidget<Sliders::SliderInt>(0, 100, static_cast<int>(Settings::EditorSettings::LightBillboardScale * 100.0f), OvUI::Widgets::Sliders::ESliderOrientation::HORIZONTAL, "Lights");
206+
lightBillboardScaleSlider.ValueChangedEvent += [this](int p_value) { Settings::EditorSettings::LightBillboardScale = p_value / 100.0f; };
207+
lightBillboardScaleSlider.format = "%d %%";
208+
203209
auto& debuggingMenu = settingsMenu.CreateWidget<MenuList>("Debugging");
204210
debuggingMenu.CreateWidget<MenuItem>("Show geometry bounds", "", true, Settings::EditorSettings::ShowGeometryBounds).ValueChangedEvent += [this](bool p_value) { Settings::EditorSettings::ShowGeometryBounds = p_value; };
205211
debuggingMenu.CreateWidget<MenuItem>("Show lights bounds", "", true, Settings::EditorSettings::ShowLightBounds).ValueChangedEvent += [this](bool p_value) { Settings::EditorSettings::ShowLightBounds = p_value; };

Sources/Overload/OvEditor/src/OvEditor/Panels/SceneView.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ void OvEditor::Panels::SceneView::RenderScene(uint8_t p_defaultRenderState)
112112
m_editorRenderer.RenderScene(m_cameraPosition, m_camera);
113113
}
114114

115+
m_editorRenderer.RenderLights();
116+
115117
if (EDITOR_EXEC(IsAnyActorSelected()))
116118
{
117119
auto& selectedActor = EDITOR_EXEC(GetSelectedActor());

Sources/Overload/OvEditor/src/OvEditor/Resources/RawShaders.cpp

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,81 @@ void main()
227227
})";
228228

229229
return source;
230-
}
230+
}
231+
232+
std::pair<std::string, std::string> OvEditor::Resources::RawShaders::GetBillboard()
233+
{
234+
std::pair<std::string, std::string> source;
235+
236+
source.first = R"(
237+
#version 460 core
238+
239+
layout (location = 0) in vec3 geo_Pos;
240+
layout (location = 1) in vec2 geo_TexCoords;
241+
layout (location = 2) in vec3 geo_Normal;
242+
243+
layout (std140) uniform EngineUBO
244+
{
245+
mat4 ubo_Model;
246+
mat4 ubo_View;
247+
mat4 ubo_Projection;
248+
vec3 ubo_ViewPos;
249+
float ubo_Time;
250+
};
251+
252+
out VS_OUT
253+
{
254+
vec2 TexCoords;
255+
} vs_out;
256+
257+
uniform float u_Scale = 1.0f;
258+
259+
void main()
260+
{
261+
vs_out.TexCoords = geo_TexCoords;
262+
263+
mat4 model = ubo_Model;
264+
float distanceToCamera = distance(ubo_ViewPos, model[3].xyz);
265+
266+
mat4 modelView = ubo_View * model;
267+
268+
// Column 0:
269+
modelView[0][0] = 1;
270+
modelView[0][1] = 0;
271+
modelView[0][2] = 0;
272+
273+
// Column 1:
274+
modelView[1][0] = 0;
275+
modelView[1][1] = 1;
276+
modelView[1][2] = 0;
277+
278+
// Column 2:
279+
modelView[2][0] = 0;
280+
modelView[2][1] = 0;
281+
modelView[2][2] = 1;
282+
283+
gl_Position = ubo_Projection * modelView * vec4(geo_Pos * distanceToCamera * u_Scale, 1.0);
284+
})";
285+
286+
source.second = R"(
287+
#version 460 core
288+
289+
out vec4 FRAGMENT_COLOR;
290+
291+
in VS_OUT
292+
{
293+
vec2 TexCoords;
294+
} fs_in;
295+
296+
uniform vec4 u_Diffuse = vec4(1.0, 1.0, 1.0, 1.0);
297+
uniform sampler2D u_DiffuseMap;
298+
uniform vec2 u_TextureTiling = vec2(1.0, 1.0);
299+
uniform vec2 u_TextureOffset = vec2(0.0, 0.0);
300+
301+
void main()
302+
{
303+
FRAGMENT_COLOR = texture(u_DiffuseMap, u_TextureOffset + vec2(mod(fs_in.TexCoords.x * u_TextureTiling.x, 1), mod(fs_in.TexCoords.y * u_TextureTiling.y, 1))) * u_Diffuse;
304+
})";
305+
306+
return source;
307+
}

0 commit comments

Comments
 (0)