Lord Kv | 2014-05-06 12:37
Light shaft shader
72
points ]
 (8 votes)
Post FX that renders light shafts

Light shaft shader

This shader adds a flare-like effect for the sun which also casts light shafts. I learned about the method from this tutorial.

The way this shader works is like this. First, it detects which pixels are sky - this should be done using the z-buffer but because that is unavalible in Sauerbraten right now I instead detect sky using brightness. Second step is to apply radial blur originating from the sun's location. This is the most hardware intensive step. The third and final step is to blend the blurred sky over the original scene.

An important part of this effect is also a cubescript loop which calculates the sun's position on the screen and passes it to the shader. The calculation requires transforming the sun's angles to a vector, rotating the vector according to camera angles and projecting it to the screen. Huge thanks to my brother for explaining the math and making this part work for me.

Installation:

Copy lightshaft.cfg to your game directory and then add "exec lightshaft.cfg" into your autoexec (you can do this in-game).

When ingame use the command /lstoggle Q which will toggle light shafts on and off. Q is the optional quality of the radial blur (100 is the best quality). Valid range is 10 to 100, and by default it is set to 50. You can also add "lstoggle" into your autoexec to have lightshafts on all the time.

Do not use addpostfx to start the shader - it requies a cubescript loop to update the sun's position.

Update 28.8.2014
- lightshafts are only rendered near sun, thus creating a flare
- lightshaft center is no longer calculated from sunlight direction, instead it is set to the sun's (or moon's) position in each skybox
- Q in lstoggle Q now controls the quality in percentage instead of number of passes for blur. This means that setting the quality to 50 in new lightshafts results in better quality than 50 in old lightshafts
These changes cause lightshafts to work with nearly every daytime map and even with some night maps. They also add a glow flare-like effect to the sun. Plus only rendering lightshafts near sun improves performance.

Update 28.9.2014
- Optimized! Mainly "if" removals (GPUs don't like ifs)
- Sun is now slightly colored
- lstoggle has a second parameter which controls the maximum number of checked pixels (like in the first version of lightshafts)
- lightshafts are now turned off on skyboxes without sun
- lightshafts will use sunlight as the sun's position on custom skyboxes
- added comments to the shader code

More pictures:

(script not available for preview because quadropolis doesn't like greater-than and less-than signs)

lightshaft.cfg (7.18 KB)
72
points
 (8 votes)
User login
Users on Quadropolis
1 guest & no users online
7YearBitch
10
points ]
 (1 vote)
Created 2020-06-02 09:43
1 day 3 hours ago
10
points ]
 (1 vote)
Created 2020-06-01 20:40
1 day 16 hours ago
18
points ]
 (2 votes)
Created 2020-05-31 16:27
2 days 21 hours ago
LURKing
33
points ]
 (4 votes)
Created 2020-05-09 17:56
3 weeks 3 days ago
20
points ]
 (2 votes)
Created 2020-05-16 23:15
2 weeks 3 days ago
Created 2020-05-14 12:56
2 weeks 6 days ago
224
points ]
 (23 votes)
Created 2012-10-20 09:56
7 years 32 weeks ago
Gangler
10
points ]
 (1 vote)
Created 2020-05-12 22:59
3 weeks 14 hours ago
afroninja
46
points ]
 (5 votes)
Created 2020-01-15 07:47
20 weeks 5 hours ago
20
points ]
 (2 votes)
Created 2020-04-29 18:35
4 weeks 6 days ago
140
points ]
 (15 votes)
Created 2013-06-09 21:05
6 years 51 weeks ago
20
points ]
 (2 votes)
Created 2020-05-02 19:58
4 weeks 3 days ago
20
points ]
 (2 votes)
Created 2016-07-28 12:06
3 years 44 weeks ago
7YearBitch
20
points ]
 (2 votes)
Created 2020-03-16 20:09
11 weeks 1 day ago
70
points ]
 (7 votes)
Created 2020-01-24 22:26
18 weeks 4 days ago
40
points ]
 (4 votes)
Created 2020-01-23 12:57
18 weeks 6 days ago
30
points ]
 (4 votes)
Created 2020-01-26 14:10
18 weeks 2 days ago
170
points ]
 (17 votes)
Created 2011-09-05 14:13
8 years 39 weeks ago
Sauce
71
points ]
 (8 votes)
Created 2018-08-22 19:15
1 year 40 weeks ago
Lord Kv
160
points ]
 (16 votes)
Created 2015-03-12 14:45
5 years 12 weeks ago
Who's new
  • Spr1te
  • Akari
  • LURKing
  • Antknee55
  • gmiz