lab 9 shifted shades

This commit is contained in:
Eikthyrnir 2024-02-07 00:32:56 +01:00
parent 60c53663a1
commit 6af9e40fd7
2 changed files with 15 additions and 7 deletions

View File

@ -2,6 +2,7 @@
float AMBIENT = 0.03;
float PI = 3.14;
float shadowBias = 0.0;
uniform sampler2D depthMap;
@ -42,11 +43,11 @@ in vec3 test;
float calculateShadow() {
vec4 sunSpacePosU = sunSpacePos / sunSpacePos.w;
vec4 sunSpacePosNormalized = sunSpacePosU * 0.5 + 0.5;
float closestDepth = texture2D(depthMap, worldPos.xy).r;
if (closestDepth > sunSpacePosNormalized.z) {
return 1;
float closestDepth = texture2D(depthMap, sunSpacePosNormalized.xy).r;
if (closestDepth + shadowBias > sunSpacePosNormalized.z) {
return 1.0;
}
return 0;
return 0.0;
}
float DistributionGGX(vec3 normal, vec3 H, float roughness){

View File

@ -182,9 +182,14 @@ void renderShadowapSun() {
glUseProgram(programDepth);
//viewProjection matrix
glm::mat4 lightVP = glm::ortho(-3.f, 3.f, -3.f, 3.f, 1.f, 30.0f) * glm::lookAt(sunPos, sunPos - sunDir, glm::vec3(0, 1, 0));
glm::mat4 lightVP = glm::ortho(-2.9f, 2.2f, -1.1f, 2.7f, 1.f, 30.0f) * glm::lookAt(sunPos, sunPos - sunDir, glm::vec3(0, 1, 0));
//draw
//lamp
drawObjectDepth(sphereContext,
glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)),
lightVP);
drawObjectDepth(sphereContext,
glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)) * glm::eulerAngleY(time / 3) * glm::translate(glm::vec3(4.f, 0, 0)) * glm::scale(glm::vec3(0.3f)),
lightVP);
@ -220,7 +225,6 @@ void renderShadowapSun() {
lightVP
);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, WIDTH, HEIGHT);
}
@ -231,7 +235,9 @@ void renderScene(GLFWwindow* window)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
float time = glfwGetTime();
updateDeltaTime(time);
glCullFace(GL_FRONT);
renderShadowapSun();
glCullFace(GL_BACK); // don't forget to reset original culling face
//space lamp
glUseProgram(programSun);
@ -342,6 +348,7 @@ void init(GLFWwindow* window)
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glEnable(GL_DEPTH_TEST);
program = shaderLoader.CreateProgram("shaders/shader_9_1.vert", "shaders/shader_9_1.frag");
programTest = shaderLoader.CreateProgram("shaders/test.vert", "shaders/test.frag");
programSun = shaderLoader.CreateProgram("shaders/shader_8_sun.vert", "shaders/shader_8_sun.frag");