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
Ao1 Pointblank
81
points ]
 (9 votes)
Created 2018-03-22 02:14
33 weeks 5 days ago
Doko
28
points ]
 (3 votes)
Created 2018-11-05 21:53
1 week 8 hours ago
Fixxxer
85
points ]
 (9 votes)
Created 2018-10-27 15:21
2 weeks 2 days ago
Redon
114
points ]
 (12 votes)
Created 2018-09-25 22:41
6 weeks 6 days ago
Cooper
49
points ]
 (6 votes)
Created 2016-02-12 07:14
2 years 39 weeks ago
7YearBitch
24
points ]
 (3 votes)
Created 2018-10-14 13:17
4 weeks 1 day ago
Sauce
45
points ]
 (5 votes)
Created 2018-08-22 19:15
11 weeks 5 days ago
7YearBitch
26
points ]
 (3 votes)
Created 2018-08-10 18:14
13 weeks 3 days ago
Shuzomi
94
points ]
 (10 votes)
Created 2018-09-15 20:19
8 weeks 2 days ago
Ao1 Pointblank
35
points ]
 (4 votes)
Created 2018-10-04 23:03
5 weeks 4 days ago
35
points ]
 (4 votes)
Created 2018-07-30 14:34
15 weeks 15 hours ago
10
points ]
 (1 vote)
Created 2018-10-04 23:22
5 weeks 4 days ago
5
points ]
 (1 vote)
Created 2013-05-28 16:41
5 years 24 weeks ago
16
points ]
 (2 votes)
Created 2013-05-28 16:31
5 years 24 weeks ago
7YearBitch
24
points ]
 (3 votes)
Created 2018-09-18 23:06
7 weeks 6 days ago
Ao1 Pointblank
46
points ]
 (5 votes)
Created 2018-08-05 21:24
14 weeks 1 day ago
Zoocata
44
points ]
 (5 votes)
Created 2018-07-15 07:17
17 weeks 1 day ago
56
points ]
 (7 votes)
Created 2018-07-12 17:59
17 weeks 4 days ago
30
points ]
 (9 votes)
Created 2011-06-16 13:56
7 years 21 weeks ago
10
points ]
 (1 vote)
Created 2018-09-17 02:06
8 weeks 1 day ago
Who's new
  • impala97
  • Fixxxer
  • Gangler
  • DON
  • sevnnseven