Merge branch 'master' into LevelSystemAndSuch

This commit is contained in:
PlatinumSkink
2015-09-15 17:31:53 +02:00
8 changed files with 224 additions and 21 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 4.0 MiB

Regular → Executable
+30 -13
View File
@@ -99,21 +99,12 @@ public:
//TODO: Remove tobias light-test code.
/*{
auto t_BrickWall = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(t_BrickWall);
transform->Position = glm::vec3(0.f, 0.f, -10.f);
auto sprite = m_World->AddComponent<Components::Sprite>(t_BrickWall);
//TODO: Rename SpriteFile to DiffuseTexture or similar.
sprite->SpriteFile = "Textures/Test/Brick_Diffuse.png";
sprite->NormalTexture = "Textures/Test/Brick_Normal.png";
sprite->SpecularTexture = "Textures/Test/Brick_Specular.png";
}*/
{
auto ent = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
transform->Position = glm::vec3(0.5f, 0.f, -10.f);
transform->Position = glm::vec3(0.5f, 0.f, -9.9f);
transform->Scale = glm::vec3(1.f, 1.f, 1.f);
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(ent);
@@ -137,6 +128,28 @@ public:
m_EventBroker->Publish(e);
}
{
auto t_BrickWall = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(t_BrickWall);
transform->Position = glm::vec3(0.f, 0.f, -10.f);
auto sprite = m_World->AddComponent<Components::Sprite>(t_BrickWall);
//TODO: Rename SpriteFile to DiffuseTexture or similar.
sprite->SpriteFile = "Textures/Ball.png";
sprite->NormalTexture = "Textures/Test/Brick_Normal.png";
sprite->SpecularTexture = "Textures/Test/Brick_Specular.png";
}
{
auto t_BrickWall = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(t_BrickWall);
transform->Position = glm::vec3(0.4f, 0.f, -9.5f);
auto sprite = m_World->AddComponent<Components::Sprite>(t_BrickWall);
//TODO: Rename SpriteFile to DiffuseTexture or similar.
sprite->SpriteFile = "Textures/Ball.png";
sprite->NormalTexture = "Textures/Test/Brick_Normal.png";
sprite->SpecularTexture = "Textures/Test/Brick_Specular.png";
}
{
auto topWall = m_World->CreateEntity();
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(topWall);
@@ -343,7 +356,7 @@ public:
glm::mat4 modelMatrix = glm::translate(absoluteTransform.Position)
* glm::toMat4(orientation2D)
* glm::scale(absoluteTransform.Scale);
EnqueueSprite(texturediff, texturenorm, texturespec, modelMatrix, spriteComponent->Color);
EnqueueSprite(texturediff, texturenorm, texturespec, modelMatrix, spriteComponent->Color, absoluteTransform.Position.z);
}
}
@@ -366,13 +379,15 @@ public:
job.EndIndex = texGroup.EndIndex;
job.ModelMatrix = modelMatrix;
job.Color = color;
//TODO: This Depth is probably wrong.
job.Depth = (glm::vec4(1,1,1,0) * modelMatrix).z;
m_RendererQueue.Deferred.Add(job);
}
}
// TODO: Get this out of engine.h
void EnqueueSprite(Texture* texture, Texture* normalTexture, Texture* specularTexture, glm::mat4 modelMatrix, glm::vec4 color)
void EnqueueSprite(Texture* texture, Texture* normalTexture, Texture* specularTexture, glm::mat4 modelMatrix, glm::vec4 color, float depth)
{
SpriteJob job;
job.TextureID = texture->ResourceID;
@@ -381,8 +396,10 @@ public:
job.SpecularTexture = *specularTexture;
job.ModelMatrix = modelMatrix;
job.Color = color;
job.Depth = depth;
m_RendererQueue.Deferred.Add(job);
m_RendererQueue.Forward.Add(job);
}
void EnqueuePointLight(glm::vec3 position, glm::vec3 diffuseColor, glm::vec3 specularColor, float radius)
+2
View File
@@ -93,6 +93,8 @@ private:
void CreateBuffers();
GLuint CreateQuad();
static bool DepthSort(const std::shared_ptr<RenderJob> &i, const std::shared_ptr<RenderJob> &j) { return (i->Depth < j->Depth); }
void DrawDeferred(RenderQueue &objects, RenderQueue &lights);
void DrawForward(RenderQueue &objects, RenderQueue &lights);
void DrawScene(RenderQueue &objects, ShaderProgram &program);
+13 -2
View File
@@ -207,7 +207,9 @@ void dd::Renderer::CreateBuffers()
void dd::Renderer::Draw(RenderQueueCollection& rq)
{
DrawDeferred(rq.Deferred, rq.Lights);
//DrawDeferred(rq.Deferred, rq.Lights);
rq.Forward.Jobs.sort(dd::Renderer::DepthSort);
DrawForward(rq.Forward, rq.Lights);
// Finally: Draw the deferred+forward combined texture to the screen
@@ -276,14 +278,20 @@ void dd::Renderer::DrawDeferred(RenderQueue &objects, RenderQueue &lights)
void dd::Renderer::DrawForward(RenderQueue &objects, RenderQueue &lights)
{
// Forward-render semi-transparent objects on top of the current framebuffer
glDisable(GL_CULL_FACE);
glCullFace(GL_BACK);
glDepthMask(GL_TRUE);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
//glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
glBindFramebuffer(GL_FRAMEBUFFER, m_fbDeferred3);
glClearColor(1, 0.9, 0.8f, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
m_spForward->Bind();
DrawScene(objects, *m_spForward);
}
@@ -304,10 +312,13 @@ void dd::Renderer::DrawScene(RenderQueue &objects, ShaderProgram &program)
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
glUniformMatrix4fv(glGetUniformLocation(shaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(viewMatrix));
glUniform3fv(glGetUniformLocation(shaderProgramHandle, "LightPosition"), 1, glm::value_ptr(glm::vec3(0.f,0.f,-9.f)));
glUniform3fv(glGetUniformLocation(shaderProgramHandle, "LightSpecular"), 1, glm::value_ptr(glm::vec3(1.f)));
glUniform3fv(glGetUniformLocation(shaderProgramHandle, "LightDiffuse"), 1, glm::value_ptr(glm::vec3(1.f)));
glUniform1f(glGetUniformLocation(shaderProgramHandle, "LightRadius"), 40.0f);
glUniform1f(glGetUniformLocation(shaderProgramHandle, "MaterialShininess"), modelJob->Shininess);
//TODO: Make sure that a normal/specular is loaded in.
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture);
if (modelJob->NormalTexture != 0) {
@@ -38,7 +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) + LightingTexel);
frag_Diffuse = DiffuseTexel * (vec4(1.f, 1.f, 1.f, 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);
}
+5 -4
View File
@@ -46,7 +46,7 @@ in VertexData
vec4 BoneWeights2;
} Input;
out vec4 FragmentColor;
out vec4 frag_Diffuse;
vec4 phong(vec3 position, vec3 normal, vec3 specular, float specularExponent)
{
@@ -83,7 +83,8 @@ void main()
vec4 specularTexel = texture(SpecularMap, Input.TextureCoord);
vec4 diffuseTexel = texture(DiffuseTexture, Input.TextureCoord);
FragmentColor = phong(Input.Position, normalize(normal), specularTexel.rgb, specularTexel.a);
//FragmentColor = diffuseTexel;
vec4 La = vec4(0.3, 0.3, 0.3, 1.0);
vec4 light = phong(Input.Position, normalize(normal), specularTexel.rgb, specularTexel.a);
//frag_Diffuse = light;
frag_Diffuse = diffuseTexel;
}
+89
View File
@@ -0,0 +1,89 @@
/*
This file is part of Daydream Engine.
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
Daydream Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Daydream Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#version 440
layout (binding=0) uniform sampler2D DiffuseTexture;
layout (binding=1) uniform sampler2D NormalMap;
layout (binding=2) uniform sampler2D SpecularMap;
uniform mat4 MVP;
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
uniform vec3 LightPosition;
uniform float LightRadius;
uniform vec3 LightSpecular;
uniform vec3 LightDiffuse;
in VertexData
{
vec3 Position;
vec3 Normal;
vec3 Tangent;
vec3 BiTangent;
vec2 TextureCoord;
vec4 DiffuseColor;
vec4 SpecularColor;
vec4 BoneIndices1;
vec4 BoneIndices2;
vec4 BoneWeights1;
vec4 BoneWeights2;
} Input;
out vec4 frag_Diffuse;
vec4 phong(vec3 position, vec3 normal, vec3 specular, float specularExponent)
{
// Diffuse
vec3 lightPos = vec3(V * vec4(LightPosition, 1.0));
vec3 distanceToLight = lightPos - position;
vec3 directionToLight = normalize(distanceToLight);
float dotProd = dot(directionToLight, normal);
dotProd = max(dotProd, 0.0);
vec3 Idiffuse = LightDiffuse * dotProd;
// Specular
//vec3 reflection = reflect(-directionToLight, normal);
vec3 surfaceToViewer = normalize(-position);
vec3 halfWay = normalize(surfaceToViewer + directionToLight);
float dotSpecular = max(dot(halfWay, normal), 0.0);
float specularFactor = pow(dotSpecular, specularExponent);
vec3 Ispecular = specular * LightSpecular * specularFactor;
//Attenuation
float dist = distance(lightPos, position);
//float attenuation = 1.0 - pow(dist / LightRadius, 2);
float attenuation = pow(max(0.0f, 1.0 - (dist / LightRadius)), 2);
return vec4((Idiffuse + Ispecular) * attenuation, 1.0);
}
void main()
{
vec4 normalTexel = texture(NormalMap, Input.TextureCoord);
mat3 TBN = mat3(Input.Tangent, Input.BiTangent, Input.Normal);
vec3 normal = normalize(vec4(TBN * normalTexel.xyz, 0.0).xyz);
vec4 specularTexel = texture(SpecularMap, Input.TextureCoord);
vec4 diffuseTexel = texture(DiffuseTexture, Input.TextureCoord);
//frag_Diffuse = phong(Input.Position, normalize(normal), specularTexel.rgb, specularTexel.a);
frag_Diffuse = diffuseTexel;
}
+83
View File
@@ -0,0 +1,83 @@
/*
This file is part of Daydream Engine.
Copyright 2014 Adam Byléhn, Tobias Dahl, Simon Holmberg, Viktor Ljung
Daydream Engine is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Daydream Engine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with Daydream Engine. If not, see <http://www.gnu.org/licenses/>.
*/
#version 440
uniform mat4 MVP;
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
uniform mat4 Bones[100];
layout (location = 0) in vec3 Position;
layout (location = 1) in vec3 Normal;
layout (location = 2) in vec3 Tangent;
layout (location = 3) in vec3 BiTangent;
layout (location = 4) in vec2 TextureCoord;
layout (location = 5) in vec4 DiffuseColor;
layout (location = 6) in vec4 SpecularColor;
layout (location = 7) in vec4 BoneIndices1;
layout (location = 8) in vec4 BoneIndices2;
layout (location = 9) in vec4 BoneWeights1;
layout (location = 10) in vec4 BoneWeights2;
out VertexData
{
vec3 Position;
vec3 Normal;
vec3 Tangent;
vec3 BiTangent;
vec2 TextureCoord;
vec4 DiffuseColor;
vec4 SpecularColor;
vec4 BoneIndices1;
vec4 BoneIndices2;
vec4 BoneWeights1;
vec4 BoneWeights2;
} Output;
void main()
{
mat4 boneTransform = mat4(1);
if (length(BoneWeights1 + BoneWeights2) > 0) {
boneTransform = BoneWeights1[0] * Bones[int(BoneIndices1[0])]
+ BoneWeights1[1] * Bones[int(BoneIndices1[1])]
+ BoneWeights1[2] * Bones[int(BoneIndices1[2])]
+ BoneWeights1[3] * Bones[int(BoneIndices1[3])]
+ BoneWeights2[0] * Bones[int(BoneIndices2[0])]
+ BoneWeights2[1] * Bones[int(BoneIndices2[1])]
+ BoneWeights2[2] * Bones[int(BoneIndices2[2])]
+ BoneWeights2[3] * Bones[int(BoneIndices2[3])];
}
//gl_Position = MVP * boneTransform * vec4(Position, 1.0);
gl_Position = MVP * vec4(Position, 1.0);
//TODO: Make sure that boneTransform works here.
Output.Position = (V * M * boneTransform * vec4(Position, 1.0)).xyz;
Output.Normal = (inverse(transpose(V * M)) * boneTransform * vec4(Normal, 0.0)).xyz;
Output.Tangent = Tangent;
Output.BiTangent = BiTangent;
Output.TextureCoord = TextureCoord;
Output.DiffuseColor = DiffuseColor;
Output.SpecularColor = SpecularColor;
Output.BoneIndices1 = BoneIndices1;
Output.BoneIndices2 = BoneIndices2;
Output.BoneWeights1 = BoneWeights1;
Output.BoneWeights2 = BoneWeights2;
}