Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrien GIVRY committed Dec 2, 2019
2 parents aede777 + c32a8c8 commit 4bc015b
Show file tree
Hide file tree
Showing 17 changed files with 364 additions and 59 deletions.
Binary file added Resources/Editor/Models/Vertical_Plane.fbx
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ namespace OvEditor::Core
/**
* Prepare the picking material by send it the color corresponding to the given actor
* @param p_actor
* @param p_material
*/
void PreparePickingMaterial(OvCore::ECS::Actor& p_actor);
void PreparePickingMaterial(OvCore::ECS::Actor& p_actor, OvCore::Resources::Material& p_material);

/**
* Calculate the model matrix for a camera attached to the given actor
Expand Down Expand Up @@ -73,6 +74,11 @@ namespace OvEditor::Core
*/
void RenderCameras();

/**
* Render every scene lights as billboards
*/
void RenderLights();

/**
* Render a gizmo at position
* @param p_position
Expand Down Expand Up @@ -171,6 +177,7 @@ namespace OvEditor::Core
OvCore::Resources::Material m_emptyMaterial;
OvCore::Resources::Material m_defaultMaterial;
OvCore::Resources::Material m_cameraMaterial;
OvCore::Resources::Material m_lightMaterial;
OvCore::Resources::Material m_gizmoArrowMaterial;
OvCore::Resources::Material m_gizmoBallMaterial;
OvCore::Resources::Material m_gizmoPickingMaterial;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ namespace OvEditor::Core
Y,
Z
};

/**
* Returns true if the snapping behaviour is enabled
*/
bool IsSnappedBehaviourEnabled() const;

/**
* Starts the gizmo picking behaviour for the given target in the given direction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,10 @@ namespace OvEditor::Resources
* Returns the gizmo shader
*/
static std::pair<std::string, std::string> GetGizmo();

/**
* Returns the billboard shader
*/
static std::pair<std::string, std::string> GetBillboard();
};
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,9 @@ namespace OvEditor::Settings
inline static Property<bool> ShowLightBounds = { false };
inline static Property<bool> ShowGeometryFrustumCullingInSceneView = { false };
inline static Property<bool> ShowLightFrustumCullingInSceneView = { false };
inline static Property<float> LightBillboardScale = { 0.5f };
inline static Property<float> TranslationSnapUnit = { 1.0f };
inline static Property<float> RotationSnapUnit = { 15.0f };
inline static Property<float> ScalingSnapUnit = { 1.0f };
};
}
37 changes: 9 additions & 28 deletions Sources/Overload/OvEditor/src/OvEditor/Core/CameraController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ OvEditor::Core::CameraController::CameraController

