Put some code in a function.

This commit is contained in:
Faerbit 2014-12-05 00:57:17 +01:00
parent 7710520c52
commit 76fd5ade92

View File

@ -68,6 +68,12 @@ float sampleShadow(sampler2DShadow shadowMap, vec4 shadowCoord) {
return visibility; return visibility;
} }
float distanceToBorder(vec2 vector) {
float xDistance = min(vector.x, 1.0-vector.x);
float yDistance = min(vector.y, 1.0-vector.y);
return min(xDistance, yDistance);
}
void main() void main()
{ {
vec3 ambientColor = ambientFactor * ambientColor; vec3 ambientColor = ambientFactor * ambientColor;
@ -102,12 +108,8 @@ void main()
// shadows // shadows
float visibility = 1.0; float visibility = 1.0;
if ((shadowCoord_far.x > 0.0 && shadowCoord_far.x < 1.0) && if (distanceToBorder(shadowCoord_middle.xy) <= 0.5 && distanceToBorder(shadowCoord_middle.xy) > 0.0) {
(shadowCoord_far.y > 0.0 && shadowCoord_far.y < 1.0)) { if (distanceToBorder(shadowCoord_near.xy) <= 0.5 && distanceToBorder(shadowCoord_near.xy) > 0.0) {
if ((shadowCoord_middle.x > 0.0 && shadowCoord_middle.x < 1.0) &&
(shadowCoord_middle.y > 0.0 && shadowCoord_middle.y < 1.0)) {
if ((shadowCoord_near.x > 0.0 && shadowCoord_near.x < 1.0) &&
(shadowCoord_near.y > 0.0 && shadowCoord_near.y < 1.0)) {
visibility = sampleShadow(shadowMap_near, shadowCoord_near); visibility = sampleShadow(shadowMap_near, shadowCoord_near);
} }
else { else {
@ -117,7 +119,6 @@ void main()
else { else {
visibility = sampleShadow(shadowMap_far, shadowCoord_far); visibility = sampleShadow(shadowMap_far, shadowCoord_far);
} }
}
specularColor *= visibility; specularColor *= visibility;
diffuseColor *= visibility; diffuseColor *= visibility;