Working lights and deferred rendering
This commit is contained in:
+38
-16
@@ -85,7 +85,7 @@ public:
|
|||||||
{
|
{
|
||||||
auto t_BrickWall = m_World->CreateEntity();
|
auto t_BrickWall = m_World->CreateEntity();
|
||||||
auto transform = m_World->AddComponent<Components::Transform>(t_BrickWall);
|
auto transform = m_World->AddComponent<Components::Transform>(t_BrickWall);
|
||||||
transform->Position = glm::vec3(-2.f, 0.f, -10.f);
|
transform->Position = glm::vec3(0.f, 0.f, -10.f);
|
||||||
auto sprite = m_World->AddComponent<Components::Sprite>(t_BrickWall);
|
auto sprite = m_World->AddComponent<Components::Sprite>(t_BrickWall);
|
||||||
//TODO: Rename SpriteFile to DiffuseTexture or similar.
|
//TODO: Rename SpriteFile to DiffuseTexture or similar.
|
||||||
sprite->SpriteFile = "Textures/Test/Brick_Diffuse.png";
|
sprite->SpriteFile = "Textures/Test/Brick_Diffuse.png";
|
||||||
@@ -93,18 +93,10 @@ public:
|
|||||||
sprite->SpecularTexture = "Textures/Test/Brick_Specular.png";
|
sprite->SpecularTexture = "Textures/Test/Brick_Specular.png";
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
|
||||||
auto t_Light = m_World->CreateEntity();
|
|
||||||
auto transform = m_World->AddComponent<Components::Transform>(t_Light);
|
|
||||||
transform->Position = glm::vec3(-1.f, 0.f, -9.f);
|
|
||||||
auto plight = m_World->AddComponent<Components::PointLight>(t_Light);
|
|
||||||
plight->Radius = 10.f;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
auto ent = m_World->CreateEntity();
|
auto ent = m_World->CreateEntity();
|
||||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
||||||
transform->Position = glm::vec3(0.f, 0.f, -10.f);
|
transform->Position = glm::vec3(0.f, 0.f, -9.5f);
|
||||||
|
|
||||||
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(ent);
|
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(ent);
|
||||||
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
sprite->SpriteFile = "Textures/Core/ErrorTexture.png";
|
||||||
@@ -114,6 +106,9 @@ public:
|
|||||||
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
|
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
|
||||||
physics->Static = false;
|
physics->Static = false;
|
||||||
|
|
||||||
|
auto plight = m_World->AddComponent<Components::PointLight>(ent);
|
||||||
|
plight->Radius = 2.f;
|
||||||
|
|
||||||
m_World->CommitEntity(ent);
|
m_World->CommitEntity(ent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +116,7 @@ public:
|
|||||||
{
|
{
|
||||||
auto ent = m_World->CreateEntity();
|
auto ent = m_World->CreateEntity();
|
||||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
||||||
transform->Position = glm::vec3(0.f, -3.f, -9.f);
|
transform->Position = glm::vec3(0.f, -3.f, -10.f);
|
||||||
transform->Scale = glm::vec3(2.f, 0.5f, 1.f);
|
transform->Scale = glm::vec3(2.f, 0.5f, 1.f);
|
||||||
//transform->Orientation = glm::rotate(transform->Orientation, glm::radians(45.f), glm::vec3(0, 0, -1));
|
//transform->Orientation = glm::rotate(transform->Orientation, glm::radians(45.f), glm::vec3(0, 0, -1));
|
||||||
|
|
||||||
@@ -212,12 +207,34 @@ public:
|
|||||||
|
|
||||||
//TODO: Add LightLoadShit
|
//TODO: Add LightLoadShit
|
||||||
|
|
||||||
|
auto pointLightComponent = m_World->GetComponent<Components::PointLight>(entity);
|
||||||
|
if (pointLightComponent)
|
||||||
|
{
|
||||||
|
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
|
||||||
|
EnqueuePointLight(absoluteTransform.Position,
|
||||||
|
pointLightComponent->Diffuse,
|
||||||
|
pointLightComponent->Specular,
|
||||||
|
pointLightComponent->Radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity);
|
auto spriteComponent = m_World->GetComponent<Components::Sprite>(entity);
|
||||||
if (spriteComponent)
|
if (spriteComponent)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
std::string normal = spriteComponent->NormalTexture;
|
||||||
|
std::string spec = spriteComponent->SpecularTexture;
|
||||||
|
|
||||||
|
if (normal.empty()) {
|
||||||
|
normal = "Textures/Core/NeutralNormalMap.png";
|
||||||
|
}
|
||||||
|
if (spec.empty()) {
|
||||||
|
spec = "Textures/Core/NeutralSpecularMap.png";
|
||||||
|
}
|
||||||
auto texturediff = ResourceManager::Load<Texture>(spriteComponent->SpriteFile);
|
auto texturediff = ResourceManager::Load<Texture>(spriteComponent->SpriteFile);
|
||||||
auto texturenorm = ResourceManager::Load<Texture>(spriteComponent->NormalTexture);
|
auto texturenorm = ResourceManager::Load<Texture>(normal);
|
||||||
auto texturespec = ResourceManager::Load<Texture>(spriteComponent->SpecularTexture);
|
auto texturespec = ResourceManager::Load<Texture>(spec);
|
||||||
|
|
||||||
|
|
||||||
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
|
Components::Transform absoluteTransform = m_TransformSystem->AbsoluteTransform(entity);
|
||||||
glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(absoluteTransform.Orientation).z, glm::vec3(0, 0, -1));
|
glm::quat orientation2D = glm::angleAxis(glm::eulerAngles(absoluteTransform.Orientation).z, glm::vec3(0, 0, -1));
|
||||||
@@ -263,13 +280,18 @@ public:
|
|||||||
job.ModelMatrix = modelMatrix;
|
job.ModelMatrix = modelMatrix;
|
||||||
job.Color = color;
|
job.Color = color;
|
||||||
|
|
||||||
m_RendererQueue.Forward.Add(job);
|
m_RendererQueue.Deferred.Add(job);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EnQueuePointLight(glm::vec3* position)
|
void EnqueuePointLight(glm::vec3 position, glm::vec3 diffuseColor, glm::vec3 specularColor, float radius)
|
||||||
{
|
{
|
||||||
PointLightJob job;
|
PointLightJob job;
|
||||||
job.Position = *position;
|
job.Position = position;
|
||||||
|
job.DiffuseColor = diffuseColor;
|
||||||
|
job.SpecularColor = specularColor;
|
||||||
|
job.Radius = radius;
|
||||||
|
|
||||||
|
m_RendererQueue.Lights.Add(job);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -265,7 +265,7 @@ void dd::Renderer::DrawDeferred(RenderQueue &objects, RenderQueue &lights)
|
|||||||
glClearColor(0, 0, 0, 1);
|
glClearColor(0, 0, 0, 1);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
m_spDeferred3->Bind();
|
m_spDeferred3->Bind();
|
||||||
glUniform3fv(glGetUniformLocation(*m_spDeferred3, "La"), 1, glm::value_ptr(glm::vec3(0.3f)));
|
glUniform3fv(glGetUniformLocation(*m_spDeferred3, "La"), 1, glm::value_ptr(glm::vec3(0.5f)));
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, m_GDiffuse);
|
glBindTexture(GL_TEXTURE_2D, m_GDiffuse);
|
||||||
glActiveTexture(GL_TEXTURE1);
|
glActiveTexture(GL_TEXTURE1);
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ void main()
|
|||||||
|
|
||||||
//frag_Diffuse = DiffuseTexel * (vec4(La, 0.0) * (vec4(LightingTexel.rgb, 0.0) + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0)));
|
//frag_Diffuse = DiffuseTexel * (vec4(La, 0.0) * (vec4(LightingTexel.rgb, 0.0) + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0)));
|
||||||
//frag_Diffuse = DiffuseTexel * (vec4(La, 0.0) + LightingTexel);
|
//frag_Diffuse = DiffuseTexel * (vec4(La, 0.0) + LightingTexel);
|
||||||
frag_Diffuse = DiffuseTexel;
|
frag_Diffuse = DiffuseTexel * (vec4(1.f, 1.f, 1.f, 0.0) + LightingTexel);
|
||||||
|
//frag_Diffuse = DiffuseTexel;
|
||||||
//frag_Diffuse = vec4(LightingTexel.r, LightingTexel.g, LightingTexel.b, 1.0);
|
//frag_Diffuse = vec4(LightingTexel.r, LightingTexel.g, LightingTexel.b, 1.0);
|
||||||
}
|
}
|
||||||
@@ -84,6 +84,6 @@ void main()
|
|||||||
|
|
||||||
vec4 diffuseTexel = texture(DiffuseTexture, Input.TextureCoord);
|
vec4 diffuseTexel = texture(DiffuseTexture, Input.TextureCoord);
|
||||||
|
|
||||||
//FragmentColor = phong(Input.Position, normalize(normal), specularTexel.rgb, specularTexel.a);
|
FragmentColor = phong(Input.Position, normalize(normal), specularTexel.rgb, specularTexel.a);
|
||||||
FragmentColor = diffuseTexel;
|
//FragmentColor = diffuseTexel;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user