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
12
points ]
 (2 votes)
Created 2017-09-17 12:33
2 days 17 hours ago
Created 2017-09-18 17:38
1 day 12 hours ago
Created 2016-07-28 12:06
1 year 7 weeks ago
DeathStarPC
Created 2017-09-11 03:47
1 week 2 days ago
Created 2017-09-12 03:37
1 week 1 day ago
20
points ]
 (3 votes)
Created 2010-03-04 23:30
7 years 28 weeks ago
DeathStarPC
Created 2017-09-11 03:32
1 week 2 days ago
20
points ]
 (2 votes)
Created 2017-06-22 03:17
12 weeks 6 days ago
Created 2017-04-24 15:32
21 weeks 1 day ago
Created 2017-04-15 03:38
22 weeks 4 days ago
LandRiders7th
Created 2017-05-06 00:42
19 weeks 4 days ago
Created 2017-04-24 15:13
21 weeks 1 day ago
30
points ]
 (9 votes)
Created 2011-06-16 13:56
6 years 13 weeks ago
10
points ]
 (1 vote)
Created 2017-02-02 00:22
32 weeks 6 days ago
74
points ]
 (9 votes)
Created 2012-07-01 13:12
5 years 11 weeks ago
Flitzpiepe
Created 2017-01-28 22:59
33 weeks 3 days ago
214
points ]
 (22 votes)
Created 2012-10-20 09:56
4 years 47 weeks ago
AtlasSteal
31
points ]
 (4 votes)
Created 2016-12-27 04:35
38 weeks 1 day ago
theradical
Created 2016-12-26 16:25
38 weeks 1 day ago
theradical
11
points ]
 (2 votes)
Created 2016-12-20 14:15
39 weeks 15 hours ago
Who's new
  • arCABAL
  • Flitzpiepe
  • M16
  • theradical
  • torben