More awesome shadows
This commit is contained in:
@@ -16,7 +16,7 @@ Renderer::Renderer()
|
|||||||
m_ShadowMapRes = 2048*2;
|
m_ShadowMapRes = 2048*2;
|
||||||
m_SunPosition = glm::vec3(0, 0.3f, 10);
|
m_SunPosition = glm::vec3(0, 0.3f, 10);
|
||||||
m_SunTarget = glm::vec3(0, 0, 0);
|
m_SunTarget = glm::vec3(0, 0, 0);
|
||||||
m_SunProjection = glm::ortho<float>(-200, 200, -10, 100, -800, 400);
|
m_SunProjection = glm::ortho<float>(-200, 200, -10, 100, -800, 800);
|
||||||
Lights = 0;
|
Lights = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,14 +209,16 @@ void Renderer::DrawScene()
|
|||||||
glBindTexture(GL_TEXTURE_2D, m_ShadowDepthTexture);
|
glBindTexture(GL_TEXTURE_2D, m_ShadowDepthTexture);
|
||||||
//DrawModels(m_ShaderProgram);
|
//DrawModels(m_ShaderProgram);
|
||||||
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
|
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
|
||||||
|
glm::mat4 depthCameraMatrix = biasMatrix * depthCamera;
|
||||||
glm::mat4 MVP;
|
glm::mat4 MVP;
|
||||||
|
glm::mat4 depthMVP;
|
||||||
for (auto tuple : ModelsToRender)
|
for (auto tuple : ModelsToRender)
|
||||||
{
|
{
|
||||||
Model* model;
|
Model* model;
|
||||||
glm::mat4 modelMatrix;
|
glm::mat4 modelMatrix;
|
||||||
std::tie(model, modelMatrix) = tuple;
|
std::tie(model, modelMatrix) = tuple;
|
||||||
MVP = cameraMatrix * modelMatrix;
|
MVP = cameraMatrix * modelMatrix;
|
||||||
glm::mat4 depthMVP = biasMatrix * depthCamera * modelMatrix;
|
depthMVP = depthCameraMatrix * modelMatrix;
|
||||||
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthMVP));
|
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "DepthMVP"), 1, GL_FALSE, glm::value_ptr(depthMVP));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "model"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgram.GetHandle(), "model"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
||||||
@@ -243,7 +245,7 @@ void Renderer::DrawShadowMap()
|
|||||||
{
|
{
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
glCullFace(GL_BACK);
|
glCullFace(GL_FRONT);
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, m_ShadowFrameBuffer);
|
glBindFramebuffer(GL_FRAMEBUFFER, m_ShadowFrameBuffer);
|
||||||
glViewport(0, 0, m_ShadowMapRes, m_ShadowMapRes);
|
glViewport(0, 0, m_ShadowMapRes, m_ShadowMapRes);
|
||||||
|
|||||||
@@ -51,9 +51,9 @@ void main() {
|
|||||||
//bias = clamp(bias, 0.0, 0.01);
|
//bias = clamp(bias, 0.0, 0.01);
|
||||||
float visibility = 1.0;
|
float visibility = 1.0;
|
||||||
if (Input.ShadowCoord.x >= 0.0 && Input.ShadowCoord.x <= 1.0 && Input.ShadowCoord.y >= 0.0 && Input.ShadowCoord.y <= 1.0) {
|
if (Input.ShadowCoord.x >= 0.0 && Input.ShadowCoord.x <= 1.0 && Input.ShadowCoord.y >= 0.0 && Input.ShadowCoord.y <= 1.0) {
|
||||||
float bias = 0.003;
|
float bias = 0.0005;
|
||||||
vec4 shadowMapValue = texture(shadowMap, Input.ShadowCoord.xy);
|
vec4 shadowMapValue = texture(shadowMap, Input.ShadowCoord.xy);
|
||||||
if (shadowMapValue.z < Input.ShadowCoord.z - bias) {
|
if (shadowMapValue.z < clamp(Input.ShadowCoord.z - bias, 0, 1)) {
|
||||||
visibility = 0.5;
|
visibility = 0.5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user