Small fixing up

This commit is contained in:
FakeShemp
2016-02-28 19:46:50 +01:00
parent 6dd7f1a657
commit 7749fc5474
3 changed files with 41 additions and 29 deletions
+8 -6
View File
@@ -211,19 +211,21 @@ float CalcShadowValue(vec4 light_space_pos, vec3 normal, vec3 light_dir, sampler
// Various bias methods.
//bias = max(0.05 * (1.0 - dot(normal, light_dir)), bias);
bias = bias * tan(acos(clamp(dot(normal, -light_dir), 0.0, 1.0)));
//bias = bias * tan(acos(clamp(dot(normal, -light_dir), 0.0, 1.0)));
bias = bias + bias * tan(acos(clamp(dot(normal, -light_dir), 0.0, 1.0)));
// Calculate coordinates in projection space.
vec3 projCoords = vec3(light_space_pos.xy, light_space_pos.z + bias) / light_space_pos.w;
projCoords = projCoords * 0.5 + 0.5;
//projCoords = (floor(projCoords * 255.0)) / 255.0;
// Various methods for shadow calculation in fastest to slowest order.
shadowMapDepth = PCFShadow(depth_texture_array, projCoords, layer_index);
//shadowMapDepth = PCFShadow(depth_texture_array, projCoords, layer_index);
//shadowMapDepth = PoissonShadow(depth_texture_array, projCoords, layer_index, 4, 25.0 * FarDistance[MAX_SPLITS - 1]);
//shadowMapDepth = PoissonDotShadow(depth_texture_array, projCoords, layer_index, 4, 25.0 * FarDistance[MAX_SPLITS]);
//shadowMapDepth = SoftwarePCF(depth_texture_array, projCoords, layer_index, bias);
//shadowMapDepth = PoissonDotShadow(depth_texture_array, projCoords, layer_index, 4, 25.0 * FarDistance[MAX_SPLITS - 1]);
shadowMapDepth = SoftwarePCF(depth_texture_array, projCoords, layer_index, bias);
return 1.0 - shadowMapDepth;
}
@@ -327,8 +329,8 @@ void main()
totalLighting.Specular += light_result.Specular;
}
totalLighting.Diffuse *= (1.0 + vec4(AmbientColor.rgba)) - vec4(vec3(shadowFactor), 0.0);
totalLighting.Specular *= (1.0 + vec4(AmbientColor.rgba)) - vec4(vec3(shadowFactor), 0.0);
totalLighting.Diffuse *= (1.5 + vec4(AmbientColor.rgba)) - vec4(vec3(shadowFactor), 0.0);
totalLighting.Specular *= (1.5 + vec4(AmbientColor.rgba)) - vec4(vec3(shadowFactor), 0.0);
//LightResult getInformation;
+1 -1
View File
@@ -2,7 +2,7 @@
#define ALPHA_CUTOFF 0.3
layout (binding = 12) uniform sampler2D DiffuseTexture;
layout (binding = 24) uniform sampler2D DiffuseTexture;
uniform float Alpha;
in VertexData{
+32 -22
View File
@@ -186,6 +186,8 @@ void ShadowPass::PointsToLightspace(Frustum& frustum, glm::mat4 v)
void ShadowPass::RadiusToLightspace(Frustum& frustum)
{
float quantizationStep = 1.0f / m_ResolutionSizeHeight;
float left = -frustum.Radius;
float right = frustum.Radius;
float bottom = -frustum.Radius;
@@ -219,6 +221,8 @@ void ShadowPass::Draw(RenderScene & scene)
m_LightView[i] = glm::lookAt(glm::vec3(-directionalLightJob->Direction) + m_shadowFrusta[i].MiddlePoint, m_shadowFrusta[i].MiddlePoint, glm::vec3(0.f, 1.f, 0.f));
PointsToLightspace(m_shadowFrusta[i], m_LightView[i]);
//FindRadius(m_shadowFrusta[i]);
//RadiusToLightspace(m_shadowFrusta[i]);
m_LightProjection[i] = glm::ortho(m_shadowFrusta[i].LRBT[LEFT], m_shadowFrusta[i].LRBT[RIGHT], m_shadowFrusta[i].LRBT[BOTTOM], m_shadowFrusta[i].LRBT[TOP], m_NearFarPlane[NEAR], m_NearFarPlane[FAR]);
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_LightProjection[i]));
@@ -227,37 +231,43 @@ void ShadowPass::Draw(RenderScene & scene)
GLERROR("ShadowLight ERROR");
for (auto &objectJob : scene.OpaqueObjects) {
auto modelJob = std::dynamic_pointer_cast<ModelJob>(objectJob);
if (!std::dynamic_pointer_cast<ExplosionEffectJob>(objectJob))
{
auto modelJob = std::dynamic_pointer_cast<ModelJob>(objectJob);
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int)));
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int)));
GLERROR("Shadow Draw ERROR");
GLERROR("Shadow Draw ERROR");
}
}
state->CullFace(GL_BACK);
for (auto &objectJob : scene.TransparentObjects) {
auto modelJob = std::dynamic_pointer_cast<ModelJob>(objectJob);
if (!std::dynamic_pointer_cast<ExplosionEffectJob>(objectJob))
{
auto modelJob = std::dynamic_pointer_cast<ModelJob>(objectJob);
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
glUniform1f(glGetUniformLocation(shaderHandle, "Alpha"), modelJob->Color.a);
glActiveTexture(GL_TEXTURE12);
if (modelJob->DiffuseTexture != nullptr) {
glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture->m_Texture);
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "M"), 1, GL_FALSE, glm::value_ptr(modelJob->Matrix));
glUniform1f(glGetUniformLocation(shaderHandle, "Alpha"), modelJob->Color.a);
glActiveTexture(GL_TEXTURE24);
if (modelJob->DiffuseTexture != nullptr) {
glBindTexture(GL_TEXTURE_2D, modelJob->DiffuseTexture->m_Texture);
}
else {
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
}
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int)));
GLERROR("Shadow Draw ERROR");
}
else {
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
}
glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int)));
GLERROR("Shadow Draw ERROR");
}
state->CullFace(GL_FRONT);
}