float GetActorFocusDist(OvCore::ECS::Actor& p_actor)
{
float distance = 5.0f;
float distance = 4.0f;

if (p_actor.IsActive())
{
Expand Down Expand Up @@ -80,33 +80,14 @@ float GetActorFocusDist(OvCore::ECS::Actor& p_actor)

if (auto modelRenderer = p_actor.GetComponent<OvCore::ECS::Components::CModelRenderer>())
{
distance = std::max(distance, 10.0f);
}

if (auto ambientBoxLight = p_actor.GetComponent<OvCore::ECS::Components::CAmbientBoxLight>())
{
distance = std::max(distance, std::max
(
std::max
(
ambientBoxLight->GetSize().x,
ambientBoxLight->GetSize().y
),
ambientBoxLight->GetSize().z
) * 1.5f);
}

if (auto ambientSphereLight = p_actor.GetComponent<OvCore::ECS::Components::CAmbientSphereLight>())
{
distance = std::max(distance, std::max
(
std::max
(
ambientSphereLight->GetRadius(),
ambientSphereLight->GetRadius()
),
ambientSphereLight->GetRadius()
) * 1.5f);
const bool hasCustomBoundingSphere = modelRenderer->GetFrustumBehaviour() == OvCore::ECS::Components::CModelRenderer::EFrustumBehaviour::CULL_CUSTOM;
const bool hasModel = modelRenderer->GetModel();
const auto boundingSphere = hasCustomBoundingSphere ? &modelRenderer->GetCustomBoundingSphere() : hasModel ? &modelRenderer->GetModel()->GetBoundingSphere() : nullptr;
const auto& actorPosition = p_actor.transform.GetWorldPosition();
const auto& actorScale = p_actor.transform.GetWorldScale();
const auto scaleFactor = std::max(std::max(actorScale.x, actorScale.y), actorScale.z);

distance = std::max(distance, boundingSphere ? (boundingSphere->radius + OvMaths::FVector3::Length(boundingSphere->position)) * scaleFactor * 2.0f : 10.0f);
}

for (auto child : p_actor.GetChildren())
Expand Down
73 changes: 69 additions & 4 deletions Sources/Overload/OvEditor/src/OvEditor/Core/EditorRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ void OvEditor::Core::EditorRenderer::InitMaterials()
m_cameraMaterial.Set("u_Diffuse", FVector4(0.0f, 0.3f, 0.7f, 1.0f));
m_cameraMaterial.Set<OvRendering::Resources::Texture*>("u_DiffuseMap", nullptr);

/* Light Material */
m_lightMaterial.SetShader(m_context.editorResources->GetShader("Billboard"));
m_lightMaterial.Set("u_Diffuse", FVector4(1.f, 1.f, 0.5f, 0.5f));
m_lightMaterial.SetBackfaceCulling(false);
m_lightMaterial.SetBlendable(true);
m_lightMaterial.SetDepthTest(false);

/* Stencil Fill Material */
m_stencilFillMaterial.SetShader(m_context.shaderManager[":Shaders\\Unlit.glsl"]);
m_stencilFillMaterial.SetBackfaceCulling(true);
Expand Down Expand Up @@ -133,14 +140,14 @@ void OvEditor::Core::EditorRenderer::InitMaterials()
m_actorPickingMaterial.SetBackfaceCulling(false);
}

void OvEditor::Core::EditorRenderer::PreparePickingMaterial(OvCore::ECS::Actor& p_actor)
void OvEditor::Core::EditorRenderer::PreparePickingMaterial(OvCore::ECS::Actor& p_actor, OvCore::Resources::Material& p_material)
{
uint32_t actorID = static_cast<uint32_t>(p_actor.GetID());

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

m_actorPickingMaterial.Set("u_Diffuse", color);
p_material.Set("u_Diffuse", color);
}

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

PreparePickingMaterial(actor);
PreparePickingMaterial(actor, m_actorPickingMaterial);

for (auto mesh : model->GetMeshes())
{
Expand Down Expand Up @@ -214,13 +221,36 @@ void OvEditor::Core::EditorRenderer::RenderSceneForActorPicking()

if (actor.IsActive())
{
PreparePickingMaterial(actor);
PreparePickingMaterial(actor, m_actorPickingMaterial);
auto& model = *m_context.editorResources->GetModel("Camera");
auto modelMatrix = CalculateCameraModelMatrix(actor);

m_context.renderer->DrawModelWithSingleMaterial(model, m_actorPickingMaterial, &modelMatrix);
}
}

/* Render lights */
if (Settings::EditorSettings::LightBillboardScale > 0.001f)
{
m_context.renderer->Clear(false, true, false);

m_lightMaterial.SetDepthTest(true);
m_lightMaterial.Set<float>("u_Scale", Settings::EditorSettings::LightBillboardScale * 0.1f);
m_lightMaterial.Set<OvRendering::Resources::Texture*>("u_DiffuseMap", nullptr);

for (auto light : m_context.sceneManager.GetCurrentScene()->GetFastAccessComponents().lights)
{
auto& actor = light->owner;

if (actor.IsActive())
{
PreparePickingMaterial(actor, m_lightMaterial);
auto& model = *m_context.editorResources->GetModel("Vertical_Plane");
auto modelMatrix = FMatrix4::Translation(actor.transform.GetWorldPosition());
m_context.renderer->DrawModelWithSingleMaterial(model, m_lightMaterial, &modelMatrix);
}
}
}
}

void OvEditor::Core::EditorRenderer::RenderUI()
Expand All @@ -246,6 +276,41 @@ void OvEditor::Core::EditorRenderer::RenderCameras()
}
}

