Skip to content

Commit 4bc015b

Browse files
author
Adrien GIVRY
committed
Merge branch 'develop'
2 parents aede777 + c32a8c8 commit 4bc015b

File tree

17 files changed

+364
-59
lines changed

17 files changed

+364
-59
lines changed

Diff for: Resources/Editor/Models/Vertical_Plane.fbx

30.3 KB
Binary file not shown.

Diff for: Sources/Overload/OvEditor/include/OvEditor/Core/EditorRenderer.h

+8-1
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;

Diff for: Sources/Overload/OvEditor/include/OvEditor/Core/GizmoBehaviour.h

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ namespace OvEditor::Core
2727
Y,
2828
Z
2929
};
30+
31+
/**
32+
* Returns true if the snapping behaviour is enabled
33+
*/
34+
bool IsSnappedBehaviourEnabled() const;
3035

3136
/**
3237
* Starts the gizmo picking behaviour for the given target in the given direction

Diff for: Sources/Overload/OvEditor/include/OvEditor/Resources/RawShaders.h

+5
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
}

Diff for: Sources/Overload/OvEditor/include/OvEditor/Resources/RawTextures.h

+5
Large diffs are not rendered by default.

Diff for: Sources/Overload/OvEditor/include/OvEditor/Settings/EditorSettings.h

+4
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,9 @@ 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 };
81+
inline static Property<float> TranslationSnapUnit = { 1.0f };
82+
inline static Property<float> RotationSnapUnit = { 15.0f };
83+
inline static Property<float> ScalingSnapUnit = { 1.0f };
8084
};
8185
}

Diff for: Sources/Overload/OvEditor/src/OvEditor/Core/CameraController.cpp

+9-28
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ OvEditor::Core::CameraController::CameraController
3535

3636
float GetActorFocusDist(OvCore::ECS::Actor& p_actor)
3737
{
38-
float distance = 5.0f;
38+
float distance = 4.0f;
3939

4040
if (p_actor.IsActive())
4141
{
@@ -80,33 +80,14 @@ float GetActorFocusDist(OvCore::ECS::Actor& p_actor)
8080

8181
if (auto modelRenderer = p_actor.GetComponent<OvCore::ECS::Components::CModelRenderer>())
8282
{
83-
distance = std::max(distance, 10.0f);
84-
}
85-
86-
if (auto ambientBoxLight = p_actor.GetComponent<OvCore::ECS::Components::CAmbientBoxLight>())
87-
{
88-
distance = std::max(distance, std::max
89-
(
90-
std::max
91-
(
92-
ambientBoxLight->GetSize().x,
93-
ambientBoxLight->GetSize().y
94-
),
95-
ambientBoxLight->GetSize().z
96-
) * 1.5f);
97-
}
98-
99-
if (auto ambientSphereLight = p_actor.GetComponent<OvCore::ECS::Components::CAmbientSphereLight>())
100-
{
101-
distance = std::max(distance, std::max
102-
(
103-
std::max
104-
(
105-
ambientSphereLight->GetRadius(),
106-
ambientSphereLight->GetRadius()
107-
),
108-
ambientSphereLight->GetRadius()
109-
) * 1.5f);
83+
const bool hasCustomBoundingSphere = modelRenderer->GetFrustumBehaviour() == OvCore::ECS::Components::CModelRenderer::EFrustumBehaviour::CULL_CUSTOM;
84+
const bool hasModel = modelRenderer->GetModel();
85+
const auto boundingSphere = hasCustomBoundingSphere ? &modelRenderer->GetCustomBoundingSphere() : hasModel ? &modelRenderer->GetModel()->GetBoundingSphere() : nullptr;
86+
const auto& actorPosition = p_actor.transform.GetWorldPosition();
87+
const auto& actorScale = p_actor.transform.GetWorldScale();
88+
const auto scaleFactor = std::max(std::max(actorScale.x, actorScale.y), actorScale.z);
89+
90+
distance = std::max(distance, boundingSphere ? (boundingSphere->radius + OvMaths::FVector3::Length(boundingSphere->position)) * scaleFactor * 2.0f : 10.0f);
11091
}
11192

11293
for (auto child : p_actor.GetChildren())

Diff for: Sources/Overload/OvEditor/src/OvEditor/Core/EditorRenderer.cpp

+69-4
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;

Diff for: Sources/Overload/OvEditor/src/OvEditor/Core/EditorResources.cpp

+33-2
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
{

Diff for: Sources/Overload/OvEditor/src/OvEditor/Core/GizmoBehaviour.cpp

+35-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@
55
*/
66

