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
Created 2024-06-02 22:13
7 weeks 12 hours ago
Created 2024-06-02 14:26
7 weeks 20 hours ago
vampirefrog
Created 2024-04-11 22:25
14 weeks 3 days ago
vampirefrog
29
points ]
 (4 votes)
Created 2010-05-30 10:00
14 years 8 weeks ago
Gangler
36
points ]
 (4 votes)
Created 2020-10-22 00:50
3 years 39 weeks ago
Zoocata
10
points ]
 (1 vote)
Created 2024-02-11 21:20
23 weeks 13 hours ago
vampirefrog
10
points ]
 (1 vote)
Created 2023-07-23 20:02
52 weeks 14 hours ago
36
points ]
 (4 votes)
Created 2020-12-10 12:49
3 years 32 weeks ago
Created 2023-12-12 23:34
31 weeks 5 days ago
Zoocata
Created 2023-11-27 23:00
33 weeks 6 days ago
20
points ]
 (2 votes)
Created 2023-10-01 15:21
42 weeks 19 hours ago
20
points ]
 (2 votes)
Created 2021-05-24 00:01
3 years 8 weeks ago
9
points ]
 (1 vote)
Created 2023-06-13 17:54
1 year 5 weeks ago
Zoocata
27
points ]
 (3 votes)
Created 2023-05-05 20:58
1 year 11 weeks ago
Zoocata
18
points ]
 (2 votes)
Created 2023-03-02 01:40
1 year 20 weeks ago
Getridou
Created 2023-01-29 23:27
1 year 24 weeks ago
Created 2023-01-19 19:36
1 year 26 weeks ago
Getridou
Created 2023-01-10 17:10
1 year 27 weeks ago
Getridou
Created 2023-01-01 14:30
1 year 28 weeks ago
Getridou
10
points ]
 (1 vote)
Created 2023-01-01 10:58
1 year 28 weeks ago
Who's new
  • ColdIV
  • Aidan
  • Hunk
  • letic86
  • BATMAN