void OvEditor::Core::EditorRenderer::RenderLights()
{
using namespace OvMaths;

m_lightMaterial.SetDepthTest(false);
m_lightMaterial.Set<float>("u_Scale", Settings::EditorSettings::LightBillboardScale * 0.1f);

for (auto light : m_context.sceneManager.GetCurrentScene()->GetFastAccessComponents().lights)
{
auto& actor = light->owner;

if (actor.IsActive())
{
auto& model = *m_context.editorResources->GetModel("Vertical_Plane");
auto modelMatrix = FMatrix4::Translation(actor.transform.GetWorldPosition());

OvRendering::Resources::Texture* texture = nullptr;

switch (static_cast<OvRendering::Entities::Light::Type>(static_cast<int>(light->GetData().type)))
{
case OvRendering::Entities::Light::Type::POINT: texture = m_context.editorResources->GetTexture("Bill_Point_Light"); break;
case OvRendering::Entities::Light::Type::SPOT: texture = m_context.editorResources->GetTexture("Bill_Spot_Light"); break;
case OvRendering::Entities::Light::Type::DIRECTIONAL: texture = m_context.editorResources->GetTexture("Bill_Directional_Light"); break;
case OvRendering::Entities::Light::Type::AMBIENT_BOX: texture = m_context.editorResources->GetTexture("Bill_Ambient_Box_Light"); break;
case OvRendering::Entities::Light::Type::AMBIENT_SPHERE: texture = m_context.editorResources->GetTexture("Bill_Ambient_Sphere_Light"); break;
}

const auto& lightColor = light->GetColor();
m_lightMaterial.Set<OvRendering::Resources::Texture*>("u_DiffuseMap", texture);
m_lightMaterial.Set<OvMaths::FVector4>("u_Diffuse", OvMaths::FVector4(lightColor.x, lightColor.y, lightColor.z, 0.75f));
m_context.renderer->DrawModelWithSingleMaterial(model, m_lightMaterial, &modelMatrix);
}
}
}

