Fixed some lighting bug + serialization progress

This commit is contained in:
Antoine Pilote
2021-05-24 19:23:34 -04:00
parent e14a2f18d9
commit 1f1047d23b
33 changed files with 277 additions and 597 deletions

View File

@@ -244,8 +244,7 @@ float ShadowCalculation(vec4 fragPosLightSpace, sampler2D shadowMap, vec3 normal
shadow += currentDepth - bias > pcfDepth ? 1.0 : 0.0;
}
}
shadow /= 9.0;
return shadow;
return shadow /= 9;
}
@@ -300,121 +299,13 @@ vec3 ComputeVolumetric(vec3 FragPos, mat4 LightTransform, vec3 LightColor, sampl
return accumFog;
}
// Reflective shadow maps constants.
const uint N_SAMPLES = 64;
const float R_MAX = 0.001; // Maximum sampling radius.
const float RSM_INTENSITY = 0.7;
/**
* Compute indirect lighting from pixels in the surroundings of current fragment.
* @param uvFrag Current fragment's projected coordinates in light space (texture).
* @param n Normalized normal vector to current fragment in world space coordinates.
* @param x Fragment position in world space coordinates.
*/
vec3 indirectLighting(vec3 n, vec3 x, Light light)
{
vec2 poissonDisk[64];
poissonDisk[0] = vec2(-0.613392, 0.617481);
poissonDisk[1] = vec2(0.170019, -0.040254);
poissonDisk[2] = vec2(-0.299417, 0.791925);
poissonDisk[3] = vec2(0.645680, 0.493210);
poissonDisk[4] = vec2(-0.651784, 0.717887);
poissonDisk[5] = vec2(0.421003, 0.027070);
poissonDisk[6] = vec2(-0.817194, -0.271096);
poissonDisk[7] = vec2(-0.705374, -0.668203);
poissonDisk[8] = vec2(0.977050, -0.108615);
poissonDisk[9] = vec2(0.063326, 0.142369);
poissonDisk[10] = vec2(0.203528, 0.214331);
poissonDisk[11] = vec2(-0.667531, 0.326090);
poissonDisk[12] = vec2(-0.098422, -0.295755);
poissonDisk[13] = vec2(-0.885922, 0.215369);
poissonDisk[14] = vec2(0.566637, 0.605213);
poissonDisk[15] = vec2(0.039766, -0.396100);
poissonDisk[16] = vec2(0.751946, 0.453352);
poissonDisk[17] = vec2(0.078707, -0.715323);
poissonDisk[18] = vec2(-0.075838, -0.529344);
poissonDisk[19] = vec2(0.724479, -0.580798);
poissonDisk[20] = vec2(0.222999, -0.215125);
poissonDisk[21] = vec2(-0.467574, -0.405438);
poissonDisk[22] = vec2(-0.248268, -0.814753);
poissonDisk[23] = vec2(0.354411, -0.887570);
poissonDisk[24] = vec2(0.175817, 0.382366);
poissonDisk[25] = vec2(0.487472, -0.063082);
poissonDisk[26] = vec2(-0.084078, 0.898312);
poissonDisk[27] = vec2(0.488876, -0.783441);
poissonDisk[28] = vec2(0.470016, 0.217933);
poissonDisk[29] = vec2(-0.696890, -0.549791);
poissonDisk[30] = vec2(-0.149693, 0.605762);
poissonDisk[31] = vec2(0.034211, 0.979980);
poissonDisk[32] = vec2(0.503098, -0.308878);
poissonDisk[33] = vec2(-0.016205, -0.872921);
poissonDisk[34] = vec2(0.385784, -0.393902);
poissonDisk[35] = vec2(-0.146886, -0.859249);
poissonDisk[36] = vec2(0.643361, 0.164098);
poissonDisk[37] = vec2(0.634388, -0.049471);
poissonDisk[38] = vec2(-0.688894, 0.007843);
poissonDisk[39] = vec2(0.464034, -0.188818);
poissonDisk[40] = vec2(-0.440840, 0.137486);
poissonDisk[41] = vec2(0.364483, 0.511704);
poissonDisk[42] = vec2(0.034028, 0.325968);
poissonDisk[43] = vec2(0.099094, -0.308023);
poissonDisk[44] = vec2(0.693960, -0.366253);
poissonDisk[45] = vec2(0.678884, -0.204688);
poissonDisk[46] = vec2(0.001801, 0.780328);
poissonDisk[47] = vec2(0.145177, -0.898984);
poissonDisk[48] = vec2(0.062655, -0.611866);
poissonDisk[49] = vec2(0.315226, -0.604297);
poissonDisk[50] = vec2(-0.780145, 0.486251);
poissonDisk[51] = vec2(-0.371868, 0.882138);
poissonDisk[52] = vec2(0.200476, 0.494430);
poissonDisk[53] = vec2(-0.494552, -0.711051);
poissonDisk[54] = vec2(0.612476, 0.705252);
poissonDisk[55] = vec2(-0.578845, -0.768792);
poissonDisk[56] = vec2(-0.772454, -0.090976);
poissonDisk[57] = vec2(0.504440, 0.372295);
poissonDisk[58] = vec2(0.155736, 0.065157);
poissonDisk[59] = vec2(0.391522, 0.849605);
poissonDisk[60] = vec2(-0.620106, -0.328104);
poissonDisk[61] = vec2(0.789239, -0.419965);
poissonDisk[62] = vec2(-0.545396, 0.538133);
poissonDisk[63] = vec2(-0.178564, -0.596057);
vec4 fragPosLightSpace = light.LightTransform * vec4(x, 1.0f);
// perform perspective divide
vec3 projCoords = fragPosLightSpace.xyz / fragPosLightSpace.w;
// transform to [0,1] range
projCoords = projCoords * 0.5 + 0.5;
vec3 rsmShading = vec3(0);
for (int i = 0; i < N_SAMPLES; i++) // Sum contributions of sampling locations.
{
vec2 uv = projCoords.xy + poissonDisk[i] * R_MAX;
vec3 flux = texture(light.RSMFlux, uv).rgb; // Collect components from corresponding RSM textures.
vec3 x_p = texture(light.RSMPos, uv).xyz; // Position (x_p) and normal (n_p) are in world coordinates too.
vec3 n_p = texture(light.RSMNormal, uv).xyz;
float closestDepth = texture(light.ShadowMap, projCoords.xy).r;
float currentDepth = projCoords.z;
vec3 E_p = flux * ((max(0, dot(n_p, x - x_p)) * max(0, dot(n , x_p - x))) / pow(length(x - x_p), 4));
//E_p *= poissonDisk[i].x * poissonDisk[i].x;
rsmShading += E_p;
}
return rsmShading * RSM_INTENSITY; // Modulate result with some intensity value.
}
void main()
{
// Parallax UV offset.
vec3 tangentViewPos = v_TBN * u_EyePosition;
vec3 tangentFragPos = v_TBN * v_FragPos;
vec3 viewDir = normalize(tangentViewPos - tangentFragPos);
vec2 texCoords = ParallaxMapping(v_UVPosition, viewDir);
vec2 texCoords = v_UVPosition;//ParallaxMapping(v_UVPosition, viewDir);
vec2 finalTexCoords = texCoords;
@@ -434,7 +325,8 @@ void main()
if (u_HasAO == 1)
finalAO = texture(m_AO, finalTexCoords).r;
vec3 finalNormal = texture(m_Normal, finalTexCoords).rgb;
vec3 finalNormal = texture(m_Normal, finalTexCoords).rgb;
finalNormal = finalNormal * 2.0 - 1.0;
finalNormal = v_TBN * normalize(finalNormal);
@@ -445,11 +337,12 @@ void main()
F0 = mix(F0, finalAlbedo, finalMetalness);
// reflectance equation
vec3 Lo = vec3(0.0);
vec3 eyeDirection = normalize(u_EyePosition - v_FragPos);
vec3 Fog = vec3(0.0);
vec3 eColor = vec3(0);
float shadow = 0.0f;
vec3 Lo = vec3(0.0);
for (int i = 0; i < LightCount; i++)
{
vec3 L = normalize(Lights[i].Position - v_FragPos);
@@ -458,16 +351,17 @@ void main()
float attenuation = 1.0 / (distance * distance);
if (Lights[i].Type == 0) {
L = Lights[i].Direction;
L = normalize(Lights[i].Direction);
attenuation = 1.0f;
if (Lights[i].Volumetric == 1)
Fog += ComputeVolumetric(v_FragPos, Lights[i].LightTransform, Lights[i].Color, Lights[i].ShadowMap, Lights[i].Direction);
//eColor = indirectLighting(N, v_FragPos, Lights[i]);
shadow += ShadowCalculation(Lights[i].LightTransform * vec4(v_FragPos, 1.0f), Lights[i].ShadowMap, N, Lights[i].Direction);
}
float shadow = ShadowCalculation(Lights[i].LightTransform * vec4(v_FragPos, 1.0f), Lights[i].ShadowMap, N, Lights[i].Direction);
vec3 H = normalize(V + L);
vec3 radiance = Lights[i].Color * attenuation * (1.f - shadow) ;
radiance += eColor;
vec3 radiance = Lights[i].Color * attenuation * (1.0f - shadow);
// Cook-Torrance BRDF
float NDF = DistributionGGX(N, H, finalRoughness);
float G = GeometrySmith(N, V, L, finalRoughness);
@@ -479,23 +373,14 @@ void main()
// kS is equal to Fresnel
vec3 kS = F;
// for energy conservation, the diffuse and specular light can't
// be above 1.0 (unless the surface emits light); to preserve this
// relationship the diffuse component (kD) should equal 1.0 - kS.
vec3 kD = vec3(1.0) - kS;
// multiply kD by the inverse metalness such that only non-metals
// have diffuse lighting, or a linear blend if partly metal (pure metals
// have no diffuse light).
kD *= 1.0 - finalMetalness;
// scale light by NdotL
float NdotL = max(dot(N, L), 0.0);
// add to outgoing radiance Lo
Lo += (kD * finalAlbedo / PI + specular ) * radiance * NdotL ;// note that we already multiplied the BRDF by the Fresnel (kS) so we won't multiply by kS again
Lo += (kD * finalAlbedo / PI + specular ) * radiance * NdotL;// note that we already multiplied the BRDF by the Fresnel (kS) so we won't multiply by kS again
}
/// ambient lighting (we now use IBL as the ambient term)
vec3 F = fresnelSchlickRoughness(max(dot(N, V), 0.0), F0, finalRoughness);
@@ -504,7 +389,7 @@ void main()
kD *= 1.0 - finalMetalness;
vec3 irradiance = mix(texture(u_IrradianceMap, N).rgb, vec3(0.1f), 0.9f);
vec3 diffuse = irradiance * finalAlbedo ;
vec3 diffuse = irradiance * finalAlbedo;
// sample both the pre-filter map and the BRDF lut and combine them together as per the Split-Sum approximation to get the IBL specular part.
const float MAX_REFLECTION_LOD = 4.0;
@@ -512,7 +397,7 @@ void main()
vec2 brdf = texture(brdfLUT, vec2(max(dot(N, V), 0.0), finalRoughness)).rg;
vec3 specular = prefilteredColor * (F * brdf.x + brdf.y);
vec3 ambient = (kD * diffuse + specular) * finalAO;
vec3 ambient = (kD * (diffuse + specular)) * finalAO;
vec3 color = ambient + Lo;
color += Fog;

View File

@@ -1,33 +1,20 @@
#shader vertex
#version 460 core
layout(location = 0) in vec3 Position;
layout(location = 2) in vec3 Normal;
uniform mat4 lightSpaceMatrix;
uniform mat4 model;
out vec4 WorldNormal;
out vec4 Pos;
void main()
{
Pos = model * vec4(Position, 1.0);
WorldNormal = model * vec4(Normal, 1.0);
gl_Position = lightSpaceMatrix * model * vec4(Position, 1.0);
}
#shader fragment
#version 460 core
in vec4 WorldNormal;
in vec4 Pos;
out vec4 Color;
layout(location = 0) out vec4 Flux;
layout(location = 1) out vec4 Normal;
layout(location = 2) out vec4 Position;
void main()
{
Normal = vec4(WorldNormal.x, WorldNormal.y, WorldNormal.z, 1.0);
Flux = vec4(0.0, 1.0, 0.0, 1.0);
Position = Pos;
Position.a = 1.0f;
}

View File

@@ -61,7 +61,7 @@ void EditorInterface::DrawViewport()
ImVec2 regionAvail = ImGui::GetContentRegionAvail();
glm::vec2 viewportPanelSize = glm::vec2(regionAvail.x, regionAvail.y);
Ref<Texture> texture = Engine::GetCurrentWindow()->GetSceneRenderTexture();
Ref<Texture> texture = Engine::GetCurrentWindow()->GetFrameBuffer()->GetTexture();
ImGui::Image((void*)texture->GetID(), regionAvail, ImVec2(0, 1), ImVec2(1, 0));
ImGuizmo::SetDrawlist();
@@ -341,7 +341,10 @@ void EditorInterface::DrawEntityPropreties()
{
//ImGui::InputText("Name:", selectedEntity->m_Name.data(), 12);
TransformComponent& component = m_SelectedEntity.GetComponent<TransformComponent>();
component.DrawEditor();
ImGuiHelper::DrawVec3("Translation", &component.Translation);
ImGuiHelper::DrawVec3("Rotation", &component.Rotation);
ImGuiHelper::DrawVec3("Scale", &component.Scale);
ImGui::Separator();
}
if (m_SelectedEntity.HasComponent<LightComponent>()) {

View File

@@ -3,10 +3,13 @@
#include "src/Vendors/imgui/imgui.h"
#include <src/Vendors/imgui/ImGuizmo.h>
#include "src/Core/FileSystem.h"
class Material;
class EditorInterface
{
private:
Entity m_SelectedEntity;
bool m_IsEntitySelected = false;
bool m_DrawGrid = false;

View File

@@ -8,12 +8,10 @@
#include <imgui/imgui_impl_glfw.h>
#include <imgui/imgui_impl_opengl3.h>
float Engine::m_LastFrameTime = 0.0f;
Ref<Window> Engine::CurrentWindow;
bool Engine::IsPlayMode = false;
Ref<Project> Engine::CurrentProject;
Ref<Window> Engine::CurrentWindow;
float Engine::m_LastFrameTime = 0.0f;
bool Engine::IsPlayMode = false;
void Engine::Init()
{
@@ -22,11 +20,10 @@ void Engine::Init()
PhysicsManager::Get()->Init();
Logger::Log("Physics initialized");
ScriptingEngine::Init();
Logger::Log("Scripting engine initialized");
CurrentWindow = std::make_shared<Window>();
CurrentWindow = Window::Get();
Logger::Log("Window initialized");
Logger::Log("Engine initialized succesfully...");
@@ -34,13 +31,16 @@ void Engine::Init()
void Engine::Tick()
{
// Dont update if no scene is loaded.
if (!CurrentWindow->GetScene())
return;
// Calculate delta time
float time = (float)glfwGetTime();
Timestep timestep = time - m_LastFrameTime;
m_LastFrameTime = time;
// Play mode update vs editor update.
if (Engine::IsPlayMode)
GetCurrentScene()->Update(timestep);
else
@@ -49,40 +49,39 @@ void Engine::Tick()
void Engine::EnterPlayMode()
{
// Dont trigger init if already in player mode.
if (!IsPlayMode)
{
GetCurrentScene()->OnInit();
}
IsPlayMode = true;
}
void Engine::ExitPlayMode()
{
// Dont trigger exit if already not in play mode.
if (IsPlayMode)
GetCurrentScene()->OnExit();
IsPlayMode = false;
}
void Engine::Draw()
{
// Start imgui frame
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
// Draw scene
Window::Get()->Draw();
}
void Engine::EndDraw()
{
// Swap buffer and draw imgui
Window::Get()->EndDraw();
}
void Engine::Run()
{
}
void Engine::Close()
{
ScriptingEngine::Close();
@@ -96,8 +95,7 @@ Ref<Scene> Engine::GetCurrentScene()
bool Engine::LoadScene(Ref<Scene> scene)
{
CurrentWindow->SetScene(scene);
return true;
return CurrentWindow->SetScene(scene);
}
Ref<Project> Engine::GetProject()
@@ -108,16 +106,14 @@ Ref<Project> Engine::GetProject()
bool Engine::LoadProject(Ref<Project> project)
{
CurrentProject = project;
Engine::LoadScene(CurrentProject->DefaultScene);
if (!Engine::LoadScene(CurrentProject->DefaultScene))
return false;
FileSystem::SetRootDirectory(project->FullPath + "/../");
return true;
}
int Engine::HelloWorld()
{
return 1;
}
Ref<Window> Engine::GetCurrentWindow()
{
return CurrentWindow;

View File

@@ -11,25 +11,29 @@ private:
static float m_LastFrameTime;
static Ref<Window> CurrentWindow;
static Ref<Project> CurrentProject;
static Ref<Scene> CurrentScene;
public:
static bool IsPlayMode;
static void Init();
static void Run();
static void Tick();
static bool IsPlayMode; // True if is playing a scene
static void EnterPlayMode();
static void ExitPlayMode();
static void Init(); // Initialize the systems
static void Tick(); // Update every system, called once per frame.
static void Close(); // Close the systems
static void EnterPlayMode(); // Start the game
static void ExitPlayMode(); // Stops the game
static void Draw();
static void EndDraw();
static void Close();
// Custom drawing should happen in between these two
static void Draw(); // Start new frame
static void EndDraw(); // Swap buffer
static int HelloWorld();
static Ref<Window> GetCurrentWindow();
static Ref<Scene> GetCurrentScene();
static bool LoadScene(Ref<Scene> scene);
static Ref<Project> GetProject();
// Load a specific scene
static bool LoadScene(Ref<Scene> scene);
static Ref<Scene> GetCurrentScene();
// Loads a project and the default scene.
static bool LoadProject(Ref<Project> project);
static Ref<Project> GetProject();
};

View File

@@ -5,12 +5,14 @@
class Material;
// TODO: Should probably be static.
class MaterialManager {
private:
static Ref<MaterialManager> s_Instance;
std::map<std::string, Ref<Material>> m_Materials;
// TODO: Pile of crap
Material* ParseMaterialFile(const std::string path);
void SaveMaterialFile(const std::string path, Material* material);
bool IsMaterialLoaded(const std::string path);
@@ -30,6 +32,7 @@ public:
{
if (!s_Instance)
s_Instance = CreateRef<MaterialManager>();
return s_Instance;
}
};

View File

@@ -4,6 +4,7 @@
#include "../Core/Core.h"
class Texture;
// Todo: SHOULD probably be static too.
class TextureManager
{
private:

View File

@@ -1,6 +1,9 @@
#pragma once
class Timestep {
private:
float m_Time;
public:
Timestep(float time = 0.0f) : m_Time(time) { }
operator float() const { return m_Time; }
@@ -8,7 +11,4 @@ public:
float GetSeconds() const { return m_Time; }
float GetMilliseconds() const { return m_Time * 1000.0f; }
private:
float m_Time;
};

View File

@@ -48,6 +48,7 @@ glm::vec3 Camera::GetDirection() {
glm::mat4 Camera::GetPerspective()
{
//TODO: Add perspective options
m_Perspective = glm::perspectiveFov(glm::radians(Fov), 9.0f * AspectRatio, 9.0f, 0.1f, 2000.0f);
//m_Perspective = glm::ortho(-8.0f, 8.0f, -4.5f, 4.5f, -1.0f, 1.0f);
return m_Perspective;

View File

@@ -1,61 +1,52 @@
#pragma once
#include "../Core/Timestep.h"
#include <glm\vec3.hpp>
#include <glm\ext\matrix_float4x4.hpp>
#include "../Core/Maths.h"
#include "../Resource/Serializable.h"
enum CAMERA_TYPE {
ORTHO,
PERSPECTIVE
};
class EditorCamera;
// TODO: Remove logic from here.
class Camera : public ISerializable
{
private:
CAMERA_TYPE m_Type;
float AspectRatio = 16.0f / 9.0f;
glm::vec3 Rotation = { 0.0f, 0.0f, 0.0f };
glm::vec3 Scale = { 1.0f, 1.0f, 1.0f };
glm::mat4 m_Perspective;
bool controlled = true;
bool firstMouse = true;
float Yaw = 0;
float Pitch = 0;
float mouseLastX = 0;
float mouseLastY = 0;
Vector3 Rotation = { 0.0f, 0.0f, 0.0f };
Vector3 Scale = { 1.0f, 1.0f, 1.0f };
Matrix4 m_Perspective;
public:
glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f);
glm::vec3 cameraFront = glm::vec3(0.0f, 0.0f, 1.0f);
// TODO: remove duplicate direction and have a proper api.
Vector3 up = Vector3(0.0f, 1.0f, 0.0f);
Vector3 cameraFront = Vector3(0.0f, 0.0f, 1.0f);
glm::vec3 cameraTarget; // = glm::vec3(0.0f, 0.0f, 0.0f);
glm::vec3 cameraDirection; // = glm::normalize(Translation - cameraTarget);
Vector3 cameraTarget;
Vector3 cameraDirection;
glm::vec3 Translation = { 0.0f, 0.0f, 0.0f };
glm::vec3 cameraRight; // = glm::normalize(glm::cross(up, cameraDirection));
glm::vec3 cameraUp; // = glm::cross(cameraDirection, cameraRight);
Vector3 Translation = { 0.0f, 0.0f, 0.0f };
Vector3 cameraRight;
Vector3 cameraUp;
float Fov = 88.0f;
float Exposure = 1.0f;
float Speed = 1.0f;
Camera();
Camera(CAMERA_TYPE type, glm::vec3 position);
Camera(CAMERA_TYPE type, Vector3 position);
void SetType(CAMERA_TYPE type);
void OnWindowResize(int x, int y);
glm::vec3 GetTranslation();
glm::vec3 GetDirection();
glm::mat4 GetPerspective();
glm::mat4 GetTransform();
glm::mat4 GetTransformRotation();
Vector3 GetTranslation();
Vector3 GetDirection();
Matrix4 GetPerspective();
Matrix4 GetTransform();
Matrix4 GetTransformRotation();
json Serialize() override;
bool Deserialize(const std::string& str) override;

View File

@@ -1,6 +1,6 @@
#include "Framebuffer.h"
#include <GL\glew.h>
FrameBuffer::FrameBuffer(bool hasRenderBuffer, glm::vec2 size, GLenum textureAttachment)
FrameBuffer::FrameBuffer(bool hasRenderBuffer, Vector2 size)
{
m_Textures = std::map<int, Ref<Texture>>();
m_Size = size;
@@ -65,7 +65,7 @@ void FrameBuffer::Unbind()
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
void FrameBuffer::UpdateSize(glm::vec2 size)
void FrameBuffer::UpdateSize(Vector2 size)
{
m_Size = size;

View File

@@ -1,5 +1,5 @@
#pragma once
#include "glm/vec2.hpp"
#include "../Core/Maths.h"
#include "Textures/Texture.h"
#include <vector>
#include "../Core/Core.h"
@@ -7,28 +7,28 @@
class FrameBuffer
{
private:
unsigned int m_FramebufferID;
unsigned int m_RenderBuffer;
glm::vec2 m_Size;
Vector2 m_Size;
std::map<int, Ref<Texture>> m_Textures;
Ref<Texture> m_Texture;
public:
FrameBuffer(bool hasRenderBuffer, glm::vec2 size, GLenum textureAttachment);
FrameBuffer(bool hasRenderBuffer, Vector2 size);
~FrameBuffer() { }
// 0x8CE0 = color attachment 0.
// TODO: Remove blackbox crap
Ref<Texture> GetTexture(GLenum attachment = 0x8CE0) { return m_Textures[(int)attachment]; }
void SetTexture(Ref<Texture> texture, GLenum attachment = 0x8CE0);
void Bind();
void Unbind();
glm::vec2 GetSize() const { return m_Size; }
void UpdateSize(glm::vec2 size);
Vector2 GetSize() const { return m_Size; }
void UpdateSize(Vector2 size);
void SetDrawBuffer(GLenum draw);
void SetReadBuffer(GLenum read);

View File

@@ -3,16 +3,18 @@
#include "Shaders/Shader.h"
#include "Camera.h"
#include <GL/glew.h>
// TODO: move this to primitive
ProceduralSky::ProceduralSky() {
float quadVertices[] = {
// positions // texture Coords
-1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
-1.0f, -1.0f, 0.0f, 0.0f, 0.0f,
1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
-1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
1.0f, -1.0f, 0.0f, 1.0f, 0.0f,
-1.0f, -1.0f, 0.0f, 0.0f, 0.0f,
-1.0f, -1.0f, 0.0f, 0.0f, 0.0f,
1.0f, 1.0f, 0.0f, 1.0f, 1.0f
};
// setup plane VAO
glGenVertexArrays(1, &VAO);
@@ -27,6 +29,7 @@ ProceduralSky::ProceduralSky() {
}
void ProceduralSky::Draw(Ref<Camera> cam) {
glm::vec3 CameraDirection = cam->GetDirection();
Renderer::m_ProceduralSkyShader->Bind();

View File

@@ -41,6 +41,7 @@ unsigned int SphereVBO;
glm::vec3 SphereVertices[360 * 6 + 6];
void Renderer::Init()
{
// TODO: Make shader storage somewhere.
m_ShadowmapShader = new Shader("resources/Shaders/shadowMap.shader");
m_SkyboxShader = new Shader("resources/Shaders/skybox.shader");
m_BRDShader = new Shader("resources/Shaders/BRD.shader");
@@ -51,7 +52,7 @@ void Renderer::Init()
m_Shader = new Shader("resources/Shaders/basic.shader");
m_Shader->Bind();
// TODO: Use buffer abstraction.
// Setup buffers
glGenVertexArrays(1, &CubeVAO);
glBindVertexArray(CubeVAO);
@@ -64,8 +65,8 @@ void Renderer::Init()
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 3, (void*)0);
glEnableVertexAttribArray(0);
// WTF is this.
float r = 1.0f;
int index = 0;
for (int i = 0; i <= 360; i++) {
@@ -96,6 +97,7 @@ void Renderer::Init()
glEnableVertexAttribArray(0);
}
// TODO: Move to shader storage
Shader* Renderer::m_ShadowmapShader;
void Renderer::BeginDraw(Ref<Camera> camera)
@@ -105,7 +107,6 @@ void Renderer::BeginDraw(Ref<Camera> camera)
m_Shader->SetUniformMat4f("u_Projection", camera->GetPerspective());
m_Shader->SetUniformMat4f("u_View", camera->GetTransform());
m_Shader->SetUniform3f("u_EyePosition", camera->GetTranslation().x, camera->GetTranslation().y, camera->GetTranslation().z);
m_Shader->Bind();
}
@@ -115,7 +116,6 @@ void Renderer::EndDraw()
}
// List of all lights queued to be used for rendering this frame.
std::vector<Light> Renderer::m_Lights;
@@ -130,16 +130,10 @@ void Renderer::RegisterLight(TransformComponent transform, LightComponent light,
glm::vec3 pos = transform.Translation;
glm::mat4 lightView = glm::lookAt(pos, pos - direction, glm::vec3(0.0f, 1.0f, 0.0f));
light.m_Framebuffer->GetTexture(GL_DEPTH_ATTACHMENT)->Bind(11);
light.m_Framebuffer->GetTexture(GL_COLOR_ATTACHMENT0)->Bind(12);
light.m_Framebuffer->GetTexture(GL_COLOR_ATTACHMENT1)->Bind(13);
light.m_Framebuffer->GetTexture(GL_COLOR_ATTACHMENT2)->Bind(20);
light.m_Framebuffer->GetTexture(GL_DEPTH_ATTACHMENT)->Bind(17);
m_Shader->SetUniform1i ("LightCount", idx);
m_Shader->SetUniform1i ("Lights[" + std::to_string(idx - 1) + "].Type" , light.Type);
m_Shader->SetUniform1i ("Lights[" + std::to_string(idx - 1) + "].ShadowMap" , 11);
//m_Shader->SetUniform1i("Lights[" + std::to_string(idx - 1) + "].RSMFlux", 12);
//m_Shader->SetUniform1i("Lights[" + std::to_string(idx - 1) + "].RSMNormal", 13);
//m_Shader->SetUniform1i("Lights[" + std::to_string(idx - 1) + "].RSMPos", 20);
m_Shader->SetUniform1i ("Lights[" + std::to_string(idx - 1) + "].ShadowMap" , 17);
m_Shader->SetUniformMat4f("Lights[" + std::to_string(idx - 1) + "].LightTransform", light.GetProjection() * lightView);
m_Shader->SetUniform3f ("Lights[" + std::to_string(idx - 1) + "].Position" , transform.Translation.x, transform.Translation.y, transform.Translation.z);
m_Shader->SetUniform3f ("Lights[" + std::to_string(idx - 1) + "].Direction" , direction.x, direction.y, direction.z);
@@ -172,12 +166,9 @@ void Renderer::RegisterDeferredLight(TransformComponent transform, LightComponen
void Renderer::DrawDebugLine(glm::vec3 start, glm::vec3 end, glm::vec4 color) {
//m_DebugShader->Bind();
//m_DebugShader->SetUniform4f("u_Color", color.r, color.g, color.b, color.a);
}
// TODO: Maybe have a debug primitive draw list
void Renderer::DrawCube(TransformComponent transform, glm::vec4 color)
{
//glDisable(GL_DEPTH_TEST);
@@ -204,7 +195,7 @@ void Renderer::DrawCube(TransformComponent transform, glm::vec4 color)
}
// TODO: See above
void Renderer::DrawSphere(TransformComponent transform, glm::vec4 color)
{
//glDisable(GL_DEPTH_TEST);
@@ -228,5 +219,4 @@ void Renderer::DrawSphere(TransformComponent transform, glm::vec4 color)
glPolygonMode(GL_FRONT, GL_FILL);
glPolygonMode(GL_BACK, GL_FILL);
//glEnable(GL_DEPTH_TEST);
}

View File

@@ -33,15 +33,15 @@ Material::Material(const std::string albedo)
m_Name = albedo;
if (m_DefaultAO == nullptr)
m_DefaultAO = TextureManager::Get()->GetTexture("Res/Textures/default/Default.png");
m_DefaultAO = TextureManager::Get()->GetTexture("resources/Textures/default/Default.png");
if (m_DefaultNormal == nullptr)
m_DefaultNormal = TextureManager::Get()->GetTexture("Res/Textures/default/defaultNormal.png");
m_DefaultNormal = TextureManager::Get()->GetTexture("resources/Textures/default/defaultNormal.png");
if (m_DefaultDisplacement == nullptr)
m_DefaultDisplacement = TextureManager::Get()->GetTexture("Res/Textures/default/Default.png");
m_DefaultDisplacement = TextureManager::Get()->GetTexture("resources/Textures/default/Default.png");
if (m_DefaultRoughness == nullptr)
m_DefaultRoughness = TextureManager::Get()->GetTexture("Res/Textures/default/DefaultMetal.png");
m_DefaultRoughness = TextureManager::Get()->GetTexture("resources/Textures/default/Default.png");
if (m_DefaultMetalness == nullptr)
m_DefaultMetalness = TextureManager::Get()->GetTexture("Res/Textures/default/defaultNormal.png");
m_DefaultMetalness = TextureManager::Get()->GetTexture("resources/Textures/default/Default.png");
}
@@ -55,18 +55,18 @@ Material::Material(const glm::vec3 albedoColor)
m_AlbedoColor = albedoColor;
m_Name = "New material";
if (m_DefaultAlbedo == nullptr)
m_DefaultAlbedo = TextureManager::Get()->GetTexture("Res/Textures/default/Default.png");
m_DefaultAlbedo = TextureManager::Get()->GetTexture("resources/Textures/default/Default.png");
m_Albedo = m_DefaultAlbedo;
if (m_DefaultAO == nullptr)
m_DefaultAO = TextureManager::Get()->GetTexture("Res/Textures/default/Default.png");
m_DefaultAO = TextureManager::Get()->GetTexture("resources/Textures/default/Default.png");
if (m_DefaultNormal == nullptr)
m_DefaultNormal = TextureManager::Get()->GetTexture("Res/Textures/default/defaultNormal.png");
m_DefaultNormal = TextureManager::Get()->GetTexture("resources/Textures/default/defaultNormal.png");
if (m_DefaultDisplacement == nullptr)
m_DefaultDisplacement = TextureManager::Get()->GetTexture("Res/Textures/default/Default.png");
m_DefaultDisplacement = TextureManager::Get()->GetTexture("resources/Textures/default/Default.png");
if (m_DefaultRoughness == nullptr)
m_DefaultRoughness = TextureManager::Get()->GetTexture("Res/Textures/default/Default.png");
m_DefaultRoughness = TextureManager::Get()->GetTexture("resources/Textures/default/Default.png");
if (m_DefaultMetalness == nullptr)
m_DefaultMetalness = TextureManager::Get()->GetTexture("Res/Textures/default/Default.png");
m_DefaultMetalness = TextureManager::Get()->GetTexture("resources/Textures/default/Default.png");
}
Material::~Material()
@@ -120,13 +120,12 @@ void Material::Bind()
else
m_DefaultNormal->Bind(8);
Renderer::m_Shader->SetUniform1i("m_Normal", 8);
Renderer::m_GBufferShader->SetUniform1i("m_Normal", 8);
// Displacement
if (m_Displacement != nullptr)
m_Displacement->Bind(9);
else
m_DefaultDisplacement->Bind(9);
Renderer::m_Shader->SetUniform1i("m_Displacement", 9);
//Renderer::m_Shader->SetUniform1i("m_Displacement", 9);
//Renderer::m_Shader->SetUniform1i("m_Displacement", 9);
}

View File

@@ -21,10 +21,12 @@ void EditorCamera::Update(Timestep ts)
else
Input::HideMouse();
// Should probably not have speed binding in here.
if (Input::IsKeyPress(GLFW_KEY_UP))
Speed += 0.1f;
else if (Input::IsKeyPress(GLFW_KEY_DOWN))
Speed -= 0.1f;
if (Speed < 0)
Speed = 0;
@@ -38,7 +40,6 @@ void EditorCamera::Update(Timestep ts)
Translation.x += Speed * ts;
if (Input::IsKeyPressed(GLFW_KEY_LEFT))
Translation.x -= Speed * ts;
if (Input::IsKeyPressed(GLFW_KEY_UP))
Translation.y += Speed * ts;
if (Input::IsKeyPressed(GLFW_KEY_DOWN))
@@ -61,15 +62,9 @@ void EditorCamera::Update(Timestep ts)
if (Input::IsKeyPressed(GLFW_KEY_SPACE))
movement += up * (Speed * ts);
Translation += glm::vec3(movement.x, 0, 0);
Translation += glm::vec3(0, movement.y, 0);
Translation += glm::vec3(0, 0, movement.z);
Translation += Vector3(movement);
}
if (firstMouse)
{
mouseLastX = x;

View File

@@ -1,8 +1,18 @@
#pragma once
#include "../Core/Timestep.h"
#include "../Rendering/Camera.h"
class EditorCamera : public Camera
{
private:
bool controlled = false;
bool firstMouse = false;
float mouseLastX;
float mouseLastY;
float Yaw = 0.f;
float Pitch = 0.f;
public:
void Update(Timestep ts);
};

View File

@@ -19,6 +19,6 @@
#include "Entity.h"
// TODO: include components here.

View File

@@ -1,6 +1,7 @@
#pragma once
#include "CameraComponent.h"
#include "../ImGuiHelper.h"
#include <src/Rendering/Camera.h>
CameraComponent::CameraComponent()
{

View File

@@ -2,6 +2,8 @@
#include "TransformComponent.h"
#include "../Core/Core.h"
#include "../Resource/Serializable.h"
#include "../Rendering/Camera.h"
class CameraComponent {
public:
Ref<Camera> CameraInstance;

View File

@@ -12,19 +12,8 @@ LightComponent::LightComponent()
Direction = glm::vec3(0, -1, 0);
// Framebuffer used for shadow mapping.
m_Framebuffer = CreateRef<FrameBuffer>(false, glm::vec2(4096, 4096), GL_COLOR_ATTACHMENT0);
m_Framebuffer = CreateRef<FrameBuffer>(false, glm::vec2(4096, 4096));
m_Framebuffer->SetTexture(CreateRef<Texture>(glm::vec2(4096, 4096), GL_DEPTH_COMPONENT), GL_DEPTH_ATTACHMENT);
// This is the Reflective shadow maps extension.
// No need for position here because we retreive position from depth in shading pass.
// Normal
m_Framebuffer->SetTexture(CreateRef<Texture>(glm::vec2(4096, 4096), GL_RGB), GL_COLOR_ATTACHMENT0);
// Flux
m_Framebuffer->SetTexture(CreateRef<Texture>(glm::vec2(4096, 4096), GL_RGB), GL_COLOR_ATTACHMENT1);
// positon
m_Framebuffer->SetTexture(CreateRef<Texture>(glm::vec2(4096, 4096), GL_RGB), GL_COLOR_ATTACHMENT2);
}
glm::mat4 LightComponent::GetProjection()
@@ -76,8 +65,6 @@ void LightComponent::DrawShadow()
void LightComponent::Draw(TransformComponent transformComponent, Ref<Camera> cam)
{
Renderer::RegisterLight(transformComponent, *this, cam);
}
void LightComponent::DrawDeferred(TransformComponent transformComponent, Camera* cam)
@@ -111,6 +98,7 @@ void LightComponent::DrawEditor() {
if (Type == Directional) {
ImGui::Checkbox("Sync with sky", &SyncDirectionWithSky);
ImGui::Checkbox("Volumetric?", &IsVolumetric);
ImGuiHelper::DrawVec3("Direction", &Direction);
}
//if (Type == 1) {
@@ -118,6 +106,6 @@ void LightComponent::DrawEditor() {
// ImGui::SliderFloat("Linear attenuation", &LinearAttenuation, 0.0f, 1.0f);
// ImGui::SliderFloat("Quadratic attenuation", &QuadraticAttenuation, 0.0f, 1.0f);
//}
ImGuiHelper::DrawVec3("Direction", &Direction);
//Direction = glm::normalize(Direction);
}

View File

@@ -15,159 +15,6 @@ class LightComponent {
public:
glm::vec2 yes = glm::vec2(2, 2);
glm::vec2 rsmNoise[151] = {
glm::vec2(-0.2105855460826458 ,0.44847103832481405 ),
glm::vec2(- 0.3249367874595762 ,0.45194211733208256 ),
glm::vec2(- 0.2215745524228665 ,0.24943447347438874 ),
glm::vec2(- 0.060082623613624264, 0.28588622282467613 ),
glm::vec2(- 0.10876121836372676 ,0.1516908621362929 ),
glm::vec2(0.029608993270258344 ,0.36225092203424447 ),
glm::vec2(- 0.4416077740215665 ,0.5922474888127149 ),
glm::vec2(0.09844974909210591 ,0.5293232385931546 ),
glm::vec2(- 0.242750816128263 ,0.5652476929932564 ),
glm::vec2(0.1849719239883465 ,0.42269268543818006 ),
glm::vec2(0.3025579097363722 ,0.5054990750455668 ),
glm::vec2(- 0.6198904961790854 ,0.4923955674020746 ),
glm::vec2(0.1371459445570682 ,0.2256376247802212 ),
glm::vec2(0.07335761833299381 ,0.060664733131448045 ),
glm::vec2(- 0.0981114897551485 ,0.5038558748024538 ),
glm::vec2(0.02105320196048943 ,0.20449635334174143 ),
glm::vec2(- 0.577615989084985 ,0.6751017664470389 ),
glm::vec2(- 0.7047095788535609 ,0.6703810066791474 ),
glm::vec2(- 0.3461478915533044 ,0.2767411968699174 ),
glm::vec2(0.22826800325817365 ,0.6885961509356942 ),
glm::vec2(0.008557608781530446 ,0.6846674257651739 ),
glm::vec2(- 0.7457514972966308 ,0.5525938412112139 ),
glm::vec2(- 0.12675177599317122 ,0.03807380965906315 ),
glm::vec2(0.26001862548878574 ,0.9017228978398559 ),
glm::vec2(- 0.12749254424512912 ,0.6394141870327132 ),
glm::vec2(- 0.25490982834883025 ,- 0.009623207028237046 ),
glm::vec2(- 0.2832188417687387 ,0.7080442976582488 ),
glm::vec2(- 0.5568853398254002 ,0.8281675565698587 ),
glm::vec2(- 0.4502169909230217 ,0.1983838328508294 ),
glm::vec2(- 0.3374755253275854 ,0.12304984569933919 ),
glm::vec2(0.28022304577413726 ,0.19855055835921753 ),
glm::vec2(- 0.21036466694065437 ,0.9159129231359 ),
glm::vec2(0.18360415112566697 ,0.02168652914349556 ),
glm::vec2(- 0.4584645969682012 ,0.3302427234342433 ),
glm::vec2(- 0.4479511888159913 ,0.7410125839426094 ),
glm::vec2(0.3991624033194776 ,0.7988858591043992 ),
glm::vec2(- 0.721662130539607 ,0.39995242005235676 ),
glm::vec2(- 0.3442261159253708 ,0.8599343768096765 ),
glm::vec2(- 0.8466679858222527 ,0.36459222475755637 ),
glm::vec2(- 0.45878496236317035 ,0.47334713275894513 ),
glm::vec2(- 0.4372446791568142 ,- 0.0165798426817938 ),
glm::vec2(0.02100915885650645 ,- 0.06981332644045746 ),
glm::vec2(0.13110358045707327 ,0.8247787987084165 ),
glm::vec2(0.00823456530315858 ,0.8107451419490457 ),
glm::vec2(0.42797771436580456 ,0.5587115156373583 ),
glm::vec2(0.32214857014394704 ,0.33031482110713184 ),
glm::vec2(- 0.22137684848340067 ,0.1136363932619775 ),
glm::vec2(- 0.14193395356177185 ,- 0.08604938105381399 ),
glm::vec2(- 0.5536753158083249 ,- 0.18073175280365916 ),
glm::vec2(- 0.5070399904334678 ,0.08689622459455082 ),
glm::vec2(0.52028114635073 ,0.3812556209224749 ),
glm::vec2(- 0.08344310105240482 ,0.95881586699393 ),
glm::vec2(- 0.5862241280594775 ,0.31599501752459136 ),
glm::vec2(- 0.7424917104785005 ,- 0.14495274618636356 ),
glm::vec2(- 0.71268208479312 ,0.18074542096312163 ),
glm::vec2(0.108990027583584 ,- 0.15666655867133028 ),
glm::vec2(- 0.015166808630370787, - 0.2487589023599489 ),
glm::vec2(0.13234925413927323 ,0.9492511038584823 ),
glm::vec2(- 0.12322536949396168 ,0.7992904731603836 ),
glm::vec2(0.36403836196961614 ,0.6617387426658699 ),
glm::vec2(0.39955450741769316 ,0.41547955572951234 ),
glm::vec2(- 0.5664427084973017 ,0.18679436589332576 ),
glm::vec2(- 0.6944101245020164 ,- 0.01343990502836212 ),
glm::vec2(0.5625324116044776 ,0.5279964765578082 ),
glm::vec2(0.3782464905914933 ,0.12643160642731033 ),
glm::vec2(- 0.8454075321944396 ,0.014131655121489839 ),
glm::vec2(0.4206171451921148 ,0.25475356609725885 ),
glm::vec2(- 0.9192606507897227 ,- 0.1425594778539232 ),
glm::vec2(- 0.9654723633960183 ,0.19512401454226325 ),
glm::vec2(0.3301371414109351 ,- 0.06358517986619083 ),
glm::vec2(- 0.16766134181208847 ,- 0.2189845370715473 ),
glm::vec2(- 0.542947723738074 ,- 0.061891341033254776 ),
glm::vec2(0.3145600952238312 ,- 0.18962449885503818 ),
glm::vec2(- 0.3877834273727072 ,- 0.11963285486335329 ),
glm::vec2(- 0.6912736594144696 ,- 0.2576592094385691 ),
glm::vec2(0.5299377470642048 ,0.6429034882840958 ),
glm::vec2(- 0.9092290171229506 ,- 0.2576042816799101 ),
glm::vec2(- 0.756598574200095 ,- 0.3783062261042447 ),
glm::vec2(- 0.3359282441771242 ,- 0.22535842315392463 ),
glm::vec2(- 0.19113437626591812 ,- 0.37544518075404265 ),
glm::vec2(- 0.8316639544686806 ,0.24888528214021544 ),
glm::vec2(- 0.3842335024447435 ,- 0.3707398001959058 ),
glm::vec2(0.0833362819102259 ,- 0.36313489626173856 ),
glm::vec2(- 0.04703622100738214 ,- 0.36769015058577315 ),
glm::vec2(0.492677762334105 ,0.10573129785820412 ),
glm::vec2(0.5145026631513785 ,0.7862005812142474 ),
glm::vec2(- 0.0805949863665465 ,- 0.5098442295614739 ),
glm::vec2(- 0.36144986019027736 ,- 0.5221245642722397 ),
glm::vec2(- 0.5338520212539983 ,- 0.41540245649168794 ),
glm::vec2(0.08799899906907926 ,- 0.5327065307354413 ),
glm::vec2(0.6051010684289804 ,0.03429146108464676 ),
glm::vec2(- 0.5199138995020798 ,- 0.5290112928940491 ),
glm::vec2(- 0.21573024720399891 ,- 0.5777225511384059 ),
glm::vec2(- 0.48401194020273963 ,- 0.28195487161906563 ),
glm::vec2(- 0.2523937202004908 ,- 0.13494585553274363 ),
glm::vec2(0.6583622019076383 ,0.25357468334574595 ),
glm::vec2(0.7332514662646883 ,0.5471373800529391 ),
glm::vec2(0.1820533681249794 ,- 0.25589649723524566 ),
glm::vec2(0.4224076053791508 ,- 0.29088682980126956 ),
glm::vec2(0.7177903741554872 ,0.07235396433442842 ),
glm::vec2(- 0.4771029660046049 ,- 0.6719876518886342 ),
glm::vec2(0.2534785901118639 ,- 0.40897467057733083 ),
glm::vec2(- 0.27600712311713327 ,- 0.680828645289126 ),
glm::vec2(- 0.6185492815793612 ,- 0.7453116089045722 ),
glm::vec2(- 0.29124157302402065 ,- 0.857368819598208 ),
glm::vec2(0.6478925289192881 ,0.6345225707327742 ),
glm::vec2(0.5606766211201131 ,- 0.16747590407909985 ),
glm::vec2(- 0.6544148295496951 ,- 0.44189162385444347 ),
glm::vec2(0.7660305835364689 ,- 0.1163440033664408 ),
glm::vec2(- 0.984396930296487 ,- 0.00434290617490074 ),
glm::vec2(0.43218518472597256 ,- 0.17091863644713534 ),
glm::vec2(- 0.04413960266224226 ,- 0.703047548286027 ),
glm::vec2(0.5362856037867374 ,- 0.30318221730699 ),
glm::vec2(0.8502947919017667 ,0.1312310157856249 ),
glm::vec2(- 0.6479918401665218 ,- 0.6051526163645965 ),
glm::vec2(0.4240350465627807 ,0.00822566312902584 ),
glm::vec2(0.2230332514623785 ,- 0.5431579662998082 ),
glm::vec2(0.6464790776805429 ,0.37436179966037253 ),
glm::vec2(0.9224902048831116 ,0.041580855014303086 ),
glm::vec2(- 0.4324019065826592 ,- 0.787299608631407 ),
glm::vec2(0.13872153774843388 ,- 0.7113018553685244 ),
glm::vec2(0.8531859057169597 ,0.40581471690902804 ),
glm::vec2(0.5453953127927622 ,0.2093370569631816 ),
glm::vec2(0.9243895369495867 ,0.2642707871055614 ),
glm::vec2(- 0.006129765418066646, - 0.8511686376433512 ),
glm::vec2(0.27384668647208743 ,- 0.7164307699873447 ),
glm::vec2(0.20004837507761009 ,- 0.8351498888499372 ),
glm::vec2(0.7777056608159021 ,0.2404310438231101 ),
glm::vec2(- 0.7484978798285156 ,- 0.5396097698216022 ),
glm::vec2(- 0.8403766405915871 ,- 0.4558144551108865 ),
glm::vec2(0.3522383577039254 ,- 0.4758041359031191 ),
glm::vec2(0.783890871969178 ,- 0.34279882440569154 ),
glm::vec2(- 0.18978613691531687 ,- 0.784090953537453 ),
glm::vec2(- 0.09560238051589443 ,- 0.9250374202209017 ),
glm::vec2(0.048502964663310166 ,- 0.9549042447300811 ),
glm::vec2(0.6456628770495716 ,- 0.33756595771091413 ),
glm::vec2(0.9593865924353975 ,- 0.12327064637742902 ),
glm::vec2(0.6783583896965726 ,- 0.4787960858888588 ),
glm::vec2(0.405881740124189 ,- 0.6279578719333552 ),
glm::vec2(0.8224294731607125 ,- 0.22993697489365883 ),
glm::vec2(0.5268791482035144 ,- 0.05272822133058308 ),
glm::vec2(0.6580553825480155 ,- 0.07591007732029698 ),
glm::vec2(0.5299876015032885 ,- 0.4972122527133582 ),
glm::vec2(0.7208672506325395 ,- 0.5952659848227987 ),
glm::vec2(0.5432340182562456 ,- 0.652824644026825 ),
glm::vec2(0.6747160604935316 ,- 0.19158382758078019 ),
glm::vec2(0.2201129257859169 ,- 0.1252318363959143 ),
glm::vec2(0.7993354103716619 ,- 0.46184850776665365 ),
glm::vec2(0.6856655239366938 ,- 0.7049805434613721 ),
glm::vec2(0.3666048733591001 ,- 0.803469722802703 ),
glm::vec2(0.48271502610609507 ,- 0.8050882593415389 )
};
LightType Type = Point;
glm::vec3 Direction = glm::vec3(0, -1, 0);
@@ -217,6 +64,25 @@ public:
bool Deserialize(std::string str)
{
BEGIN_DESERIALIZE();
if (j.contains("Type"))
Type = (LightType)j["Type"];
if (j.contains("IsVolumetric"))
IsVolumetric = j["IsVolumetric"];
if (j.contains("Strength"))
Strength = j["Strength"];
if (j.contains("SyncDirectionWithSky"))
SyncDirectionWithSky = j["SyncDirectionWithSky"];
if (j.contains("CastShadows"))
SyncDirectionWithSky = j["CastShadows"];
if (j.contains("Direction"))
{
float x = j["Direction"]["x"];
float y = j["Direction"]["y"];
float z = j["Direction"]["z"];
this->Direction = Vector3(x, y, z);
}
return true;
}
};

View File

@@ -5,7 +5,9 @@
#include "../../../Core/MaterialManager.h"
#include <imgui\imgui.h>
// TODO: This is a pile of crap.
// TODO: MOVE TO PRIMITIVE
Vertex vertices[] = {
Vertex{ glm::vec3(-0.5f, -0.5f, -0.5f), glm::vec2(1.0f, 0.0f), glm::vec3(0, 0, -1), glm::vec3(0, 1, 0), glm::vec3(-1, 0, 0), 1.0f },
Vertex{ glm::vec3(0.5f, -0.5f, -0.5f), glm::vec2(1.0f, 1.0f), glm::vec3(0, 0, -1), glm::vec3(0, 1, 0), glm::vec3(-1, 0, 0), 1.0f },

View File

@@ -32,7 +32,7 @@ public:
{
BEGIN_DESERIALIZE();
this->Path = j["Path"];
Build(); // Maybe have some kind of loading bar or something.
return true;
}
};

View File

@@ -1,29 +1,20 @@
#pragma once
#include "TransformComponent.h"
#include <glm\ext\matrix_transform.hpp>
#include "../ImGuiHelper.h"
TransformComponent::TransformComponent() {
Translation = glm::vec3(0, 0, 0);
Rotation = glm::vec3(0, 0, 0);
Scale = glm::vec3(1, 1, 1);
TransformComponent::TransformComponent()
{
Translation = Vector3(0, 0, 0);
Rotation = Vector3(0, 0, 0);
Scale = Vector3(1, 1, 1);
}
glm::mat4 TransformComponent::GetTransform() {
glm::mat4 transform = glm::mat4(1.0f);
glm::mat4 TransformComponent::GetTransform()
{
Matrix4 transform = Matrix4(1.0f);
transform = glm::translate(transform, Translation);
transform = glm::rotate(transform, glm::radians(Rotation.x), glm::vec3(1, 0, 0));
transform = glm::rotate(transform, glm::radians(Rotation.y), glm::vec3(0, 1, 0));
transform = glm::rotate(transform, glm::radians(Rotation.z), glm::vec3(0, 0, 1));
transform = glm::rotate(transform, glm::radians(Rotation.x), Vector3(1, 0, 0));
transform = glm::rotate(transform, glm::radians(Rotation.y), Vector3(0, 1, 0));
transform = glm::rotate(transform, glm::radians(Rotation.z), Vector3(0, 0, 1));
transform = glm::scale(transform, Scale);
return transform;
}
void TransformComponent::DrawEditor()
{
ImGuiHelper::DrawVec3("Translation", &Translation);
ImGuiHelper::DrawVec3("Rotation", &Rotation);
ImGuiHelper::DrawVec3("Scale", &Scale);
ImGui::Separator();
}

View File

@@ -1,18 +1,16 @@
#pragma once
#include <glm\ext\matrix_float4x4.hpp>
#include "BaseComponent.h"
#include "../Core/Maths.h"
#include "../Resource/Serializable.h"
class TransformComponent {
public:
glm::vec3 Translation;
glm::vec3 Rotation;
glm::vec3 Scale;
Vector3 Translation;
Vector3 Rotation; // TODO: Should use quaternions.
Vector3 Scale;
TransformComponent();
glm::mat4 GetTransform();
void DrawEditor();
Matrix4 GetTransform();
json Serialize()
{
@@ -27,10 +25,9 @@ public:
bool Deserialize(std::string str)
{
BEGIN_DESERIALIZE();
this->Translation = glm::vec3(j["Translation"]["x"], j["Translation"]["y"], j["Translation"]["z"]);
this->Rotation = glm::vec3(j["Rotation"]["x"], j["Rotation"]["y"], j["Rotation"]["z"]);
this->Scale = glm::vec3(j["Scale"]["x"], j["Scale"]["y"], j["Scale"]["z"]);
this->Translation = Vector3(j["Translation"]["x"], j["Translation"]["y"], j["Translation"]["z"]);
this->Rotation = Vector3(j["Rotation"]["x"], j["Rotation"]["y"], j["Rotation"]["z"]);
this->Scale = Vector3(j["Scale"]["x"], j["Scale"]["y"], j["Scale"]["z"]);
return true;
}
};

View File

@@ -12,7 +12,6 @@ public:
Entity(const Entity& ent);
Entity();
void AddChild(Entity ent);
int GetHandle() { return (int)m_EntityHandle; }

View File

@@ -3,8 +3,8 @@
#include <glm\ext\vector_float3.hpp>
#include "../Core/Core.h"
#include "../Rendering/ProceduralSky.h"
#include "../Resource/Serializable.h"
class Environment : public ISerializable
{
public:

View File

@@ -532,7 +532,7 @@ Entity Scene::GetEntity(const std::string& name)
}
}
Entity Scene::CreateEmptyEntity(const std::string& name) {
Entity Scene::CreateEmptyEntity() {
Entity entity = { m_Registry.create(), this };
return entity;
}
@@ -639,7 +639,7 @@ bool Scene::Deserialize(const std::string& str)
for (json e : j["Entities"])
{
std::string name = e["NameComponent"]["Name"];
Entity ent = CreateEmptyEntity(name);
Entity ent = CreateEmptyEntity();
ent.Deserialize(e.dump());
}
}

View File

@@ -25,6 +25,7 @@ private:
public:
std::string Path = "";
static Ref<Scene> New();
Scene();
~Scene();
@@ -37,19 +38,23 @@ public:
void Update(Timestep ts);
void EditorUpdate(Timestep ts);
// TODO: Maybe move this to Renderer::DrawScene() ?
void DrawShadows();
void DrawGBuffer();
void DrawDeferred();
void Draw();
void EditorDraw();
std::vector<Entity> GetAllEntities();
glm::vec3 GetGlobalPosition(Entity ent);
Entity GetEntity(const std::string& name);
Entity CreateEmptyEntity(const std::string& name);
Entity CreateEntity(const std::string& name);
void DestroyEntity(Entity entity);
// TODO: This shouldnt be allowed
Entity CreateEmptyEntity();
Entity CreateEntity(const std::string& name);
// TODO: Could be moved to transform component directly.
glm::vec3 GetGlobalPosition(Entity ent);
void DestroyEntity(Entity entity); // TODO: Could return bool
// TODO: Add multiple camera support.
Ref<Camera> GetCurrentCamera();
Ref<Environment> GetEnvironment();

View File

@@ -19,36 +19,39 @@
#include "Resource/FontAwesome5.h"
#include "../Engine.h"
// TODO: Use abstraction for vertex buffers
unsigned int vbo;
unsigned int vao;
// TODO: Move to primitive storage.
float vertices[] = {
1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
1.0f, -1.0f, 0.0f, 1.0f, 0.0f,
-1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
-1.0f, -1.0f, 0.0f, 0.0f, 0.0f,
-1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
1.0f, -1.0f, 0.0f, 1.0f, 0.0f
1.0f, -1.0f, 0.0f, 1.0f, 0.0f,
-1.0f, -1.0f, 0.0f, 0.0f, 0.0f,
-1.0f, 1.0f, 0.0f, 0.0f, 1.0f
};
Ref<Window> Window::s_Instance;
Window::Window()
{
s_Instance = this;
Init();
Renderer::Init();
//m_Scene->Init();
}
Window::~Window()
{
}
Window::~Window() { }
Window* Window::Get()
Ref<Window> Window::Get()
{
if (s_Instance == nullptr)
s_Instance = CreateRef<Window>();
return s_Instance;
}
@@ -64,6 +67,9 @@ GLFWwindow* Window::GetHandle()
bool Window::SetScene(Ref<Scene> scene)
{
if (scene == nullptr)
return false;
m_Scene = scene;
return true;
}
@@ -78,41 +84,44 @@ Ref<FrameBuffer> Window::GetFrameBuffer() const
return m_Framebuffer;
}
unsigned int captureFBO, captureRBO;
Window* Window::s_Instance;
unsigned int texture;
int Window::Init()
{
if (!glfwInit()) {
std::cout << "glfw initialization failed." << std::endl;
return -1;
if (!glfwInit())
{
Logger::Log("glfw initialization failed.");
return -1;
}
int width, height;
// Create window
m_Window = glfwCreateWindow(1280, 720, "Editor - Dev build", NULL, NULL);
m_Window = glfwCreateWindow(m_Width, m_Height, "Editor - Dev build", NULL, NULL);
if (!m_Window) {
std::cout << "Window creation failed." << std::endl;
if (!m_Window)
{
Logger::Log("Window creation failed.");
return -1;
}
glfwMakeContextCurrent(m_Window);
std::cout << glGetString(GL_VERSION) << std::endl;
Logger::Log((char*)glGetString(GL_VERSION));
if (glewInit() != GLEW_OK) {
std::cout << "GLEW initialization failed!";
if (glewInit() != GLEW_OK)
{
Logger::Log("GLEW initialization failed!");
return -1;
}
// TODO: Move this to renderer init. The window shouldnt have to do gl calls.
glfwWindowHint(GLFW_SAMPLES, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// TODO: have clear color in environnement.
glClearColor(0.019f, 0.501f, 1.0f, 1.0f);
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
glEnable(GL_DEPTH_TEST);
glEnable(GL_MULTISAMPLE);
@@ -120,16 +129,11 @@ int Window::Init()
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glEnable(GL_CULL_FACE);
// create viewports
m_DeferredFrambuffer = new FrameBuffer(false, glm::vec2(1920, 1080), GL_COLOR_ATTACHMENT0);
m_DeferredFrambuffer->SetTexture(CreateRef<Texture>(glm::vec2(1920, 1080), GL_RGB));
m_Framebuffer = CreateRef<FrameBuffer>(true, glm::vec2(1920, 1080), GL_COLOR_ATTACHMENT0);
// Create viewports
m_Framebuffer = CreateRef<FrameBuffer>(true, glm::vec2(1920, 1080));
m_Framebuffer->SetTexture(CreateRef<Texture>(glm::vec2(1920, 1080), GL_RGB));
m_GBuffer = new GBuffer(glm::vec2(1920, 1080));
// Temporary quad vbo for deferred.
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
@@ -146,14 +150,13 @@ int Window::Init()
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 5, (void*)(sizeof(float) * 3));
glEnableVertexAttribArray(1);
// TODO: Style should move to editor
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
io.Fonts->AddFontDefault();
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
ImGui::StyleColorsDark();
//io.Fonts->AddFontFromFileTTF("../data/Fonts/Ruda-Bold.ttf", 15.0f, &config);
ImGui::GetStyle().FrameRounding = 4.0f;
ImGui::GetStyle().GrabRounding = 4.0f;
@@ -207,53 +210,43 @@ int Window::Init()
colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f);
colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.35f);
ImGui_ImplGlfw_InitForOpenGL(m_Window, true);
ImGui_ImplOpenGL3_Init("#version 330");
//m_Scene = CreateRef<Scene>();
return 0;
}
void Window::Update(Timestep ts)
{
// TODO: have event here?
}
glm::vec4 m_Color;
float x = 0.0f;
float y = 0.0f;
float z = 0.0f;
bool init = false;
void Window::Draw()
{
// Dont render if no scene is loaded.
if (!m_Scene)
return;
// Dont render if no cam is found.
Ref<Camera> cam = m_Scene->GetCurrentCamera();
if (!cam)
return;
if (!cam) return;
Renderer::BeginDraw(cam);
{
glCullFace(GL_FRONT);
m_Scene->DrawShadows();
glCullFace(GL_BACK);
//glCullFace(GL_FRONT);
//glCullFace(GL_BACK);
m_Scene->DrawShadows();
m_Framebuffer->Bind();
if(Engine::IsPlayMode)
m_Scene->Draw();
else
m_Scene->EditorDraw();
m_Framebuffer->Unbind();
m_Framebuffer->Bind();
{
if (Engine::IsPlayMode)
m_Scene->Draw();
else
m_Scene->EditorDraw();
}
m_Framebuffer->Unbind();
}
Renderer::EndDraw();
}
@@ -265,40 +258,3 @@ void Window::EndDraw()
glfwSwapBuffers(m_Window);
glfwPollEvents();
}
void Window::DrawQuad()
{
//Renderer::m_DeferredShader->Bind();
//m_DeferredFrambuffer->Bind();
//m_Scene->DrawDeferred();
//glActiveTexture(GL_TEXTURE0 + 5);
//glBindTexture(GL_TEXTURE_2D, m_GBuffer->gAlbedo);
//
//glActiveTexture(GL_TEXTURE0 + 6);
//glBindTexture(GL_TEXTURE_2D, m_GBuffer->gNormal);
//
//glActiveTexture(GL_TEXTURE0 + 7);
//glBindTexture(GL_TEXTURE_2D, m_GBuffer->gMaterial);
//
//glActiveTexture(GL_TEXTURE0 + 8);
//glBindTexture(GL_TEXTURE_2D, m_GBuffer->gDepth);
//
//Renderer::m_DeferredShader->SetUniform1i("m_Albedo", 5);
//Renderer::m_DeferredShader->SetUniform1i("m_Depth", 8);
//Renderer::m_DeferredShader->SetUniform1i("m_Normal", 6);
//Renderer::m_DeferredShader->SetUniform1i("m_Material", 7);
//
//glBindVertexArray(vao);
//glDrawArrays(GL_TRIANGLES, 0, 6);
//
//m_DeferredFrambuffer->Unbind();
}
Ref<Texture> Window::GetSceneRenderTexture()
{
return m_Framebuffer->GetTexture();
}

View File

@@ -3,37 +3,39 @@
#include "Rendering/Framebuffer.h"
#include "Scene/Scene.h"
#include "Core/Core.h"
struct GLFWwindow;
class Window
{
private:
static Window* s_Instance;
static Ref<Window> s_Instance;
int m_Width = 1280;
int m_Height = 720;
GLFWwindow* m_Window;
Ref<FrameBuffer> m_Framebuffer;
GBuffer* m_GBuffer;
Ref<Scene> m_Scene;
FrameBuffer* m_DeferredFrambuffer;
int Width, Height;
public:
Window();
~Window();
static Window* Get();
static Ref<Window> Get(); // Get the window instance
GLFWwindow* GetHandle();
int Init();
void Update(Timestep ts);
void Draw();
void EndDraw();
bool ShouldClose();
Ref<Texture> GetSceneRenderTexture();
int Init();
void Update(Timestep ts);
void DrawQuad();
Ref<Scene> GetScene();
bool SetScene(Ref<Scene> scene);
void Draw();
void EndDraw();
Ref<FrameBuffer> GetFrameBuffer() const;
Ref<Texture> GetSceneRenderTexture();
void DrawQuad();
Ref<Scene> GetScene();
bool SetScene(Ref<Scene> scene);
};