lab 9 shifted shades
This commit is contained in:
parent
60c53663a1
commit
6af9e40fd7
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
float AMBIENT = 0.03;
|
float AMBIENT = 0.03;
|
||||||
float PI = 3.14;
|
float PI = 3.14;
|
||||||
|
float shadowBias = 0.0;
|
||||||
|
|
||||||
uniform sampler2D depthMap;
|
uniform sampler2D depthMap;
|
||||||
|
|
||||||
@ -42,11 +43,11 @@ in vec3 test;
|
|||||||
float calculateShadow() {
|
float calculateShadow() {
|
||||||
vec4 sunSpacePosU = sunSpacePos / sunSpacePos.w;
|
vec4 sunSpacePosU = sunSpacePos / sunSpacePos.w;
|
||||||
vec4 sunSpacePosNormalized = sunSpacePosU * 0.5 + 0.5;
|
vec4 sunSpacePosNormalized = sunSpacePosU * 0.5 + 0.5;
|
||||||
float closestDepth = texture2D(depthMap, worldPos.xy).r;
|
float closestDepth = texture2D(depthMap, sunSpacePosNormalized.xy).r;
|
||||||
if (closestDepth > sunSpacePosNormalized.z) {
|
if (closestDepth + shadowBias > sunSpacePosNormalized.z) {
|
||||||
return 1;
|
return 1.0;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
float DistributionGGX(vec3 normal, vec3 H, float roughness){
|
float DistributionGGX(vec3 normal, vec3 H, float roughness){
|
||||||
|
@ -182,9 +182,14 @@ void renderShadowapSun() {
|
|||||||
glUseProgram(programDepth);
|
glUseProgram(programDepth);
|
||||||
|
|
||||||
//viewProjection matrix
|
//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
|
//draw
|
||||||
|
//lamp
|
||||||
|
drawObjectDepth(sphereContext,
|
||||||
|
glm::translate(pointlightPos) * glm::scale(glm::vec3(0.1)),
|
||||||
|
lightVP);
|
||||||
|
|
||||||
drawObjectDepth(sphereContext,
|
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)),
|
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);
|
lightVP);
|
||||||
@ -220,7 +225,6 @@ void renderShadowapSun() {
|
|||||||
lightVP
|
lightVP
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
glViewport(0, 0, WIDTH, HEIGHT);
|
glViewport(0, 0, WIDTH, HEIGHT);
|
||||||
}
|
}
|
||||||
@ -231,7 +235,9 @@ void renderScene(GLFWwindow* window)
|
|||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
float time = glfwGetTime();
|
float time = glfwGetTime();
|
||||||
updateDeltaTime(time);
|
updateDeltaTime(time);
|
||||||
|
glCullFace(GL_FRONT);
|
||||||
renderShadowapSun();
|
renderShadowapSun();
|
||||||
|
glCullFace(GL_BACK); // don't forget to reset original culling face
|
||||||
|
|
||||||
//space lamp
|
//space lamp
|
||||||
glUseProgram(programSun);
|
glUseProgram(programSun);
|
||||||
@ -342,6 +348,7 @@ void init(GLFWwindow* window)
|
|||||||
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
|
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
program = shaderLoader.CreateProgram("shaders/shader_9_1.vert", "shaders/shader_9_1.frag");
|
program = shaderLoader.CreateProgram("shaders/shader_9_1.vert", "shaders/shader_9_1.frag");
|
||||||
programTest = shaderLoader.CreateProgram("shaders/test.vert", "shaders/test.frag");
|
programTest = shaderLoader.CreateProgram("shaders/test.vert", "shaders/test.frag");
|
||||||
programSun = shaderLoader.CreateProgram("shaders/shader_8_sun.vert", "shaders/shader_8_sun.frag");
|
programSun = shaderLoader.CreateProgram("shaders/shader_8_sun.vert", "shaders/shader_8_sun.frag");
|
||||||
|
Loading…
Reference in New Issue
Block a user