void OvEditor::Core::EditorRenderer::RenderGizmo(const OvMaths::FVector3& p_position, const OvMaths::FQuaternion& p_rotation, OvEditor::Core::EGizmoOperation p_operation, bool p_pickable)
{
using namespace OvMaths;
Expand Down
35 changes: 33 additions & 2 deletions Sources/Overload/OvEditor/src/OvEditor/Core/EditorResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ OvEditor::Core::EditorResources::EditorResources(const std::string& p_editorAsse
OvRendering::Settings::ETextureFilteringMode firstFilterEditor = OvRendering::Settings::ETextureFilteringMode::LINEAR;
OvRendering::Settings::ETextureFilteringMode secondFilterEditor = OvRendering::Settings::ETextureFilteringMode::LINEAR;

OvRendering::Settings::ETextureFilteringMode firstFilterBillboard = OvRendering::Settings::ETextureFilteringMode::NEAREST;
OvRendering::Settings::ETextureFilteringMode secondFilterBillboard = OvRendering::Settings::ETextureFilteringMode::NEAREST;

/* Buttons */

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

{
std::vector<uint64_t> raw = BILL_PLIGHT;
m_textures["Bill_Point_Light"] = TextureLoader::CreateFromMemory(reinterpret_cast<uint8_t*>(raw.data()), 128, 128, firstFilterBillboard, secondFilterBillboard, false);
}

{
std::vector<uint64_t> raw = BILL_SLIGHT;
m_textures["Bill_Spot_Light"] = TextureLoader::CreateFromMemory(reinterpret_cast<uint8_t*>(raw.data()), 128, 128, firstFilterBillboard, secondFilterBillboard, false);
}

{
std::vector<uint64_t> raw = BILL_DLIGHT;
m_textures["Bill_Directional_Light"] = TextureLoader::CreateFromMemory(reinterpret_cast<uint8_t*>(raw.data()), 128, 128, firstFilterBillboard, secondFilterBillboard, false);
}

{
std::vector<uint64_t> raw = BILL_ABLIGHT;
m_textures["Bill_Ambient_Box_Light"] = TextureLoader::CreateFromMemory(reinterpret_cast<uint8_t*>(raw.data()), 128, 128, firstFilterBillboard, secondFilterBillboard, false);
}

{
std::vector<uint64_t> raw = BILL_ASLIGHT;
m_textures["Bill_Ambient_Sphere_Light"] = TextureLoader::CreateFromMemory(reinterpret_cast<uint8_t*>(raw.data()), 128, 128, firstFilterBillboard, secondFilterBillboard, false);
}

/* Models */
m_models["Cube"] = ModelLoader::Create(modelsFolder + "Cube.fbx", modelParserFlags);
m_models["Cylinder"] = ModelLoader::Create(modelsFolder + "Cylinder.fbx", modelParserFlags);
m_models["Plane"] = ModelLoader::Create(modelsFolder + "Plane.fbx", modelParserFlags);
m_models["Vertical_Plane"] = ModelLoader::Create(modelsFolder + "Vertical_Plane.fbx", modelParserFlags);
m_models["Roll"] = ModelLoader::Create(modelsFolder + "Roll.fbx", modelParserFlags);
m_models["Sphere"] = ModelLoader::Create(modelsFolder + "Sphere.fbx", modelParserFlags);
m_models["Arrow_Translate"] = ModelLoader::Create(modelsFolder + "Arrow_Translate.fbx", modelParserFlags);
Expand All @@ -131,10 +160,12 @@ OvEditor::Core::EditorResources::EditorResources(const std::string& p_editorAsse
m_models["Camera"] = ModelLoader::Create(modelsFolder + "Camera.fbx", modelParserFlags);

/* Shaders */
auto gridSource = OvEditor::Resources::RawShaders::GetGrid();
auto gizmoSource = OvEditor::Resources::RawShaders::GetGizmo();
auto gridSource = OvEditor::Resources::RawShaders::GetGrid();
auto gizmoSource = OvEditor::Resources::RawShaders::GetGizmo();
auto billboardSource = OvEditor::Resources::RawShaders::GetBillboard();
m_shaders["Grid"] = ShaderLoader::CreateFromSource(gridSource.first, gridSource.second);
m_shaders["Gizmo"] = ShaderLoader::CreateFromSource(gizmoSource.first, gizmoSource.second);
m_shaders["Billboard"] = ShaderLoader::CreateFromSource(billboardSource.first, billboardSource.second);

/* From memory */
{
Expand Down
41 changes: 35 additions & 6 deletions Sources/Overload/OvEditor/src/OvEditor/Core/GizmoBehaviour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@
*/

#include "OvEditor/Core/GizmoBehaviour.h"
#include "OvEditor/Settings/EditorSettings.h"

float SnapValue(float p_value, float p_step)
{
return p_value - std::fmod(p_value, p_step);
}

bool OvEditor::Core::GizmoBehaviour::IsSnappedBehaviourEnabled() const
{
using namespace OvWindowing::Inputs;

const auto& inputManager = EDITOR_CONTEXT(inputManager);
return inputManager->GetKeyState(EKey::KEY_LEFT_CONTROL) == EKeyState::KEY_DOWN || inputManager->GetKeyState(EKey::KEY_RIGHT_CONTROL) == EKeyState::KEY_DOWN;
}

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

auto totalDisplacement = m_currentMouse - m_originMouse;
auto translationCoefficient = OvMaths::FVector2::Dot(totalDisplacement, screenDirection);
auto translationCoefficient = OvMaths::FVector2::Dot(totalDisplacement, screenDirection) * unitsPerPixel;

if (IsSnappedBehaviourEnabled())
{
translationCoefficient = SnapValue(translationCoefficient, OvEditor::Settings::EditorSettings::TranslationSnapUnit);
}

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

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

auto totalDisplacement = m_currentMouse - m_originMouse;
auto rotationCoefficient = OvMaths::FVector2::Dot(totalDisplacement, screenDirection);
auto rotationCoefficient = OvMaths::FVector2::Dot(totalDisplacement, screenDirection) * unitsPerPixel;

if (IsSnappedBehaviourEnabled())
{
rotationCoefficient = SnapValue(rotationCoefficient, OvEditor::Settings::EditorSettings::RotationSnapUnit);
}

auto rotationToApply = OvMaths::FQuaternion(OvMaths::FVector3(GetFakeDirection() * rotationCoefficient * unitsPerPixel));
auto rotationToApply = OvMaths::FQuaternion(OvMaths::FVector3(GetFakeDirection() * rotationCoefficient));
m_target->transform.SetLocalRotation(originRotation * rotationToApply);
}

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

auto totalDisplacement = m_currentMouse - m_originMouse;
auto scaleCoefficient = OvMaths::FVector2::Dot(totalDisplacement, screenDirection);
auto scaleCoefficient = OvMaths::FVector2::Dot(totalDisplacement, screenDirection) * unitsPerPixel;

if (IsSnappedBehaviourEnabled())
{
scaleCoefficient = SnapValue(scaleCoefficient, OvEditor::Settings::EditorSettings::ScalingSnapUnit);
}

auto newScale = originScale + GetFakeDirection() * scaleCoefficient * unitsPerPixel;
auto newScale = originScale + GetFakeDirection() * scaleCoefficient;

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

0 comments on commit 4bc015b

Please sign in to comment.