Merge remote-tracking branch 'origin/master' into Sound+Particles

Conflicts:
	assets
This commit is contained in:
Stiffly
2014-06-04 06:17:05 +02:00
13 changed files with 228 additions and 140 deletions
+1 -1
Submodule assets updated: a6e3f120fd...e09ebf5a29
+32 -29
View File
@@ -513,12 +513,15 @@ void GameWorld::BindGamepadButton(Gamepad::Button button, std::string command, f
EventBroker->Publish(e); EventBroker->Publish(e);
} }
void GameWorld::CreateGate(glm::vec3 Position) void GameWorld::CreateGate(EntityID parent, glm::vec3 position, glm::quat orientation)
{ {
auto gateParent = CreateEntity(parent);
auto transform = AddComponent<Components::Transform>(gateParent);
transform->Position = position;
transform->Orientation = orientation;
{ {
auto gateBase = CreateEntity(); auto gateBase = CreateEntity(gateParent);
auto transform = AddComponent<Components::Transform>(gateBase); auto transform = AddComponent<Components::Transform>(gateBase);
transform->Position = Position;
auto model = AddComponent<Components::Model>(gateBase); auto model = AddComponent<Components::Model>(gateBase);
model->ModelFile = "Models/Gate/Lift/Lift.obj"; model->ModelFile = "Models/Gate/Lift/Lift.obj";
auto physics = AddComponent<Components::Physics>(gateBase); auto physics = AddComponent<Components::Physics>(gateBase);
@@ -577,10 +580,9 @@ void GameWorld::CreateGate(glm::vec3 Position)
CommitEntity(gateBase); CommitEntity(gateBase);
} }
auto gate = CreateEntity(gateParent);
{ {
auto gate = CreateEntity();
auto transform = AddComponent<Components::Transform>(gate); auto transform = AddComponent<Components::Transform>(gate);
transform->Position = Position;
auto model = AddComponent<Components::Model>(gate); auto model = AddComponent<Components::Model>(gate);
model->ModelFile = "Models/Gate/Gate/Gate.obj"; model->ModelFile = "Models/Gate/Gate/Gate.obj";
auto physics = AddComponent<Components::Physics>(gate); auto physics = AddComponent<Components::Physics>(gate);
@@ -588,8 +590,8 @@ void GameWorld::CreateGate(glm::vec3 Position)
physics->CollisionLayer = (int)Components::Physics::CollisionLayer::STATIC; physics->CollisionLayer = (int)Components::Physics::CollisionLayer::STATIC;
auto move = AddComponent<Components::Move>(gate); auto move = AddComponent<Components::Move>(gate);
move->Speed = 5.f; move->Speed = 5.f;
move->GoalPosition = glm::vec3(Position.x, Position.y + 9.02345f, Position.z); move->GoalPosition = glm::vec3(0, 9.02345f, 0);
move->StartPosition = glm::vec3(Position.x, Position.y, Position.z); move->StartPosition = glm::vec3(0, 0, 0);
{ {
auto mainShape = CreateEntity(gate); auto mainShape = CreateEntity(gate);
auto transform = AddComponent<Components::Transform>(mainShape); auto transform = AddComponent<Components::Transform>(mainShape);
@@ -611,29 +613,27 @@ void GameWorld::CreateGate(glm::vec3 Position)
CommitEntity(lowerShape); CommitEntity(lowerShape);
} }
CommitEntity(gate); CommitEntity(gate);
}
{
auto gateTrigger = CreateEntity(gateParent);
auto transform = AddComponent<Components::Transform>(gateTrigger);
transform->Position = glm::vec3(0, 2.8241, 0);
auto trigger = AddComponent<Components::Trigger>(gateTrigger);
auto triggerMove = AddComponent<Components::TriggerMove>(gateTrigger);
triggerMove->Entity = gate;
{ {
auto gateTrigger = CreateEntity(); auto shape = CreateEntity(gateTrigger);
auto transform = AddComponent<Components::Transform>(gateTrigger); auto transform = AddComponent<Components::Transform>(shape);
transform->Position = glm::vec3(Position.x, Position.y + 2.8241, Position.z); transform->Position = glm::vec3(0.f, 2.8241f, 0.f);
auto trigger = AddComponent<Components::Trigger>(gateTrigger); auto box = AddComponent<Components::BoxShape>(shape);
auto triggerMove = AddComponent<Components::TriggerMove>(gateTrigger); box->Width = 6.963f;
triggerMove->Entity = gate; box->Height = 3.104f;
box->Depth = 10.356f;
CommitEntity(shape);
{
auto shape = CreateEntity(gateTrigger);
auto transform = AddComponent<Components::Transform>(shape);
transform->Position = glm::vec3(0.f, 2.8241f, 0.f);
auto box = AddComponent<Components::BoxShape>(shape);
box->Width = 6.963f;
box->Height = 3.104f;
box->Depth = 10.356f;
CommitEntity(shape);
}
CommitEntity(gateTrigger);
} }
CommitEntity(gateTrigger);
} }
} }
@@ -949,7 +949,7 @@ void GameWorld::CreateBase(glm::quat orientation, int playerID)
auto base = CreateEntity(); auto base = CreateEntity();
auto transform = AddComponent<Components::Transform>(base); auto transform = AddComponent<Components::Transform>(base);
transform->Orientation = orientation; transform->Orientation = orientation;
#pragma region Terrain
{ {
auto ground_small = CreateEntity(base); auto ground_small = CreateEntity(base);
auto transform = AddComponent<Components::Transform>(ground_small); auto transform = AddComponent<Components::Transform>(ground_small);
@@ -1012,7 +1012,7 @@ void GameWorld::CreateBase(glm::quat orientation, int playerID)
auto shape = CreateEntity(bridge_middle); auto shape = CreateEntity(bridge_middle);
auto transformshape = AddComponent<Components::Transform>(shape); auto transformshape = AddComponent<Components::Transform>(shape);
auto meshShape = AddComponent<Components::MeshShape>(shape); auto meshShape = AddComponent<Components::MeshShape>(shape);
meshShape->ResourceName = "Models/TerrainFiveIstles/Bridges/MiddleBridge.obj"; meshShape->ResourceName = "Models/TerrainFiveIstles/Bridges/MiddleBridgeCollision.obj";
CommitEntity(shape); CommitEntity(shape);
} }
CommitEntity(bridge_middle); CommitEntity(bridge_middle);
@@ -1105,6 +1105,9 @@ void GameWorld::CreateBase(glm::quat orientation, int playerID)
} }
CommitEntity(bridge_base); CommitEntity(bridge_base);
} }
#pragma endregion Terrain
CreateGate(base, glm::vec3(273.f, 40.185f, 0.06f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)));
CreateGarage(base, glm::vec3(323.2f, 41.4f, -10.2f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)), playerID); CreateGarage(base, glm::vec3(323.2f, 41.4f, -10.2f), glm::quat(glm::vec3(0, glm::pi<float>() / 2.f, 0)), playerID);
} }
+1 -1
View File
@@ -78,7 +78,7 @@ private:
void BindGamepadAxis(Gamepad::Axis axis, std::string command, float value); void BindGamepadAxis(Gamepad::Axis axis, std::string command, float value);
void BindGamepadButton(Gamepad::Button button, std::string command, float value); void BindGamepadButton(Gamepad::Button button, std::string command, float value);
void CreateGate(glm::vec3 Position); void CreateGate(EntityID parent, glm::vec3 position, glm::quat orientation);
void AddTankWheelPair(EntityID tankEntity, glm::vec3 position, int axleID, bool steering); void AddTankWheelPair(EntityID tankEntity, glm::vec3 position, int axleID, bool steering);
EntityID CreateJeep(int playerID); EntityID CreateJeep(int playerID);
EntityID CreateWall(glm::vec3 pos, glm::quat orientation); EntityID CreateWall(glm::vec3 pos, glm::quat orientation);
+9 -6
View File
@@ -93,7 +93,7 @@ Model::Model(std::shared_ptr<ResourceManager> rm, OBJ &obj)
if (Vertices.size() > 0) if (Vertices.size() > 0)
{ {
CreateTangents(); CreateTangents();
//getSimilarVertexIndex(); getSimilarVertexIndex();
CreateBuffers(Vertices, Normals, TangentNormals, BiTangentNormals, TextureCoords); CreateBuffers(Vertices, Normals, TangentNormals, BiTangentNormals, TextureCoords);
} }
else else
@@ -105,7 +105,7 @@ Model::Model(std::shared_ptr<ResourceManager> rm, OBJ &obj)
void Model::CreateBuffers( std::vector<glm::vec3> vertices, std::vector<glm::vec3> normals, std::vector<glm::vec3> tangents, std::vector<glm::vec3> biTangents, std::vector<glm::vec2>textureCoords) void Model::CreateBuffers( std::vector<glm::vec3> vertices, std::vector<glm::vec3> normals, std::vector<glm::vec3> tangents, std::vector<glm::vec3> biTangents, std::vector<glm::vec2>textureCoords)
{ {
LOG_INFO("Generating VertexBuffer"); //LOG_INFO("Generating VertexBuffer");
glGenBuffers(1, &VertexBuffer); glGenBuffers(1, &VertexBuffer);
if (vertices.size() > 0) if (vertices.size() > 0)
{ {
@@ -118,7 +118,7 @@ void Model::CreateBuffers( std::vector<glm::vec3> vertices, std::vector<glm::vec
LOG_WARNING("Created empty vertex buffer!"); LOG_WARNING("Created empty vertex buffer!");
} }
LOG_INFO("Generating NormalBuffer"); //LOG_INFO("Generating NormalBuffer");
glGenBuffers(1, &NormalBuffer); glGenBuffers(1, &NormalBuffer);
if (normals.size() > 0) if (normals.size() > 0)
{ {
@@ -131,7 +131,7 @@ void Model::CreateBuffers( std::vector<glm::vec3> vertices, std::vector<glm::vec
LOG_WARNING("Created empty normal buffer!"); LOG_WARNING("Created empty normal buffer!");
} }
LOG_INFO("Generating TangentNormalsBuffer"); //LOG_INFO("Generating TangentNormalsBuffer");
glGenBuffers(1, &TangentNormalsBuffer); glGenBuffers(1, &TangentNormalsBuffer);
if (tangents.size() > 0) if (tangents.size() > 0)
{ {
@@ -144,7 +144,7 @@ void Model::CreateBuffers( std::vector<glm::vec3> vertices, std::vector<glm::vec
LOG_WARNING("Created empty tangent buffer!"); LOG_WARNING("Created empty tangent buffer!");
} }
LOG_INFO("Generating BiTangentNormalsBuffer"); //LOG_INFO("Generating BiTangentNormalsBuffer");
glGenBuffers(1, &BiTangentNormalsBuffer); glGenBuffers(1, &BiTangentNormalsBuffer);
if (biTangents.size() > 0) if (biTangents.size() > 0)
{ {
@@ -158,7 +158,7 @@ void Model::CreateBuffers( std::vector<glm::vec3> vertices, std::vector<glm::vec
} }
LOG_INFO("Generating textureCoordBuffer"); //LOG_INFO("Generating textureCoordBuffer");
glGenBuffers(1, &TextureCoordBuffer); glGenBuffers(1, &TextureCoordBuffer);
if (textureCoords.size() > 0) if (textureCoords.size() > 0)
{ {
@@ -223,6 +223,8 @@ void Model::getSimilarVertexIndex()
{ {
glm::vec3 tempNormal, tempTangent, tempBiTangent; glm::vec3 tempNormal, tempTangent, tempBiTangent;
if(glm::dot(Normals[i], Normals[t]) > 0)
{
tempNormal = Normals[i] + Normals[t]; tempNormal = Normals[i] + Normals[t];
tempTangent = TangentNormals[i] + TangentNormals[t]; tempTangent = TangentNormals[i] + TangentNormals[t];
tempBiTangent = BiTangentNormals[i] + BiTangentNormals[t]; tempBiTangent = BiTangentNormals[i] + BiTangentNormals[t];
@@ -235,6 +237,7 @@ void Model::getSimilarVertexIndex()
BiTangentNormals[i] = tempBiTangent; BiTangentNormals[i] = tempBiTangent;
BiTangentNormals[t] = tempBiTangent; BiTangentNormals[t] = tempBiTangent;
}
} }
} }
} }
+3 -3
View File
@@ -13,7 +13,7 @@ bool OBJ::LoadFromFile(std::string filename)
return false; return false;
} }
LOG_INFO("Parsing .obj \"%s\"", m_Path.string().c_str()); //LOG_INFO("Parsing .obj \"%s\"", m_Path.string().c_str());
std::string line; std::string line;
while (std::getline(file, line)) while (std::getline(file, line))
@@ -121,7 +121,7 @@ void OBJ::ParseMaterial()
return; return;
} }
LOG_INFO("Parsing .mtl \"%s\"", m_MaterialPath.string().c_str()); //LOG_INFO("Parsing .mtl \"%s\"", m_MaterialPath.string().c_str());
std::string currentMaterialName; std::string currentMaterialName;
MaterialInfo* currentMaterial = nullptr; MaterialInfo* currentMaterial = nullptr;
@@ -144,7 +144,7 @@ void OBJ::ParseMaterial()
{ {
MaterialInfo mat; MaterialInfo mat;
ss >> currentMaterialName; ss >> currentMaterialName;
LOG_INFO("Parsing material %s", currentMaterialName.c_str()); //LOG_INFO("Parsing material %s", currentMaterialName.c_str());
Materials[currentMaterialName] = mat; Materials[currentMaterialName] = mat;
currentMaterial = &Materials[currentMaterialName]; currentMaterial = &Materials[currentMaterialName];
continue; continue;
+108 -81
View File
@@ -22,7 +22,7 @@ Renderer::Renderer(std::shared_ptr<::ResourceManager> resourceManager)
LAtt = 0.0f; LAtt = 0.0f;
QAtt = 3.0f; QAtt = 3.0f;
m_ShadowMapRes = 1; m_ShadowMapRes = 1;
m_SunPosition = glm::vec3(0.f, 1.0f, 0.5f); m_SunPosition = glm::vec3(0.f, 1.0f, 0.7f);
m_SunTarget = glm::vec3(0, 0, 0); m_SunTarget = glm::vec3(0, 0, 0);
m_SunProjection_height = glm::vec2(-40.f, 40.f); m_SunProjection_height = glm::vec2(-40.f, 40.f);
m_SunProjection_width = glm::vec2(-40.f, 40.f); m_SunProjection_width = glm::vec2(-40.f, 40.f);
@@ -126,6 +126,7 @@ void Renderer::LoadContent()
m_SunPassProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/SunPass.vert.glsl"))); m_SunPassProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/SunPass.vert.glsl")));
m_SunPassProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/SunPass.frag.glsl"))); m_SunPassProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/SunPass.frag.glsl")));
m_SunPassProgram.Compile(); m_SunPassProgram.Compile();
glBindFragDataLocation(m_SunPassProgram.GetHandle(), 0, "frag_Light");
m_SunPassProgram.Link(); m_SunPassProgram.Link();
m_ForwardRendering.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/ForwardRendering.vert.glsl"))); m_ForwardRendering.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/ForwardRendering.vert.glsl")));
@@ -142,7 +143,6 @@ void Renderer::LoadContent()
m_FirstPassProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Vertex.glsl"))); m_FirstPassProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Vertex.glsl")));
m_FirstPassProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Fragment.glsl"))); m_FirstPassProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Fragment.glsl")));
m_FirstPassProgram.Compile(); m_FirstPassProgram.Compile();
glBindFragDataLocation(m_FirstPassProgram.GetHandle(), 0, "frag_Diffuse"); glBindFragDataLocation(m_FirstPassProgram.GetHandle(), 0, "frag_Diffuse");
glBindFragDataLocation(m_FirstPassProgram.GetHandle(), 1, "frag_Position"); glBindFragDataLocation(m_FirstPassProgram.GetHandle(), 1, "frag_Position");
glBindFragDataLocation(m_FirstPassProgram.GetHandle(), 2, "frag_Normal"); glBindFragDataLocation(m_FirstPassProgram.GetHandle(), 2, "frag_Normal");
@@ -151,6 +151,7 @@ void Renderer::LoadContent()
m_SecondPassProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Vertex2.glsl"))); m_SecondPassProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Vertex2.glsl")));
m_SecondPassProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Fragment2.glsl"))); m_SecondPassProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/Fragment2.glsl")));
m_SecondPassProgram.Compile(); m_SecondPassProgram.Compile();
glBindFragDataLocation(m_SecondPassProgram.GetHandle(), 0, "frag_Light");
m_SecondPassProgram.Link(); m_SecondPassProgram.Link();
m_SecondPassProgram_Debug.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Vertex2.glsl"))); m_SecondPassProgram_Debug.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/Vertex2.glsl")));
@@ -161,6 +162,7 @@ void Renderer::LoadContent()
m_FinalPassProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/FinalPass.vert.glsl"))); m_FinalPassProgram.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/FinalPass.vert.glsl")));
m_FinalPassProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/FinalPass.frag.glsl"))); m_FinalPassProgram.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/FinalPass.frag.glsl")));
m_FinalPassProgram.Compile(); m_FinalPassProgram.Compile();
glBindFragDataLocation(m_FinalPassProgram.GetHandle(), 0, "frag_Diffuse");
m_FinalPassProgram.Link(); m_FinalPassProgram.Link();
m_ScreenQuad = CreateQuad(); m_ScreenQuad = CreateQuad();
CreateShadowMap(m_ShadowMapRes); CreateShadowMap(m_ShadowMapRes);
@@ -269,6 +271,7 @@ void Renderer::Draw(double dt)
void Renderer::DrawFrame(RenderQueuePair &rq) void Renderer::DrawFrame(RenderQueuePair &rq)
{ {
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height); glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
glScissor(m_Scissor.X, m_Height - m_Scissor.Y - m_Scissor.Height, m_Scissor.Width, m_Scissor.Height); glScissor(m_Scissor.X, m_Height - m_Scissor.Y - m_Scissor.Height, m_Scissor.Width, m_Scissor.Height);
@@ -386,81 +389,78 @@ void Renderer::DrawWorld(RenderQueuePair &rq)
rq.Forward.Jobs.sort(Renderer::DepthSort); rq.Forward.Jobs.sort(Renderer::DepthSort);
//DrawShadowMap(rq.Deferred); //DrawShadowMap(rq.Deferred);
/* /*
Base pass Base pass
*/ */
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbBasePass); glBindFramebuffer(GL_FRAMEBUFFER, m_fbBasePass);
glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height); glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
glScissor(m_Scissor.X, m_Height - m_Scissor.Y - m_Scissor.Height, m_Scissor.Width, m_Scissor.Height); glScissor(m_Scissor.X, m_Height - m_Scissor.Y - m_Scissor.Height, m_Scissor.Width, m_Scissor.Height);
//glViewport(0, 0, m_Width, m_Height); //glViewport(0, 0, m_Width, m_Height);
// Clear G-buffer // Clear G-buffer
GLenum windowBuffClear[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 };
glDrawBuffers(4, windowBuffClear);
glClearColor(115.f / 255, 192.f / 255, 255.f / 255, 0.f); glClearColor(115.f / 255, 192.f / 255, 255.f / 255, 0.f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Execute the first render stage which will fill out the internal buffers with data(??) // Execute the first render stage which will fill out the internal buffers with data(??)
m_FirstPassProgram.Bind(); m_FirstPassProgram.Bind();
GLenum windowBuffOpaque[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 };
glDrawBuffers(4, windowBuffOpaque);
glCullFace(GL_BACK); glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
DrawSkybox(); //DrawSkybox();
DrawFBOScene(rq.Deferred); DrawFBOScene(rq.Deferred);
/* /*
Lighting pass Lighting pass
*/ */
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbLightingPass); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbLightingPass);
//glBindFramebuffer(GL_FRAMEBUFFER, m_fbBasePass);
glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height); glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
glScissor(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height); glScissor(m_Scissor.X, m_Height - m_Scissor.Y - m_Scissor.Height, m_Scissor.Width, m_Scissor.Height);
GLenum lightingPassAttachments[] = { GL_COLOR_ATTACHMENT0 };
glDrawBuffers(1, lightingPassAttachments);
glCullFace(GL_FRONT);
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
glClearColor(0.f, 0.f, 0.f, 0.f); glClearColor(0.f, 0.f, 0.f, 0.f);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
m_SecondPassProgram.Bind();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_fPositionTexture);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_fNormalsTexture);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, m_fSpecularTexture);
glCullFace(GL_FRONT);
DrawLightScene(rq.Deferred); DrawLightScene(rq.Deferred);
glCullFace(GL_BACK);
DrawSunLightScene(); DrawSunLightScene();
/* /*
Final pass Final pass
*/ */
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
//glViewport(m_Viewport.X, m_Viewport.Y, m_Viewport.Width, m_Viewport.Height);
glViewport(0, 0, m_Width, m_Height);
//glScissor(0, 0, m_Width, m_Height);
glScissor(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
glClear(GL_DEPTH_BUFFER_BIT); glBindFramebuffer(GL_FRAMEBUFFER, m_fbFinalPass);
glViewport(0, 0, m_Width, m_Height);
glScissor(0, 0, m_Width, m_Height);
//glScissor(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.f, 0.f, 0.f, 0.f);
m_FinalPassProgram.Bind(); m_FinalPassProgram.Bind();
// Ambient light
glUniform3fv(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "La"), 1, glm::value_ptr(glm::vec3(1.0f)));
//glUniform1f(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "Gamma"), Gamma);
// Ambient light glActiveTexture(GL_TEXTURE0);
glUniform3fv(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "La"), 1, glm::value_ptr(glm::vec3(0.7f))); glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture);
glUniform1f(glGetUniformLocation(m_FinalPassProgram.GetHandle(), "Gamma"), Gamma); glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_fLightingTexture);
glActiveTexture(GL_TEXTURE0); glCullFace(GL_BACK);
glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture); glBindVertexArray(m_ScreenQuad);
glActiveTexture(GL_TEXTURE1); glEnableVertexAttribArray(0);
glBindTexture(GL_TEXTURE_2D, m_fLightingTexture); glDrawArrays(GL_TRIANGLES, 0, 6);
glCullFace(GL_BACK);
glBindVertexArray(m_ScreenQuad);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 6);
/* /*
Transparency Transparency
@@ -470,25 +470,23 @@ void Renderer::DrawWorld(RenderQueuePair &rq)
void Renderer::ForwardRendering(RenderQueue &rq) void Renderer::ForwardRendering(RenderQueue &rq)
{ {
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_fbBasePass);
glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
glScissor(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
// Clear G-buffer
GLenum attachments[] = { GL_COLOR_ATTACHMENT0, GL_NONE , GL_NONE , GL_NONE };
glDrawBuffers(4, attachments);
//glClearColor(0.f, 0.f, 0.f, 1.f);
//glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE); glDepthMask(GL_FALSE);
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
glCullFace(GL_BACK); glCullFace(GL_BACK);
//glBindFramebuffer(GL_FRAMEBUFFER, m_fbBasePass);
glViewport(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
glScissor(m_Viewport.X, m_Height - m_Viewport.Y - m_Viewport.Height, m_Viewport.Width, m_Viewport.Height);
// Clear G-buffer
//GLenum attachments[] = { GL_COLOR_ATTACHMENT0, GL_NONE , GL_NONE, GL_NONE };
//glDrawBuffers(4, attachments);
//glClear(GL_COLOR_BUFFER_BIT);
//glClearColor(0.f, 0.f, 0.f, 0.f);
glm::mat4 cameraProjection = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height); glm::mat4 cameraProjection = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height);
glm::mat4 cameraMatrix = cameraProjection * m_Camera->ViewMatrix(); glm::mat4 cameraMatrix = cameraProjection * m_Camera->ViewMatrix();
glm::mat4 MVP; glm::mat4 MVP;
@@ -497,7 +495,7 @@ void Renderer::ForwardRendering(RenderQueue &rq)
GLuint ShaderProgramHandle = m_ForwardRendering.GetHandle(); GLuint ShaderProgramHandle = m_ForwardRendering.GetHandle();
for (auto &job : rq) for (auto &job : rq)
{ {
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job); auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
if (modelJob) if (modelJob)
{ {
glm::mat4 modelMatrix = modelJob->ModelMatrix; glm::mat4 modelMatrix = modelJob->ModelMatrix;
@@ -508,12 +506,14 @@ void Renderer::ForwardRendering(RenderQueue &rq)
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix())); glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "P"), 1, GL_FALSE, glm::value_ptr(cameraProjection)); glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "P"), 1, GL_FALSE, glm::value_ptr(cameraProjection));
glUniform4fv(glGetUniformLocation(ShaderProgramHandle, "Color"), 1, glm::value_ptr(modelJob->Color)); glUniform4fv(glGetUniformLocation(ShaderProgramHandle, "Color"), 1, glm::value_ptr(modelJob->Color));
glUniform3fv(glGetUniformLocation(ShaderProgramHandle, "La"), 1, glm::value_ptr(glm::vec3(1.0f)));
glUniform3fv(glGetUniformLocation(ShaderProgramHandle, "directionToSun"), 1, glm::value_ptr(glm::normalize(m_SunPosition)));
glBindVertexArray(modelJob->VAO); glBindVertexArray(modelJob->VAO);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture); glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture);
/*if (modelJob->NormalTexture != 0) if (modelJob->NormalTexture != 0)
{ {
glActiveTexture(GL_TEXTURE2); glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, modelJob->NormalTexture); glBindTexture(GL_TEXTURE_2D, modelJob->NormalTexture);
@@ -522,7 +522,7 @@ void Renderer::ForwardRendering(RenderQueue &rq)
{ {
glActiveTexture(GL_TEXTURE3); glActiveTexture(GL_TEXTURE3);
glBindTexture(GL_TEXTURE_2D, modelJob->SpecularTexture); glBindTexture(GL_TEXTURE_2D, modelJob->SpecularTexture);
}*/ }
glDrawArrays(GL_TRIANGLES, modelJob->StartIndex, modelJob->EndIndex - modelJob->StartIndex + 1); glDrawArrays(GL_TRIANGLES, modelJob->StartIndex, modelJob->EndIndex - modelJob->StartIndex + 1);
continue; continue;
@@ -555,7 +555,8 @@ void Renderer::ForwardRendering(RenderQueue &rq)
/* /*
Final pass Final pass
*/ */
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, m_Width, m_Height); glViewport(0, 0, m_Width, m_Height);
glScissor(0, 0, m_Width, m_Height); glScissor(0, 0, m_Width, m_Height);
@@ -571,7 +572,9 @@ void Renderer::ForwardRendering(RenderQueue &rq)
//glUniform1f(glGetUniformLocation(ShaderProgramHandle, "Gamma"), Gamma); //glUniform1f(glGetUniformLocation(ShaderProgramHandle, "Gamma"), Gamma);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture); glBindTexture(GL_TEXTURE_2D, m_fFinalDiffuseTexture);
// glActiveTexture(GL_TEXTURE1);
// glBindTexture(GL_TEXTURE_2D, m_fLightingTexture);
glCullFace(GL_BACK); glCullFace(GL_BACK);
glBindVertexArray(m_ScreenQuad); glBindVertexArray(m_ScreenQuad);
@@ -947,7 +950,7 @@ void Renderer::FrameBufferTextures()
//Generate and bind diffuse texture //Generate and bind diffuse texture
glGenTextures(1, &m_fDiffuseTexture); glGenTextures(1, &m_fDiffuseTexture);
glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture); glBindTexture(GL_TEXTURE_2D, m_fDiffuseTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
@@ -999,6 +1002,9 @@ void Renderer::FrameBufferTextures()
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_TEXTURE_2D, m_fSpecularTexture, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_TEXTURE_2D, m_fSpecularTexture, 0);
//glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_TEXTURE_2D, m_fShadowTexture, 0); //glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, GL_TEXTURE_2D, m_fShadowTexture, 0);
GLenum FirstPass[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 };
glDrawBuffers(4, FirstPass);
GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER); GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(fbStatus != GL_FRAMEBUFFER_COMPLETE) if(fbStatus != GL_FRAMEBUFFER_COMPLETE)
{ {
@@ -1006,12 +1012,37 @@ void Renderer::FrameBufferTextures()
//exit(1); //exit(1);
} }
m_fbFinalPass = 0;
glGenFramebuffers(1, &m_fbFinalPass);
glGenTextures(1, &m_fFinalDiffuseTexture);
glBindTexture(GL_TEXTURE_2D, m_fFinalDiffuseTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glBindFramebuffer(GL_FRAMEBUFFER, m_fbFinalPass);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_fFinalDiffuseTexture, 0);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_fDepthBuffer);
GLenum FinalPassAttachments[] = { GL_COLOR_ATTACHMENT0 };
glDrawBuffers(1, FinalPassAttachments);
fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(fbStatus != GL_FRAMEBUFFER_COMPLETE)
{
LOG_ERROR("DeferredLighting:Init: m_fbLightingPass incomplete: 0x%x\n", fbStatus);
//exit(1);
}
m_fbLightingPass = 0; m_fbLightingPass = 0;
glGenFramebuffers(1, &m_fbLightingPass); glGenFramebuffers(1, &m_fbLightingPass);
glGenTextures(1, &m_fLightingTexture); glGenTextures(1, &m_fLightingTexture);
glBindTexture(GL_TEXTURE_2D, m_fLightingTexture); glBindTexture(GL_TEXTURE_2D, m_fLightingTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_Width, m_Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
@@ -1020,6 +1051,9 @@ void Renderer::FrameBufferTextures()
glBindFramebuffer(GL_FRAMEBUFFER, m_fbLightingPass); glBindFramebuffer(GL_FRAMEBUFFER, m_fbLightingPass);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_fLightingTexture, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_fLightingTexture, 0);
GLenum lightingPassAttachments[] = { GL_COLOR_ATTACHMENT0 };
glDrawBuffers(1, lightingPassAttachments);
fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER); fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(fbStatus != GL_FRAMEBUFFER_COMPLETE) if(fbStatus != GL_FRAMEBUFFER_COMPLETE)
{ {
@@ -1268,12 +1302,7 @@ void Renderer::DrawFBOScene(RenderQueue &rq)
void Renderer::DrawLightScene(RenderQueue &rq) void Renderer::DrawLightScene(RenderQueue &rq)
{ {
glEnable(GL_BLEND);
glBlendEquation (GL_FUNC_ADD);
glBlendFunc(GL_ONE,GL_ONE);
glDisable (GL_DEPTH_TEST);
glDepthMask (GL_FALSE);
glBindVertexArray(m_sphereModel->VAO); glBindVertexArray(m_sphereModel->VAO);
glm::mat4 cameraProjection = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height); glm::mat4 cameraProjection = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height);
@@ -1284,6 +1313,13 @@ void Renderer::DrawLightScene(RenderQueue &rq)
m_SecondPassProgram.Bind(); m_SecondPassProgram.Bind();
GLuint ShaderProgramHandle = m_SecondPassProgram.GetHandle(); GLuint ShaderProgramHandle = m_SecondPassProgram.GetHandle();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_fPositionTexture);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_fNormalsTexture);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, m_fSpecularTexture);
for (auto &light : Lights) for (auto &light : Lights)
{ {
MVP = cameraMatrix * light.SphereModelMatrix; MVP = cameraMatrix * light.SphereModelMatrix;
@@ -1306,21 +1342,10 @@ void Renderer::DrawLightScene(RenderQueue &rq)
glDrawArrays(GL_TRIANGLES, 0, m_sphereModel->Vertices.size()); glDrawArrays(GL_TRIANGLES, 0, m_sphereModel->Vertices.size());
}; };
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glDisable(GL_BLEND);
} }
void Renderer::DrawSunLightScene() void Renderer::DrawSunLightScene()
{ {
glCullFace(GL_BACK);
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_ONE,GL_ONE);
glDisable (GL_DEPTH_TEST);
glDepthMask (GL_FALSE);
//glBindVertexArray(m_sphereModel->VAO); //glBindVertexArray(m_sphereModel->VAO);
glm::mat4 cameraProjection = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height); glm::mat4 cameraProjection = m_Camera->ProjectionMatrix((float)m_Viewport.Width / m_Viewport.Height);
@@ -1330,6 +1355,12 @@ void Renderer::DrawSunLightScene()
m_SunPassProgram.Bind(); m_SunPassProgram.Bind();
GLuint ShaderProgramHandle = m_SunPassProgram.GetHandle(); GLuint ShaderProgramHandle = m_SunPassProgram.GetHandle();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, m_fPositionTexture);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_fNormalsTexture);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, m_fSpecularTexture);
glUniform2fv(glGetUniformLocation(ShaderProgramHandle, "ViewportSize"), 1, glm::value_ptr(glm::vec2(m_Width, m_Height))); glUniform2fv(glGetUniformLocation(ShaderProgramHandle, "ViewportSize"), 1, glm::value_ptr(glm::vec2(m_Width, m_Height)));
glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP)); glUniformMatrix4fv(glGetUniformLocation(ShaderProgramHandle, "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
@@ -1341,10 +1372,6 @@ void Renderer::DrawSunLightScene()
glBindVertexArray(m_ScreenQuad); glBindVertexArray(m_ScreenQuad);
glEnableVertexAttribArray(0); glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 6); glDrawArrays(GL_TRIANGLES, 0, 6);
glEnable (GL_DEPTH_TEST);
glDepthMask (GL_TRUE);
glDisable (GL_BLEND);
} }
void Renderer::SetSphereModel( Model* _model ) void Renderer::SetSphereModel( Model* _model )
+4
View File
@@ -167,6 +167,10 @@ private:
GLuint m_ShadowFrameBuffer; GLuint m_ShadowFrameBuffer;
GLuint m_ShadowDepthTexture; GLuint m_ShadowDepthTexture;
GLuint m_fbFinalPass;
GLuint m_fFinalDiffuseTexture;
GLuint m_fbBasePass; GLuint m_fbBasePass;
GLuint m_fDiffuseTexture; GLuint m_fDiffuseTexture;
GLuint m_fPositionTexture; GLuint m_fPositionTexture;
+1 -2
View File
@@ -1,6 +1,5 @@
#version 430 #version 430
//uniform vec3 La;
layout (binding=0) uniform sampler2D DiffuseTexture; layout (binding=0) uniform sampler2D DiffuseTexture;
@@ -15,11 +14,11 @@ out vec4 FragmentColor;
void main() void main()
{ {
vec4 DiffuseTexel = texture(DiffuseTexture, Input.TextureCoord); vec4 DiffuseTexel = texture(DiffuseTexture, Input.TextureCoord);
//vec4 LightingTexel = texture(LightingTexture, Input.TextureCoord);
//FragmentColor = LightingTexel + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0); //FragmentColor = LightingTexel + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0);
//FragmentColor = DiffuseTexel; //FragmentColor = DiffuseTexel;
FragmentColor = DiffuseTexel; FragmentColor = DiffuseTexel;
//FragmentColor = DiffuseTexel * (vec4(La, 0.0) + vec4(LightingTexel.rgb, 0.0)) + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0);
//FragmentColor = vec4(pow(_FragmentColor.rgb, vec3(1.0 / Gamma)), _FragmentColor.a); //FragmentColor = vec4(pow(_FragmentColor.rgb, vec3(1.0 / Gamma)), _FragmentColor.a);
} }
+8 -3
View File
@@ -1,7 +1,7 @@
#version 430 #version 430
//Dicksdickdickdickssssss
uniform vec3 La; uniform vec3 La;
uniform float Gamma;
layout (binding=0) uniform sampler2D DiffuseTexture; layout (binding=0) uniform sampler2D DiffuseTexture;
layout (binding=1) uniform sampler2D LightingTexture; layout (binding=1) uniform sampler2D LightingTexture;
@@ -12,7 +12,7 @@ in VertexData
vec2 TextureCoord; vec2 TextureCoord;
} Input; } Input;
out vec4 FragmentColor; out vec4 frag_Diffuse;
void main() void main()
{ {
@@ -21,7 +21,12 @@ void main()
//FragmentColor = LightingTexel + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0); //FragmentColor = LightingTexel + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0);
//FragmentColor = DiffuseTexel; //FragmentColor = DiffuseTexel;
//FragmentColor = DiffuseTexel;
//frag_Diffuse = vec4(LightingTexel.rgb, 0.0);
//frag_Diffuse = DiffuseTexel * ((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 = LightingTexel;
FragmentColor = DiffuseTexel * (vec4(La, 0.0) + vec4(LightingTexel.rgb, 0.0)) + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0);
//FragmentColor = vec4(pow(_FragmentColor.rgb, vec3(1.0 / Gamma)), _FragmentColor.a); //FragmentColor = vec4(pow(_FragmentColor.rgb, vec3(1.0 / Gamma)), _FragmentColor.a);
} }
+41 -1
View File
@@ -1,8 +1,23 @@
#version 430 #version 430
uniform vec4 Color; uniform vec4 Color;
uniform vec3 La;
uniform vec3 directionToSun;
uniform mat4 V;
layout(binding=0) uniform sampler2D texture0; layout(binding=0) uniform sampler2D texture0;
layout(binding=1) uniform sampler2D PositionTexture;
layout(binding=2) uniform sampler2D NormalsTexture;
layout(binding=3) uniform sampler2D SpecularTexture;
const vec3 ks = vec3(1.0, 1.0, 1.0);
const vec3 kd = vec3(1.0, 1.0, 1.0);
const vec3 ka = vec3(1.0, 1.0, 1.0);
const float kshine = 1.0;
const vec3 SunDiffuseLight = vec3(1.0, 1.0, 1.0);
const vec3 SunSpecularLight = vec3(1.0, 1.0, 1.0);
const vec3 SunPos = directionToSun*vec3(100);
const float specularExponent = 100;
in VertexData { in VertexData {
vec3 Position; vec3 Position;
@@ -12,9 +27,34 @@ in VertexData {
out vec4 frag_Diffuse; out vec4 frag_Diffuse;
vec4 phong(vec3 position, vec3 normal, vec3 specular)
{
//Diffuse Sunlight
vec3 directionToLight = normalize(vec3(V * vec4(directionToSun, 0.0)));
float dotProdLight = dot(directionToLight, normal);
dotProdLight = max(dotProdLight, 0.0);
vec3 sId = kd * SunDiffuseLight * dotProdLight;
//Specular Sunlight
vec3 surfaceToViewer = normalize(-position);
vec3 halfWay = normalize(surfaceToViewer + directionToLight);
float dotSpecular = max(dot(halfWay, normal), 0.0);
float specularFactorSun = pow(dotSpecular, specularExponent);
vec3 sIs = specular.r * SunSpecularLight * specularFactorSun;
return vec4((sId), sIs.r);
}
void main() { void main() {
// Texture
vec4 texel = texture(texture0, Input.TextureCoord); vec4 texel = texture(texture0, Input.TextureCoord);
vec4 PositionTexel = texture(PositionTexture, Input.TextureCoord);
vec4 NormalTexel = texture(NormalsTexture, Input.TextureCoord);
vec4 SpecularTexel = texture(SpecularTexture, Input.TextureCoord);
frag_Diffuse = texel * Color; frag_Diffuse = texel * Color;
//frag_Diffuse = texel * Color * (vec4(La, 0.0) * phong(vec3(PositionTexel), vec3(NormalTexel), vec3(SpecularTexel)));
//frag_Diffuse = DiffuseTexel * (vec4(La, 0.0) * (vec4(LightingTexel.rgb, 0.0) + vec4(LightingTexel.a, LightingTexel.a, LightingTexel.a, 0.0)));
} }
+5 -2
View File
@@ -24,6 +24,7 @@ const vec3 ks = vec3(1.0, 1.0, 1.0);
const vec3 kd = vec3(1.0, 1.0, 1.0); const vec3 kd = vec3(1.0, 1.0, 1.0);
const vec3 ka = vec3(1.0, 1.0, 1.0); const vec3 ka = vec3(1.0, 1.0, 1.0);
const float kshine = 1.0; const float kshine = 1.0;
const vec3 La = vec3(0.3, 0.3, 0.3);
in VertexData in VertexData
@@ -32,7 +33,7 @@ in VertexData
vec2 TextureCoord; vec2 TextureCoord;
} Input; } Input;
out vec4 FragColor; out vec4 frag_Light;
vec4 phong(vec3 position, vec3 normal, vec3 specular) vec4 phong(vec3 position, vec3 normal, vec3 specular)
{ {
@@ -67,6 +68,8 @@ void main()
vec4 NormalTexel = texture(NormalsTexture, TextureCoord); vec4 NormalTexel = texture(NormalsTexture, TextureCoord);
vec4 SpecularTexel = texture(SpecularTexture, TextureCoord); vec4 SpecularTexel = texture(SpecularTexture, TextureCoord);
FragColor = phong(vec3(PositionTexel), vec3(NormalTexel), vec3(SpecularTexel)); frag_Light = phong(vec3(PositionTexel), vec3(NormalTexel), vec3(SpecularTexel));
//FragColor = DiffuseTexel * vec4(1.0/La, 0.0) * (vec4(La, 0.0) + vec4(LightTexel.rgb, 0.0) + vec4(LightTexel.a, LightTexel.a, LightTexel.a, 0.0));
//FragColor = DiffuseTexel * (vec4(La, 0.0) + vec4(LightTexel.rgb, 0.0)) + vec4(LightTexel.a, LightTexel.a, LightTexel.a, 0.0);
//FragColor = NormalTexel; //FragColor = NormalTexel;
} }
+10 -5
View File
@@ -4,6 +4,7 @@ layout (binding=0) uniform sampler2D PositionTexture;
layout (binding=1) uniform sampler2D NormalsTexture; layout (binding=1) uniform sampler2D NormalsTexture;
layout (binding=2) uniform sampler2D SpecularTexture; layout (binding=2) uniform sampler2D SpecularTexture;
uniform vec2 ViewportSize; uniform vec2 ViewportSize;
uniform mat4 MVP; uniform mat4 MVP;
uniform mat4 M; uniform mat4 M;
@@ -16,10 +17,12 @@ const vec3 ks = vec3(1.0, 1.0, 1.0);
const vec3 kd = vec3(1.0, 1.0, 1.0); const vec3 kd = vec3(1.0, 1.0, 1.0);
const vec3 ka = vec3(1.0, 1.0, 1.0); const vec3 ka = vec3(1.0, 1.0, 1.0);
const float kshine = 1.0; const float kshine = 1.0;
const vec3 SunDiffuseLight = vec3(0.3, 0.3, 0.3); const vec3 SunDiffuseLight = vec3(1.0, 1.0, 1.0);
const vec3 SunSpecularLight = vec3(1.0, 1.0, 1.0); const vec3 SunSpecularLight = vec3(1.0, 1.0, 1.0);
const vec3 SunPos = directionToSun*vec3(100); const vec3 SunPos = directionToSun*vec3(100);
const float specularExponent = 5; const float specularExponent = 100;
const vec3 La = vec3(0.3, 0.3, 0.3);
in VertexData in VertexData
@@ -28,7 +31,7 @@ in VertexData
vec2 TextureCoord; vec2 TextureCoord;
} Input; } Input;
out vec4 FragColor; out vec4 frag_Light;
vec4 phong(vec3 position, vec3 normal, vec3 specular) vec4 phong(vec3 position, vec3 normal, vec3 specular)
{ {
@@ -46,7 +49,7 @@ vec4 phong(vec3 position, vec3 normal, vec3 specular)
float specularFactorSun = pow(dotSpecular, specularExponent); float specularFactorSun = pow(dotSpecular, specularExponent);
vec3 sIs = specular.r * SunSpecularLight * specularFactorSun; vec3 sIs = specular.r * SunSpecularLight * specularFactorSun;
return vec4((sId), sIs.r); return vec4((sId + La), sIs.r);
} }
void main() void main()
@@ -56,6 +59,8 @@ void main()
vec4 NormalTexel = texture(NormalsTexture, TextureCoord); vec4 NormalTexel = texture(NormalsTexture, TextureCoord);
vec4 SpecularTexel = texture(SpecularTexture, TextureCoord); vec4 SpecularTexel = texture(SpecularTexture, TextureCoord);
FragColor = phong(vec3(PositionTexel), vec3(normalize(NormalTexel)), vec3(SpecularTexel));
frag_Light = phong(vec3(PositionTexel), vec3(NormalTexel), vec3(SpecularTexel));
//FragColor = DiffuseTexel * (vec4(La, 0.0) * (vec4(LightTexel.rgb, 0.0) + vec4(LightTexel.a, LightTexel.a, LightTexel.a, 0.0)));
//FragColor = NormalTexel; //FragColor = NormalTexel;
} }
-1
View File
@@ -60,7 +60,6 @@ void Systems::SoundSystem::Update(double dt)
} }
//LOG_INFO("Antal emitters i listan: %i", m_Channels.size()); //LOG_INFO("Antal emitters i listan: %i", m_Channels.size());
std::map<EntityID, FMOD_CHANNEL*>::iterator it;
for(it = m_Channels.begin(); it != m_Channels.end();) for(it = m_Channels.begin(); it != m_Channels.end();)
{ {
FMOD_BOOL isPlaying = false; FMOD_BOOL isPlaying = false;