Fixed forward rendering for transparensy

This commit is contained in:
Tleety
2014-05-25 01:52:57 +02:00
parent a9f2911e41
commit e3aab96a75
7 changed files with 115 additions and 10 deletions
+9 -9
View File
@@ -33,7 +33,7 @@ void GameWorld::Initialize()
CommitEntity(ground);
}
for(int i = 0; i < 50; i++)
for(int i = 0; i < 500; i++)
{
auto Light = CreateEntity();
auto transform = AddComponent<Components::Transform>(Light, "Transform");
@@ -92,8 +92,8 @@ void GameWorld::Initialize()
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
transform->Position = glm::vec3(1.4f, 0.5546f - 0.6577f - 0.2, -0.9242f);
transform->Scale = glm::vec3(1.0f);
//auto model = AddComponent<Components::Model>(wheel, "Model");
//model->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj";
auto model = AddComponent<Components::Model>(wheel, "Model");
model->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f, 0.f);
Wheel->AxleID = 0;
@@ -112,8 +112,8 @@ void GameWorld::Initialize()
transform->Position = glm::vec3(-1.4f, 0.5546f - 0.6577f - 0.2, -0.9242f);
transform->Scale = glm::vec3(1.0f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 0, 1));
//auto model = AddComponent<Components::Model>(wheel, "Model");
//model->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj";
auto model = AddComponent<Components::Model>(wheel, "Model");
model->ModelFile = "Models/Jeep/WheelFront/wheelFront.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f, 0.f);
Wheel->AxleID = 0;
@@ -130,8 +130,8 @@ void GameWorld::Initialize()
auto wheel = CreateEntity(jeep);
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
transform->Position = glm::vec3(0.2726f, 0.2805f - 0.6577f, 1.9307f);
//auto model = AddComponent<Components::Model>(wheel, "Model");
//model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj";
auto model = AddComponent<Components::Model>(wheel, "Model");
model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f, 0.f);
Wheel->AxleID = 1;
@@ -148,8 +148,8 @@ void GameWorld::Initialize()
auto transform = AddComponent<Components::Transform>(wheel, "Transform");
transform->Position = glm::vec3(-0.2726f, 0.2805f - 0.6577f, 1.9307f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 0, 1));
//auto model = AddComponent<Components::Model>(wheel, "Model");
//model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj";
auto model = AddComponent<Components::Model>(wheel, "Model");
model->ModelFile = "Models/Jeep/WheelBack/wheelBack.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel, "Wheel");
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, 1.f, 0.f);
Wheel->AxleID = 1;
+52 -1
View File
@@ -111,6 +111,11 @@ void Renderer::LoadContent()
m_ShaderProgramSkybox.Compile();
m_ShaderProgramSkybox.Link();*/
m_ForwardRendering.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/ForwardRendering.vert.glsl")));
m_ForwardRendering.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/ForwardRendering.frag.glsl")));
m_ForwardRendering.Compile();
m_ForwardRendering.Link();
m_ShaderProgramShadows.AddShader(std::shared_ptr<Shader>(new VertexShader("Shaders/ShadowMap.vert.glsl")));
m_ShaderProgramShadows.AddShader(std::shared_ptr<Shader>(new FragmentShader("Shaders/ShadowMap.frag.glsl")));
m_ShaderProgramShadows.Compile();
@@ -711,6 +716,11 @@ void Renderer::DrawFBO()
glDrawArrays(GL_TRIANGLES, 0, 6);
}
void Renderer::DrawFBO2()
{
ForwardRendering();
}
void Renderer::DrawFBOScene()
{
// glEnable(GL_DEPTH_TEST);//Tests where objects are and display them correctly
@@ -734,7 +744,6 @@ void Renderer::DrawFBOScene()
glm::vec3 sunDirection = m_SunTarget - m_SunPosition;
glm::vec3 sunDirection_cameraview = glm::vec3(m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix() * glm::vec4(sunDirection, 1.0));
//Proj * view * vector
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_ShadowDepthTexture);
@@ -868,3 +877,45 @@ void Renderer::UpdateSunProjection()
//Pass the bounding box's extents to glOrtho or similar to set up the orthographic projection matrix for the shadow map.
}
void Renderer::ForwardRendering()
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, WIDTH, HEIGHT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.0f, 0.5f, 0.0f, 1.0f);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
glm::mat4 MVP;
m_ForwardRendering.Bind();
for (auto tuple : ModelsToRender) //// Todo: Add so it's TransparentModelsToRender
{
Model* model;
glm::mat4 modelMatrix;
bool visible;
std::tie(model, modelMatrix, visible, std::ignore) = tuple;
if (!visible)
continue;
MVP = cameraMatrix * modelMatrix;
glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "M"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "V"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
glUniformMatrix4fv(glGetUniformLocation(m_ForwardRendering.GetHandle(), "P"), 1, GL_FALSE, glm::value_ptr(m_Camera->ProjectionMatrix()));
glBindVertexArray(model->VAO);
for (auto texGroup : model->TextureGroups)
{
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, *texGroup.Texture);
glDrawArrays(GL_TRIANGLES, texGroup.StartIndex, texGroup.EndIndex - texGroup.StartIndex + 1);
}
}
}
+3
View File
@@ -127,6 +127,7 @@ private:
ShaderProgram m_SecondPassProgram;
ShaderProgram m_SecondPassProgram_Debug;
ShaderProgram m_FinalPassProgram;
ShaderProgram m_ForwardRendering;
ShaderProgram m_ShaderProgramNormals;
ShaderProgram m_ShaderProgramShadows;
@@ -143,12 +144,14 @@ private:
void CreateShadowMap(int resolution);
void FrameBufferTextures();
void DrawFBO();
void DrawFBO2();
void DrawFBOScene();
void DrawLightScene();
void BindFragDataLocation();
glm::mat4 CreateLightMatrix(Light &_light);
void UpdateSunProjection();
void CreateNormalMapTangent();
void ForwardRendering();
GLuint CreateQuad();
+18
View File
@@ -0,0 +1,18 @@
#version 430
layout(binding=0) uniform sampler2D texture0;
in VertexData {
vec3 Position;
vec3 Normal;
vec2 TextureCoord;
} Input;
out vec4 fragmentColor;
void main() {
// Texture
vec4 texel = texture(texture0, Input.TextureCoord);
fragmentColor = texel;
}
+25
View File
@@ -0,0 +1,25 @@
#version 430
uniform mat4 MVP;
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
layout (location = 0) in vec3 Position;
layout (location = 1) in vec3 Normal;
layout (location = 2) in vec2 TextureCoord;
out VertexData {
vec3 Position;
vec3 Normal;
vec2 TextureCoord;
} Output;
void main()
{
gl_Position = MVP * vec4(Position, 1.0);
Output.Position = Position;
Output.Normal = Normal;
Output.TextureCoord = TextureCoord;
}
+2
View File
@@ -169,6 +169,8 @@
<None Include="..\..\src\Shaders\AABB.frag.glsl" />
<None Include="..\..\src\Shaders\FinalPass.frag.glsl" />
<None Include="..\..\src\Shaders\FinalPass.vert.glsl" />
<None Include="..\..\src\Shaders\ForwardRendering.frag.glsl" />
<None Include="..\..\src\Shaders\ForwardRendering.vert.glsl" />
<None Include="..\..\src\Shaders\Fragment.glsl" />
<None Include="..\..\src\Shaders\Fragment2-Debug.glsl" />
<None Include="..\..\src\Shaders\Fragment2.glsl" />
@@ -277,5 +277,11 @@
<None Include="..\..\src\Shaders\FinalPass.frag.glsl">
<Filter>Shaders</Filter>
</None>
<None Include="..\..\src\Shaders\ForwardRendering.frag.glsl">
<Filter>Shaders</Filter>
</None>
<None Include="..\..\src\Shaders\ForwardRendering.vert.glsl">
<Filter>Shaders</Filter>
</None>
</ItemGroup>
</Project>