77
#include "OvEditor/Core/GizmoBehaviour.h"
8+
#include "OvEditor/Settings/EditorSettings.h"
9+
10+
float SnapValue(float p_value, float p_step)
11+
{
12+
return p_value - std::fmod(p_value, p_step);
13+
}
14+
15+
bool OvEditor::Core::GizmoBehaviour::IsSnappedBehaviourEnabled() const
16+
{
17+
using namespace OvWindowing::Inputs;
18+
19+
const auto& inputManager = EDITOR_CONTEXT(inputManager);
20+
return inputManager->GetKeyState(EKey::KEY_LEFT_CONTROL) == EKeyState::KEY_DOWN || inputManager->GetKeyState(EKey::KEY_RIGHT_CONTROL) == EKeyState::KEY_DOWN;
21+
}
822

923
void OvEditor::Core::GizmoBehaviour::StartPicking(OvCore::ECS::Actor& p_target, const OvMaths::FVector3& p_cameraPosition, EGizmoOperation p_operation, EDirection p_direction)
1024
{
@@ -101,9 +115,14 @@ void OvEditor::Core::GizmoBehaviour::ApplyTranslation(const OvMaths::FMatrix4& p
101115
auto screenDirection = GetScreenDirection(p_viewMatrix, p_projectionMatrix, p_viewSize);
102116

103117
auto totalDisplacement = m_currentMouse - m_originMouse;
104-
auto translationCoefficient = OvMaths::FVector2::Dot(totalDisplacement, screenDirection);
118+
auto translationCoefficient = OvMaths::FVector2::Dot(totalDisplacement, screenDirection) * unitsPerPixel;
119+
120+
if (IsSnappedBehaviourEnabled())
121+
{
122+
translationCoefficient = SnapValue(translationCoefficient, OvEditor::Settings::EditorSettings::TranslationSnapUnit);
123+
}
105124

106-
m_target->transform.SetLocalPosition(originPosition + GetRealDirection() * translationCoefficient * unitsPerPixel);
125+
m_target->transform.SetLocalPosition(originPosition + GetRealDirection() * translationCoefficient);
107126
}
108127

109128
void OvEditor::Core::GizmoBehaviour::ApplyRotation(const OvMaths::FMatrix4& p_viewMatrix, const OvMaths::FMatrix4& p_projectionMatrix, const OvMaths::FVector2& p_viewSize) const
@@ -115,9 +134,14 @@ void OvEditor::Core::GizmoBehaviour::ApplyRotation(const OvMaths::FMatrix4& p_vi
115134
screenDirection = OvMaths::FVector2(-screenDirection.y, screenDirection.x);
116135

117136
auto totalDisplacement = m_currentMouse - m_originMouse;
118-
auto rotationCoefficient = OvMaths::FVector2::Dot(totalDisplacement, screenDirection);
137+
auto rotationCoefficient = OvMaths::FVector2::Dot(totalDisplacement, screenDirection) * unitsPerPixel;
138+
139+
if (IsSnappedBehaviourEnabled())
140+
{
141+
rotationCoefficient = SnapValue(rotationCoefficient, OvEditor::Settings::EditorSettings::RotationSnapUnit);
142+
}
119143

120-
auto rotationToApply = OvMaths::FQuaternion(OvMaths::FVector3(GetFakeDirection() * rotationCoefficient * unitsPerPixel));
144+
auto rotationToApply = OvMaths::FQuaternion(OvMaths::FVector3(GetFakeDirection() * rotationCoefficient));
121145
m_target->transform.SetLocalRotation(originRotation * rotationToApply);
122146
}
123147

@@ -129,9 +153,14 @@ void OvEditor::Core::GizmoBehaviour::ApplyScale(const OvMaths::FMatrix4& p_viewM
129153
auto screenDirection = GetScreenDirection(p_viewMatrix, p_projectionMatrix, p_viewSize);
130154

131155
auto totalDisplacement = m_currentMouse - m_originMouse;
132-
auto scaleCoefficient = OvMaths::FVector2::Dot(totalDisplacement, screenDirection);
156+
auto scaleCoefficient = OvMaths::FVector2::Dot(totalDisplacement, screenDirection) * unitsPerPixel;
157+
158+
if (IsSnappedBehaviourEnabled())
159+
{
160+
scaleCoefficient = SnapValue(scaleCoefficient, OvEditor::Settings::EditorSettings::ScalingSnapUnit);
161+
}
133162

134-
auto newScale = originScale + GetFakeDirection() * scaleCoefficient * unitsPerPixel;
163+
auto newScale = originScale + GetFakeDirection() * scaleCoefficient;
135164

136165
/* Prevent scale from being negative*/
137166
newScale.x = std::max(newScale.x, 0.0001f);

0 commit comments

Comments
 (0)