# Flickering spot light shadows in GLSL

Two years ago I made a labyrinth game for a class, and it worked perfectly. Now I need to use this game for other reasons, but the lightning is bugged.

I'm using GLSL because that's how I managed to make everything work back then. I'm using a spot light to generate shadows, in lieu of the sun, because a Sun wasn't generating shadows as I wanted. But I'm using a sphere of 20 Suns to simulate global illumination, because other means to do that weren't working back then.

I have a camera overlooking the labyrinth, and the shadows are correct there. I also have a first person camera, and that's where the problem is. I'm failing to put this problem into words, so I made a video:

https://youtu.be/iwVJ0AlqWtU

I've Googled and messed around a bit, but I found no solution. I found out that I could replace my spot light by a Sun, and the shadows even look better, but the bug remains exactly the same.

The necessary files are here:

https://github.com/GuiRitter/labyrinth-game-exercise

Is there a solution to this?

Update:

• I tested a bit further. I don't know if it can be seen in the video (terrible job at using OBS Studio), but the ground texture is also bugged, (not) moving like the shadows are. I've deleted all light sources and the problem remains (tested in two scenarios: #1 added Emit in Properties > Material > Shading to the ground texture; #2 added ambient lightning in Properties > World > Environment Lightning (didn't knew of this before or it didn't existed when I had to make that fake ambient lightning))..

• I've made a minimal version from scratch (nothing copied from the first one) and the bug remains.

• Also didn't work: deleting all cameras, creating a new camera, not scaling it, setting it's physics to No Collision, vertex parenting it to the player character (although that makes the camera not change orientation with the parent), positioning it such that it would not be inside another object. I positioned it above the labyrinth walls and deleted the sky to ensure the last one.

• Seeing the same result you have here. You have too many lamps, if different mixed types, with too many needlessly independent object data, with too wide radius, too far from the scene, too big shadowmap sizes, and too far apart clipping ranges. Your scene needs some serious cleanup and optimization. You also seem to have lamps illuminating your scene from under the floor, which seems quite pontless. May 12 '17 at 16:15
• @DuarteFarrajotaRamos see the update in the first post. May 15 '17 at 11:42
• @GuiRitter i have tested your file and try to fix it but seems corrupted somehow, so i suggest that try with a new blend. May 16 '17 at 17:51
• @Strapicarus I've made a minimal version from scratch (nothing copied from the first one) and the bug remains. I've uploaded it to the link I provided, inside the "minimum" folder. May 17 '17 at 12:35

You need set up only one sun lamp.

1. (Asuming all objects are deselect)RigthMouseButton to select the sun lamp and while pressing Shit + RigthMouseButton select your player:

2. While both selected press Ctrl + P and select Vertex:

1. select, deselect all pressing A.
2. Select the sun lamp RigthMouseButton.
3. in property > data, active the shadow and show shadow check box.

1. In Quality you can edit the shadow size (higher value more impact)
2. In Quality you can edit the 'Bias' value, set to 0.1 and then go up to see what happens :P.
3. In Clipping the clip end value define the distance, beyond which objects will no generate shadows

1. In Clipping the frustum size value define the box size

Note HIGHER VALUES MAY HAVE PERFORMACE IMPACT

EDIT

Then add a Hemi lamp and point it oposite to the sun lamp

The problem is with the camera.

I have reproduced the problem in 2 ways.

1. Positioning the camera closer or inside of an object with camera physics static
2. Positioning the camera inside of an object with camera physics no collision

Also found that your camera was tiny and the cylinder(character) too. take a look to the blender manual> render>camera

To solve it:

1.Delete the camera and add a new camera (and dont scale it)

2.Move the camera To Position (dont put it inside of an object.) Make sure that the camera physics are no collision.

1. Yo can change the size of the camera:

And then you can parent the camera to object, and the sun to the vertex object (better with vertex make parent in edition mode).

• See the update in the first post May 15 '17 at 11:43
• Your updated answer didn't work :'( (I updated the first post again) May 22 '17 at 12:54

Tilt the camera by 0.1 degrees up or down to fix the problem.

This is a bug since Blender 2.77, source: https://developer.blender.org/T48256