@@ -63,7 +63,7 @@ float lightZenith = 45.f;
|
|
63
63
|
float lightDistance = 55.f;
|
64
64
|
bool animateLight = false;
|
65
65
|
vec3 point_light_color = vec3(1.f, 1.f, 1.f);
|
66
|
-
bool useSpotLight =
|
66
|
+
bool useSpotLight = true;
|
67
67
|
float innerSpotlightAngle = 17.5f;
|
68
68
|
float outerSpotlightAngle = 22.5f;
|
69
69
|
float point_light_intensity_multiplier = 10000.0f;
|
@@ -280,6 +280,9 @@ void drawScene(GLuint currentShaderProgram,
|
|
280
280
|
normalize(vec3(viewMatrix * vec4(-lightPosition, 0.0f))));
|
281
281
|
labhelper::setUniformSlow(currentShaderProgram, "spotOuterAngle", std::cos(radians(outerSpotlightAngle)));
|
282
282
|
|
283
|
+
labhelper::setUniformSlow(currentShaderProgram, "useSpotLight", useSpotLight ? 1 : 0);
|
284
|
+
labhelper::setUniformSlow(currentShaderProgram, "useSoftFalloff", useSoftFalloff ? 1 : 0);
|
285
|
+
labhelper::setUniformSlow(currentShaderProgram, "spotInnerAngle", std::cos(radians(innerSpotlightAngle)));
|
283
286
|
|
284
287
|
glActiveTexture(GL_TEXTURE10);
|
285
288
|
glBindTexture(GL_TEXTURE_2D, shadowMapFB.depthBuffer);
|
@@ -142,6 +142,25 @@ void main()
|
|
142
142
|
float depth = texture(shadowMapTex, shadowMapCoord.xy / shadowMapCoord.w).r;
|
143
143
|
visibility = (depth >= (shadowMapCoord.z / shadowMapCoord.w)) ? 1.0 : 0.0;
|
144
144
|
#endif // ~ USE_BUILTIN_SHADOW_TEST
|
145
|
+
attenuation = 1.0;
|
146
|
+
if(useSpotLight == 1)
|
147
|
+
{
|
148
|
+
vec3 posToLight = normalize(viewSpaceLightPosition - viewSpacePosition);
|
149
|
+
float cosAngle = dot(posToLight, -viewSpaceLightDir);
|
150
|
+
|
151
|
+
if(useSoftFalloff == 0)
|
152
|
+
{
|
153
|
+
// Spotlight with hard border:
|
154
|
+
attenuation = (cosAngle > spotOuterAngle) ? 1.0 : 0.0;
|
155
|
+
}
|
156
|
+
else
|
157
|
+
{
|
158
|
+
// Spotlight with soft border:
|
159
|
+
attenuation = smoothstep(spotOuterAngle, spotInnerAngle, cosAngle);
|
160
|
+
}
|
161
|
+
|
162
|
+
visibility *= attenuation;
|
163
|
+
}
|
145
164
|
|
146
165
|
vec3 wo = -normalize(viewSpacePosition);
|
147
166
|
vec3 n = normalize(viewSpaceNormal);
|