Added light and camera gizmo.
This commit is contained in:
@@ -3,13 +3,17 @@
|
||||
|
||||
|
||||
layout(location = 0) in vec3 VertexPosition;
|
||||
layout(location = 1) in vec3 Normal;
|
||||
|
||||
uniform mat4 u_Projection;
|
||||
uniform mat4 u_View;
|
||||
uniform mat4 u_Model;
|
||||
|
||||
out vec3 v_Normal;
|
||||
|
||||
void main()
|
||||
{
|
||||
v_Normal = Normal;
|
||||
gl_Position = u_Projection * u_View * u_Model * vec4(VertexPosition, 1.0f);
|
||||
}
|
||||
|
||||
@@ -19,11 +23,23 @@ void main()
|
||||
uniform vec4 u_Color;
|
||||
|
||||
out vec4 FragColor;
|
||||
in vec3 v_Normal;
|
||||
|
||||
void main()
|
||||
{
|
||||
if(mod(gl_FragCoord.x / 4.0 + gl_FragCoord.y / 4.0, 4.0) < 2.0)
|
||||
discard;
|
||||
vec3 scolor = u_Color.rgb;
|
||||
vec3 lightAmbient = vec3(0.5, 0.5, 0.5);
|
||||
vec3 lightDiffuse = vec3(1, 1, 1);
|
||||
vec3 lightDir = normalize(vec3(0.5, 0.5, 0.5));
|
||||
lightDir = normalize(lightDir);
|
||||
// diffuse shading
|
||||
float diff = max(dot(v_Normal, lightDir), 0.0);
|
||||
// specular shading
|
||||
vec3 reflectDir = reflect(-lightDir, v_Normal);
|
||||
// combine results
|
||||
vec3 ambient = lightAmbient * scolor;
|
||||
vec3 diffuse = diff * lightDiffuse;
|
||||
scolor = scolor * diffuse;
|
||||
|
||||
FragColor = u_Color;
|
||||
FragColor = vec4(scolor, 1.0);
|
||||
}
|
||||
@@ -1,5 +1,10 @@
|
||||
#include "GizmoDrawer.h"
|
||||
#include <src/Rendering/Buffers/VertexBuffer.h>
|
||||
#include <src/Scene/Components/CameraComponent.h>
|
||||
#include <src/Resource/ModelLoader.h>
|
||||
#include <src/Rendering/RenderList.h>
|
||||
#include <dependencies/GLEW/include/GL/glew.h>
|
||||
#include <src/Scene/Components/LightComponent.h>
|
||||
|
||||
GizmoDrawer::GizmoDrawer()
|
||||
{
|
||||
@@ -14,10 +19,17 @@ GizmoDrawer::GizmoDrawer()
|
||||
vblayout->Push<float>(4);
|
||||
|
||||
mAxisLineBuffer->AddBuffer(*mAxisLineVertexBuffer, *vblayout);
|
||||
|
||||
// Load gizmos
|
||||
ModelLoader loader;
|
||||
_gizmos = std::map<std::string, Ref<Model>>();
|
||||
_gizmos["cam"] = loader.LoadModel("resources/Models/Camera.gltf");
|
||||
_gizmos["light"] = loader.LoadModel("resources/Models/Light.gltf");
|
||||
}
|
||||
|
||||
void GizmoDrawer::DrawGizmos(Ref<Scene> scene)
|
||||
{
|
||||
using namespace Nuake;
|
||||
RenderCommand::Disable(RendererEnum::DEPTH_TEST);
|
||||
|
||||
// Draw Axis lignes.
|
||||
@@ -30,10 +42,36 @@ void GizmoDrawer::DrawGizmos(Ref<Scene> scene)
|
||||
Nuake::RenderCommand::DrawLines(0, 6);
|
||||
}
|
||||
|
||||
// Draw Cameras Frustum.
|
||||
auto flatShader = ShaderManager::GetShader("resources/Shaders/flat.shader");
|
||||
flatShader->Bind();
|
||||
flatShader->SetUniformMat4f("u_View", scene->m_EditorCamera->GetTransform());
|
||||
flatShader->SetUniformMat4f("u_Projection", scene->m_EditorCamera->GetPerspective());
|
||||
flatShader->SetUniform4f("u_Color", 0.5f, 0.5f, 0.5f, 1.0f);
|
||||
RenderCommand::Disable(RendererEnum::FACE_CULL);
|
||||
RenderCommand::Enable(RendererEnum::DEPTH_TEST);
|
||||
RenderList renderList;
|
||||
auto camView = scene->m_Registry.view<TransformComponent, CameraComponent>();
|
||||
for (auto e : camView)
|
||||
{
|
||||
auto [transform, cam] = scene->m_Registry.get<TransformComponent, CameraComponent>(e);
|
||||
|
||||
renderList.AddToRenderList(_gizmos["cam"]->GetMeshes()[0], transform.GetGlobalTransform());
|
||||
}
|
||||
renderList.Flush(flatShader, true);
|
||||
|
||||
auto lightView = scene->m_Registry.view<TransformComponent, LightComponent>();
|
||||
for (auto e : lightView)
|
||||
{
|
||||
auto [transform, light] = scene->m_Registry.get<TransformComponent, LightComponent>(e);
|
||||
|
||||
flatShader->SetUniformVec4("u_Color", Vector4(light.Color, 1.0f));
|
||||
renderList.AddToRenderList(_gizmos["light"]->GetMeshes()[0], transform.GetGlobalTransform());
|
||||
renderList.Flush(flatShader, true);
|
||||
}
|
||||
|
||||
RenderCommand::Enable(RendererEnum::FACE_CULL);
|
||||
glCullFace(GL_FRONT);
|
||||
renderList.Flush(flatShader, true);
|
||||
|
||||
RenderCommand::Enable(RendererEnum::DEPTH_TEST);
|
||||
}
|
||||
@@ -5,11 +5,15 @@
|
||||
#include <src/Rendering/Shaders/ShaderManager.h>
|
||||
#include <src/Rendering/Vertex.h>
|
||||
#include <src/Scene/Scene.h>
|
||||
#include <src/Resource/Model.h>
|
||||
|
||||
using namespace Nuake;
|
||||
|
||||
class GizmoDrawer
|
||||
{
|
||||
private:
|
||||
std::map<std::string, Ref<Model>> _gizmos;
|
||||
|
||||
const std::vector<LineVertex> vertices
|
||||
{
|
||||
LineVertex {{10000.f, 0.0f, 0.0f}, {1.f, 0.f, 0.f, 1.f}},
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace Nuake
|
||||
this->IsEmbedded = true;
|
||||
|
||||
ModelLoader loader;
|
||||
auto otherModel = loader.LoadModel(j["Path"]);
|
||||
auto otherModel = loader.LoadModel(FileSystem::Root + j["Path"].dump());
|
||||
m_Meshes = otherModel->GetMeshes();
|
||||
|
||||
this->Path = j["Path"];
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace Nuake
|
||||
|
||||
Ref<Model> ModelLoader::LoadModel(const std::string& path)
|
||||
{
|
||||
m_Meshes.clear();
|
||||
Ref<Model> model = CreateRef<Model>(path);
|
||||
|
||||
Assimp::Importer import;
|
||||
@@ -25,7 +26,7 @@ namespace Nuake
|
||||
aiProcess_CalcTangentSpace;
|
||||
|
||||
modelDir = path + "/../";
|
||||
const aiScene* scene = import.ReadFile(FileSystem::Root + path, importFlags);
|
||||
const aiScene* scene = import.ReadFile(path, importFlags);
|
||||
if (!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode)
|
||||
{
|
||||
std::string assimpErrorMsg = std::string(import.GetErrorString());
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Nuake {
|
||||
void ModelComponent::LoadModel()
|
||||
{
|
||||
auto loader = ModelLoader();
|
||||
this->ModelResource = loader.LoadModel(ModelPath);
|
||||
this->ModelResource = loader.LoadModel(FileSystem::Root + "../" + ModelPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,6 @@ namespace Nuake
|
||||
SERIALIZE_OBJECT_REF_LBL("WrenScriptComponent", GetComponent<WrenScriptComponent>());
|
||||
if (HasComponent<CharacterControllerComponent>())
|
||||
SERIALIZE_OBJECT_REF_LBL("CharacterControllerComponent", GetComponent<CharacterControllerComponent>());
|
||||
|
||||
if (HasComponent<BoxColliderComponent>())
|
||||
SERIALIZE_OBJECT_REF_LBL("BoxColliderComponent", GetComponent<BoxColliderComponent>());
|
||||
if (HasComponent<ModelComponent>())
|
||||
@@ -66,7 +65,6 @@ namespace Nuake
|
||||
DESERIALIZE_COMPONENT(ModelComponent);
|
||||
DESERIALIZE_COMPONENT(WrenScriptComponent);
|
||||
DESERIALIZE_COMPONENT(CharacterControllerComponent);
|
||||
//DESERIALIZE_COMPONENT(BSPBrushComponent);
|
||||
DESERIALIZE_COMPONENT(BoxColliderComponent);
|
||||
return true;
|
||||
}
|
||||
@@ -83,7 +81,6 @@ namespace Nuake
|
||||
this->m_Scene = ent.m_Scene;
|
||||
}
|
||||
|
||||
|
||||
Entity::Entity()
|
||||
{
|
||||
this->m_EntityHandle = (entt::entity)-1;
|
||||
|
||||
Reference in New Issue
Block a user