Skip to content

Commit 70ddfc6

Browse files
author
CHAMPETIER CLEMENT
committed
TD3 - ex3
1 parent ad30a96 commit 70ddfc6

File tree

4 files changed

+39
-21
lines changed

4 files changed

+39
-21
lines changed

TD2/002/002_deferred.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ int main( int argc, char **argv )
606606
glBindFramebuffer(GL_FRAMEBUFFER, 0);
607607

608608
/////////////////////////////////////////////////////////////////
609-
// Compute all light and render the merge into the main window //
609+
// Compute all lights and render the merge into the main window //
610610
/////////////////////////////////////////////////////////////////
611611

612612
// Reset Viewport

TD3/003/003.cpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ int main( int argc, char **argv )
280280
GLuint lighting_lightColorLocation = glGetUniformLocation(lighting_shader.program, "LightColor");
281281
GLuint lighting_lightIntensityLocation = glGetUniformLocation(lighting_shader.program, "LightIntensity");
282282
GLuint lighting_shadowBiasLocation = glGetUniformLocation(lighting_shader.program, "ShadowBias");
283+
GLuint lighting_shadowSamplesLocation = glGetUniformLocation(lighting_shader.program, "ShadowSamples");
284+
GLuint lighting_shadowSpreadLocation = glGetUniformLocation(lighting_shader.program, "ShadowSpread");
285+
283286

284287

285288
/* --------------------------------------------------------------------------------------------- */
@@ -546,9 +549,6 @@ int main( int argc, char **argv )
546549

547550
// Compute light positions
548551
// TO DO : several lights, each sent to the shadow shader
549-
//for(unsigned int i = 0; i < numLights; ++i){
550-
//
551-
//}
552552
glm::vec3 lightPosition(5.f, 5.f, 5.f);
553553
glm::vec3 lightTarget(0.f, 0.f, 0.f);
554554
glm::vec3 lightUp(0.f, 1.f, 0.f);
@@ -573,14 +573,11 @@ int main( int argc, char **argv )
573573
// Unbind framebuffer
574574
glBindFramebuffer(GL_FRAMEBUFFER, 0);
575575

576-
577-
578576
/* --------------------------------------------------------------------------------------------- */
579577
/* ------------------------------ Remplissage du Shadow Frame Buffer --------------------------- */
580578
/* --------------------------------------------------------------------------------------------- */
581579

582580
glBindFramebuffer(GL_FRAMEBUFFER, gbufferFbo[1]);
583-
584581
// Viewport
585582
glViewport(0, 0, width, height);
586583

@@ -603,8 +600,6 @@ int main( int argc, char **argv )
603600
glDrawElementsInstanced(GL_TRIANGLES, cube_triangleCount * 3, GL_UNSIGNED_INT, (void*)0, 4);
604601
glBindVertexArray(vao[1]);
605602
glDrawElements(GL_TRIANGLES, plane_triangleCount * 3, GL_UNSIGNED_INT, (void*)0);
606-
607-
608603
glBindFramebuffer(GL_FRAMEBUFFER, 0);
609604

610605
/* --------------------------------------------------------------------------------------------- */
@@ -655,6 +650,8 @@ int main( int argc, char **argv )
655650
glUniform3fv(lighting_lightColorLocation, 1, lightColor);
656651
glUniform1f(lighting_lightIntensityLocation, lightIntensity);
657652
glUniform1f(lighting_shadowBiasLocation, shadowBias);
653+
glUniform1f(lighting_shadowSamplesLocation, shadowSamples);
654+
glUniform1f(lighting_shadowSpreadLocation, shadowSampleSpread);
658655

659656
// Draw quad
660657
glBindVertexArray(vao[2]);

TD3/003/light.glsl

+33-12
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ uniform mat4 InverseViewProjection;
3030
uniform mat4 LigthToShadowMap;
3131
uniform float Time;
3232
uniform float ShadowBias;
33+
uniform float ShadowSamples;
34+
uniform float ShadowSpread;
3335

3436
out vec4 Color;
3537

@@ -76,29 +78,48 @@ void main(void)
7678

7779
vec3 cspotlight1 = spotLight(LightColor, LightIntensity, LightDirection, LightPosition, n, position, diffuse, spec, CameraPosition );
7880

79-
//Color = vec4(cspotlight1, 1.0);
81+
// Poisson disk
82+
vec2 poissonDisk[16] = vec2[](
83+
vec2( -0.94201624, -0.39906216 ),
84+
vec2( 0.94558609, -0.76890725 ),
85+
vec2( -0.094184101, -0.92938870 ),
86+
vec2( 0.34495938, 0.29387760 ),
87+
vec2( -0.91588581, 0.45771432 ),
88+
vec2( -0.81544232, -0.87912464 ),
89+
vec2( -0.38277543, 0.27676845 ),
90+
vec2( 0.97484398, 0.75648379 ),
91+
vec2( 0.44323325, -0.97511554 ),
92+
vec2( 0.53742981, -0.47373420 ),
93+
vec2( -0.26496911, -0.41893023 ),
94+
vec2( 0.79197514, 0.19090188 ),
95+
vec2( -0.24188840, 0.99706507 ),
96+
vec2( -0.81409955, 0.91437590 ),
97+
vec2( 0.19984126, 0.78641367 ),
98+
vec2( 0.14383161, -0.14100790 )
99+
);
100+
101+
float visibility = 1.0;
102+
float visibilityOffset = 1.0 / ShadowSamples;
80103

81-
//Color = vec4(lightSpacePosition.z, 0, 0, 1);
82-
//Color = lightDepth;
83-
104+
for(int i = 0; i < 16; i++) {
105+
if(texture(ShadowMap, lightSpacePosition.xy + poissonDisk[i]/ShadowSpread).r + ShadowBias < lightSpacePosition.z) {
106+
visibility-=visibilityOffset;
107+
}
108+
}
109+
84110
Color = vec4(0, 0, 0, 0);
85111
if(lightSpacePosition.z < shadowPixel.x + ShadowBias) {
86-
if (wlightSpacePosition.w > 0.0 &&
112+
// En dehors du champs de la lumière
113+
if(wlightSpacePosition.w > 0.0 &&
87114
lightSpacePosition.x > 0.0 &&
88115
lightSpacePosition.x < 1.0 &&
89116
lightSpacePosition.y > 0.0 &&
90117
lightSpacePosition.y < 1.0 )
91118
{
92-
Color = vec4(cspotlight1, 1.0);
93-
}
94-
else{
95-
Color = vec4(1, 0, 0, 1);
119+
Color = vec4(cspotlight1 * visibility, 1.0);
96120
}
97121
}
98122

99-
100-
//Color = vec4(lightSpacePosition.z, 0, 0, 1) - lightDepth;
101-
102123
}
103124

104125
#endif

TD3/003d

260 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)