Last active
January 8, 2025 18:49
-
-
Save partybusiness/f6dc244277b5ade637242730062f65bd to your computer and use it in GitHub Desktop.
Two methods of displaying a starry sky. One generates a star map as a 64x64 png file using star position data and then uses that star map to display a sky shader. The other just displays random star positions along vertical strips.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RA | DEC | V | B-V | |
---|---|---|---|---|
00 08.2 | +29 04 | 2.1 | -0.11 | |
00 09.0 | +59 08 | 2.3 | 0.34 | |
00 13.1 | +15 10 | 2.8 | -0.23 | |
00 25.4 | -77 17 | 2.8 | 0.62 | |
00 26.2 | -42 20 | 2.39 | 1.09 | |
00 39.2 | +30 50 | 3.27 | 1.28 | |
00 40.3 | +56 31 | 2.23 | 1.17 | |
00 43.5 | -18 01 | 2.04 | 1.02 | |
00 49.0 | +57 48 | 3.44 | 0.57 | |
00 56.6 | +60 42 | 2.5 | -0.15 | |
01 05.9 | -46 44 | 3.31 | 0.89 | |
01 08.5 | -10 12 | 3.45 | 1.16 | |
01 09.5 | +35 36 | 2.06 | 1.58 | |
01 25.6 | +60 13 | 2.7 | 0.13 | |
01 28.3 | -43 20 | 3.4 | 1.57 | |
01 37.5 | -57 15 | 0.46 | -0.16 | |
01 44.0 | -15 58 | 3.5 | 0.72 | |
01 52.9 | +29 34 | 3.41 | 0.49 | |
01 54.1 | +63 39 | 3.38 | -0.15 | |
01 54.5 | +20 47 | 2.64 | 0.13 | |
01 58.7 | -61 36 | 2.86 | 0.28 | |
02 03.7 | +42 19 | 2.26 | 1.37 | |
02 07.0 | +23 27 | 2 | 1.15 | |
02 09.4 | +34 58 | 3 | 0.14 | |
02 19.2 | -3 01 | 2 | 1.42 | |
02 27.9 | +89 15 | 2 | 0.6 | |
02 43.2 | +3 14 | 3.47 | 0.09 | |
02 58.1 | -40 20 | 3.42 | 0.14 | |
03 02.1 | +4 04 | 2.53 | 1.64 | |
03 04.5 | +53 29 | 2.93 | 0.7 | |
03 05.0 | +38 49 | 3.4 | 1.65 | |
03 08.0 | +40 56 | 2.1 | -0.05 | |
03 24.1 | +49 50 | 1.79 | 0.48 | |
03 42.7 | +47 46 | 3.01 | -0.13 | |
03 43.1 | -9 47 | 3.54 | 0.92 | |
03 47.4 | +24 05 | 2.87 | -0.09 | |
03 47.3 | -74 15 | 3.24 | 1.62 | |
03 54.0 | +31 52 | 2.85 | 0.12 | |
03 57.6 | +40 00 | 2.89 | -0.18 | |
03 57.9 | -13 31 | 2.95 | 1.59 | |
04 00.5 | +12 29 | 3.5 | -0.12 | |
04 14.4 | -62 29 | 3.35 | 0.91 | |
04 28.4 | +15 52 | 3.4 | 0.18 | |
04 28.6 | +19 10 | 3.53 | 1.01 | |
04 33.9 | -55 03 | 3.27 | -0.1 | |
04 35.7 | +16 30 | 0.85 | 1.54 | |
04 49.7 | +6 58 | 3.19 | 0.45 | |
04 56.8 | +33 10 | 2.69 | 1.53 | |
05 01.7 | +43 50 | 3.04 | 0.54 | |
05 05.3 | -22 23 | 3.19 | 1.46 | |
05 06.3 | +41 13 | 3.17 | -0.18 | |
05 07.7 | -5 06 | 2.79 | 0.13 | |
05 12.8 | -16 13 | 3.3 | -0.11 | |
05 14.7 | -8 13 | 0.12 | -0.03 | |
05 16.4 | +45 59 | 0.08 | 0.8 | |
05 24.3 | -2 24 | 3.4 | -0.17 | |
05 25.0 | +6 20 | 1.64 | -0.22 | |
05 26.2 | +28 36 | 1.65 | -0.13 | |
05 28.2 | -20 46 | 2.84 | 0.82 | |
05 31.9 | -0 18 | 2.23 | -0.22 | |
05 32.7 | -17 50 | 2.58 | 0.21 | |
05 33.6 | -62 30 | 3.8 | 0.84 | |
05 35.0 | +9 56 | 3.54 | -0.18 | |
05 35.3 | -5 55 | 2.77 | -0.24 | |
05 36.1 | -1 12 | 1.7 | -0.19 | |
05 37.5 | +21 08 | 3 | -0.19 | |
05 39.5 | -34 05 | 2.64 | -0.12 | |
05 40.6 | -1 57 | 2.05 | -0.21 | |
05 46.9 | -14 50 | 3.55 | 0.1 | |
05 47.7 | -9 40 | 2.06 | -0.17 | |
05 50.8 | -35 46 | 3.12 | 1.16 | |
05 55.0 | +7 24 | 0.5 | 1.85 | |
05 59.3 | +44 57 | 1.9 | 0.03 | |
05 59.5 | +37 13 | 2.62 | -0.08 | |
06 14.7 | +22 31 | 3.3 | 1.6 | |
06 20.1 | -30 03 | 3.02 | -0.19 | |
06 22.6 | -17 57 | 2 | -0.23 | |
06 22.8 | +22 31 | 2.9 | 1.64 | |
06 23.8 | -52 41 | -0.72 | 0.15 | |
06 37.5 | +16 25 | 1.93 | 0 | |
06 37.6 | -43 11 | 3.17 | -0.11 | |
06 43.8 | +25 09 | 2.98 | 1.4 | |
06 45.1 | +12 54 | 3.36 | 0.43 | |
06 45.1 | -16 42 | -1.46 | 0 | |
06 48.3 | -61 56 | 3.27 | 0.21 | |
06 49.8 | -50 36 | 2.93 | 1.2 | |
06 58.4 | -28 58 | 1.5 | -0.21 | |
07 01.5 | -27 56 | 3.5 | 1.73 | |
07 03.0 | -23 50 | 3.02 | -0.08 | |
07 08.2 | -26 24 | 1.84 | 0.68 | |
07 13.4 | -44 38 | 2.6 | 1.56 | |
07 17.0 | -37 06 | 2.7 | 1.62 | |
07 20.0 | +21 59 | 3.53 | 0.34 | |
07 23.9 | -29 18 | 2.45 | -0.08 | |
07 27.0 | +8 18 | 2.9 | -0.09 | |
07 29.1 | -43 18 | 3.25 | 1.51 | |
07 34.4 | +31 54 | 1.94 | 0.03 | |
07 34.5 | +31 54 | 2.92 | 0.04 | |
07 39.2 | +5 14 | 0.38 | 0.42 | |
07 45.2 | +28 02 | 1.14 | 1 | |
07 49.3 | -24 51 | 3.34 | 1.24 | |
07 56.7 | -52 58 | 3.47 | -0.18 | |
08 03.4 | -39 59 | 2.25 | -0.26 | |
08 07.5 | -24 17 | 2.8 | 0.43 | |
08 09.4 | -47 19 | 1.8 | -0.22 | |
08 16.3 | +9 12 | 3.52 | 1.48 | |
08 22.4 | -59 30 | 1.86 | 1.28 | |
08 30.0 | +60 44 | 3.4 | 0.84 | |
08 44.6 | -54 41 | 1.96 | 0.04 | |
08 46.6 | +6 26 | 3.38 | 0.68 | |
08 55.2 | +5 58 | 3.11 | 1 | |
08 59.0 | +48 04 | 3.14 | 0.19 | |
09 07.8 | -43 24 | 2.21 | 1.66 | |
09 10.9 | -58 56 | 3.44 | -0.19 | |
09 13.2 | -69 41 | 1.68 | 0 | |
09 17.0 | -59 16 | 2.2 | 0.18 | |
09 20.9 | +34 24 | 3.13 | 1.55 | |
09 22.0 | -55 00 | 2.5 | -0.18 | |
09 27.5 | -8 39 | 1.98 | 1.44 | |
09 31.0 | -57 01 | 3.13 | 1.55 | |
09 32.7 | +51 42 | 3.17 | 0.46 | |
09 41.0 | +9 54 | 3.52 | 0.49 | |
09 45.2 | -62 30 | 3.8 | 0.14 | |
09 45.7 | +23 47 | 2.98 | 0.8 | |
09 46.9 | -65 03 | 3.01 | 0.28 | |
09 56.7 | -54 33 | 3.54 | -0.08 | |
10 07.2 | +16 47 | 3.52 | -0.03 | |
10 08.2 | +12 00 | 1.35 | -0.11 | |
10 13.6 | -70 01 | 3.32 | -0.08 | |
10 16.5 | +23 26 | 3.44 | 0.31 | |
10 17.0 | +42 56 | 3.45 | 0.03 | |
10 16.9 | -61 19 | 3.4 | 1.54 | |
10 19.8 | +19 52 | 2.61 | 1.15 | |
10 19.8 | +19 52 | 3.47 | 1.1 | |
10 22.2 | +41 31 | 3.05 | 1.59 | |
10 31.8 | -61 40 | 3.3 | -0.09 | |
10 42.8 | -64 22 | 2.76 | -0.22 | |
10 46.7 | -49 24 | 2.69 | 0.9 | |
10 49.5 | -16 10 | 3.11 | 1.25 | |
11 01.7 | +56 24 | 2.37 | -0.02 | |
11 03.6 | +61 46 | 1.79 | 1.07 | |
11 09.5 | +44 31 | 3.01 | 1.14 | |
11 14.0 | +20 33 | 2.56 | 0.12 | |
11 14.0 | +15 27 | 3.34 | -0.01 | |
11 18.3 | +33 07 | 3.48 | 1.4 | |
11 32.9 | -31 50 | 3.54 | 0.94 | |
11 35.7 | -63 00 | 3.13 | -0.04 | |
11 48.9 | +14 36 | 2.14 | 0.09 | |
11 53.7 | +53 43 | 2.44 | 0 | |
12 10.0 | -22 36 | 3 | 1.33 | |
12 15.0 | -58 43 | 2.8 | -0.23 | |
12 15.3 | +57 03 | 3.31 | 0.08 | |
12 15.7 | -17 31 | 2.59 | -0.11 | |
12 26.4 | -63 04 | 1.33 | -0.24 | |
12 29.7 | -16 29 | 2.95 | -0.05 | |
12 31.0 | -57 05 | 1.63 | 1.59 | |
12 34.2 | -23 22 | 2.65 | 0.89 | |
12 37.0 | -69 07 | 2.69 | -0.2 | |
12 41.3 | -48 56 | 2.87 | -0.03 | |
12 41.5 | -1 26 | 2.76 | 0.36 | |
12 46.1 | -68 05 | 3.05 | -0.18 | |
12 47.6 | -59 40 | 1.2 | -0.23 | |
12 54.0 | +56 00 | 1.8 | -0.02 | |
12 55.4 | +3 25 | 3.38 | 1.58 | |
13 02.1 | +10 59 | 2.83 | 0.94 | |
13 18.7 | -23 09 | 3 | 0.92 | |
13 20.4 | -36 41 | 2.75 | 0.04 | |
13 23.7 | +54 58 | 2.27 | 0.02 | |
13 25.0 | -11 08 | 1 | -0.23 | |
13 39.7 | -53 27 | 2.3 | -0.22 | |
13 47.2 | +49 21 | 1.86 | -0.19 | |
13 49.4 | -41 40 | 3.41 | -0.22 | |
13 49.5 | -42 27 | 3 | -0.17 | |
13 54.6 | +18 25 | 2.68 | 0.58 | |
14 03.6 | -60 21 | 0.6 | -0.23 | |
14 06.2 | -26 40 | 3.27 | 1.12 | |
14 06.6 | -36 21 | 2.06 | 1.01 | |
14 15.6 | +19 12 | -0.04 | 1.23 | |
14 19.2 | -46 03 | 3.55 | -0.18 | |
14 35.3 | -42 09 | 2.3 | -0.19 | |
14 39.5 | -60 50 | 1.33 | 0.88 | |
14 39.5 | -60 49 | -0.01 | 0.71 | |
14 41.7 | -47 23 | 2.3 | -0.2 | |
14 42.2 | -64 58 | 3.19 | 0.24 | |
14 50.7 | -16 01 | 2.75 | 0.15 | |
14 50.7 | +74 11 | 2.08 | 1.47 | |
14 58.3 | -43 07 | 2.68 | -0.22 | |
14 59.0 | -42 05 | 3.13 | -0.2 | |
15 01.7 | +40 25 | 3.5 | 0.97 | |
15 12.0 | -52 05 | 3.41 | 0.92 | |
15 15.3 | +33 20 | 3.47 | 0.95 | |
15 16.8 | -9 22 | 2.61 | -0.11 | |
15 18.6 | -68 39 | 2.89 | 0 | |
15 20.7 | +71 51 | 3.05 | 0.05 | |
15 22.5 | -44 40 | 3.37 | -0.18 | |
15 24.8 | +58 59 | 3.29 | 1.16 | |
15 34.6 | +26 44 | 2.2 | -0.02 | |
15 34.9 | -41 09 | 2.78 | -0.2 | |
15 44.1 | +6 26 | 2.65 | 1.17 | |
15 54.8 | -63 25 | 2.85 | 0.29 | |
15 58.8 | -26 06 | 2.89 | -0.19 | |
15 59.3 | +25 56 | 2 | 0.1 | |
15 59.9 | -38 23 | 3.41 | -0.22 | |
16 00.2 | -22 37 | 2.32 | -0.12 | |
16 14.2 | -3 41 | 2.74 | 1.58 | |
16 18.2 | -4 41 | 3.24 | 0.96 | |
16 21.0 | -25 35 | 2.9 | 0.13 | |
16 23.9 | +61 31 | 2.74 | 0.91 | |
16 30.2 | +21 30 | 2.77 | 0.94 | |
16 35.7 | -28 13 | 2.82 | -0.25 | |
16 37.0 | -10 34 | 2.56 | 0.02 | |
16 41.1 | +31 36 | 2.81 | 0.65 | |
16 48.2 | -69 02 | 1.92 | 1.44 | |
16 50.0 | -34 17 | 2.29 | 1.15 | |
16 51.7 | -38 03 | 3.1 | -0.2 | |
16 57.6 | +9 22 | 3.2 | 1.15 | |
16 58.3 | -55 59 | 3.13 | 1.6 | |
17 08.8 | +65 44 | 3.17 | -0.12 | |
17 10.2 | -15 43 | 2.43 | 0.06 | |
17 11.9 | -43 14 | 3.33 | 0.41 | |
17 14.6 | +14 24 | 3.1 | 1.44 | |
17 14.9 | +24 51 | 3.14 | 0.08 | |
17 14.9 | +36 49 | 3.16 | 1.44 | |
17 21.9 | -24 59 | 3.3 | -0.22 | |
17 25.0 | -55 31 | 2.85 | 1.46 | |
17 25.1 | -56 22 | 3.34 | -0.13 | |
17 30.6 | -37 17 | 2.69 | -0.22 | |
17 30.3 | +52 19 | 2.79 | 0.98 | |
17 31.6 | -49 52 | 2.95 | -0.17 | |
17 33.4 | -37 06 | 1.6 | -0.22 | |
17 34.9 | +12 34 | 2.08 | 0.15 | |
17 37.1 | -43 00 | 1.87 | 0.4 | |
17 37.4 | -15 24 | 3.54 | 0.26 | |
17 42.3 | -39 02 | 2.4 | -0.22 | |
17 43.3 | +4 34 | 2.77 | 1.16 | |
17 46.2 | +27 44 | 3.42 | 0.75 | |
17 47.4 | -40 07 | 3.03 | 0.51 | |
17 49.6 | -37 02 | 3.21 | 1.17 | |
17 56.5 | +51 29 | 2.23 | 1.52 | |
17 58.8 | -9 46 | 3.34 | 0.99 | |
18 05.6 | -30 25 | 2.99 | 1 | |
18 17.4 | -36 46 | 3.11 | 1.56 | |
18 20.8 | -29 50 | 2.7 | 1.38 | |
18 21.2 | -2 54 | 3.26 | 0.94 | |
18 24.0 | -34 23 | 1.85 | -0.03 | |
18 26.7 | -45 58 | 3.51 | -0.17 | |
18 27.8 | -25 26 | 2.81 | 1.04 | |
18 36.8 | +38 46 | 0.03 | 0 | |
18 45.5 | -27 00 | 3.17 | -0.11 | |
18 49.9 | +33 21 | 3.4 | 0 | |
18 55.1 | -26 19 | 2.02 | -0.22 | |
18 57.6 | -21 07 | 3.51 | 1.18 | |
18 58.7 | +32 41 | 3.24 | -0.05 | |
19 02.4 | -29 53 | 2.6 | 0.08 | |
19 05.3 | +13 52 | 2.99 | 0.01 | |
19 06.1 | -4 53 | 3.44 | -0.09 | |
19 06.8 | -27 40 | 3.32 | 1.19 | |
19 09.6 | -21 01 | 2.89 | 0.35 | |
19 12.6 | +67 40 | 3.07 | 1 | |
19 25.4 | +3 07 | 3.36 | 0.32 | |
19 30.5 | +27 57 | 3.08 | 1.13 | |
19 44.8 | +45 07 | 2.87 | -0.03 | |
19 46.1 | +10 36 | 2.72 | 1.52 | |
19 50.7 | + 8 51 | 0.77 | 0.22 | |
19 52.3 | + 1 00 | 3.9 | 0.83 | |
19 58.7 | +19 29 | 3.47 | 1.57 | |
20 11.2 | -0 50 | 3.23 | -0.07 | |
20 20.8 | -14 48 | 3.08 | 0.79 | |
20 22.0 | +40 14 | 2.2 | 0.68 | |
20 25.4 | -56 45 | 1.94 | -0.2 | |
20 37.3 | -47 19 | 3.11 | 1 | |
20 41.3 | +45 16 | 1.25 | 0.09 | |
20 44.6 | -66 13 | 3.42 | 0.16 | |
20 45.2 | +61 49 | 3.43 | 0.92 | |
20 46.0 | +33 57 | 2.46 | 1.03 | |
21 12.9 | +30 12 | 3.2 | 0.99 | |
21 18.4 | +62 34 | 2.44 | 0.22 | |
21 28.6 | +70 33 | 3.2 | -0.22 | |
21 31.4 | -5 35 | 2.91 | 0.83 | |
21 44.0 | +9 51 | 2.4 | 1.53 | |
21 46.9 | -16 09 | 2.9 | 0.29 | |
21 53.8 | -37 23 | 3.01 | -0.12 | |
22 05.6 | -0 20 | 2.96 | 0.98 | |
22 08.0 | -47 00 | 1.74 | -0.13 | |
22 10.1 | +6 11 | 3.53 | 0.08 | |
22 10.7 | +58 11 | 3.35 | 1.57 | |
22 18.3 | -60 17 | 2.86 | 1.39 | |
22 29.0 | +58 24 | 4 | 0.71 | |
22 41.3 | +10 49 | 3.4 | -0.09 | |
22 42.5 | -46 54 | 2.1 | 1.6 | |
22 42.8 | +30 12 | 2.94 | 0.86 | |
22 48.4 | -51 20 | 3.49 | 0.08 | |
22 49.5 | +66 11 | 3.52 | 1.05 | |
22 49.9 | +24 35 | 3.48 | 0.93 | |
22 54.6 | -15 51 | 3.27 | 0.05 | |
22 57.5 | -29 39 | 1.16 | 0.09 | |
23 03.7 | +28 04 | 2.4 | 1.67 | |
23 04.6 | +15 11 | 2.49 | -0.04 | |
23 39.3 | +77 36 | 3.21 | 1.03 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@tool | |
extends EditorScript | |
# generates a panorama skyamid based on list of stars | |
# importing star data relies on CSV data importer add-on available here: | |
# https://github.com/timothyqiu/godot-csv-data-importer | |
var target_skyamid:String = "res://starry_sky/star_skyamid.png" | |
# bright star and near star csv files were derived from the spreadsheets here: | |
# https://www.astrosci.scimuze.com/stellar_data.htm | |
const bright_star_data:String = "res://starry_sky/bright_star_lst.csv" | |
const near_star_data:String = "res://starry_sky/near_star_lst.csv" | |
# size of generated skyamid png | |
var target_size:int = 64 | |
func pixel_to_vector(pixel:Vector2i) -> Vector3: | |
var result:Vector3 = Vector3.ONE | |
# convert pixel to range from -1.0 to 1.0 | |
var scaled:Vector2 = ((Vector2(pixel) + Vector2.ONE * 0.5 ) / float(target_size) * 2.0 - Vector2.ONE) | |
var rad:Vector2 = scaled * PI / 2.0 | |
if abs(scaled.x) > abs(scaled.y): | |
if scaled.x < 0: | |
scaled.y = -scaled.y | |
rad.y = -rad.y | |
var y:float = cos(rad.x) | |
var dist:float = sin(rad.x) | |
var side:float = scaled.y / abs(scaled.x) * PI / 4.0 | |
var x:float = cos(side) * dist | |
var z:float = sin(side) * dist # * sign(scaled.y) | |
#print(Vector3(x, y, z) , ", ", side, ", ", (Vector3(x, y, z).length()), " here") | |
return Vector3(x, y, z) | |
else: | |
if scaled.y < 0: | |
scaled.x = -scaled.x | |
rad.x = -rad.x | |
var y:float = cos(rad.y) | |
var dist:float = sin(rad.y) | |
var side:float = scaled.x / abs(scaled.y) * PI / 4.0 | |
var z:float = cos(side) * dist | |
var x:float = sin(side) * dist # * sign(scaled.x) | |
return Vector3(x, y, z) | |
var angle_x:float = scaled.x | |
var angle_y:float = scaled.y | |
result.x = (float(pixel.x) + 0.5) / float(target_size) * 2.0 - 1.0 | |
result.z = (float(pixel.y) + 0.5) / float(target_size) * 2.0 - 1.0 | |
result.y = sqrt(pow(result.x, 2.0) + pow(result.z, 2.0)) | |
return (result - Vector3(0.5, 0.5, 0.5)).normalized() | |
# include these just to test pixel_to_vector is working correctly | |
func test_inverse_pixel(eyedir:Vector3) -> Vector2i: | |
var result:Vector2i = Vector2i( floor(test_inverse(eyedir) * float(target_size))) | |
result.x = clamp(result.x, 0, target_size - 1) | |
result.y = clamp(result.y, 0, target_size - 1) | |
return result | |
func smooth_inverse_pixel(eyedir:Vector3) -> Vector2: | |
var result:Vector2 = Vector2(test_inverse(eyedir) * float(target_size)) | |
return result | |
func test_inverse(eyedir:Vector3) -> Vector2: | |
var ax:float = abs(eyedir.x); | |
var xs:float = sign(eyedir.x); | |
var az:float = abs(eyedir.z); | |
var zs:float = sign(eyedir.z); | |
var ay:float = abs(eyedir.y); | |
var y:float = 1.0 - atan2(ay, Vector2(ax,az).length()) / 1.5708; | |
var x:float = 0.0; | |
if ax > az: | |
x = xs * atan2(eyedir.z, ax) / 1.5708; | |
return Vector2(0.5 + y * 0.5 * xs, 0.5 + y * x * xs); | |
else: | |
x = zs * atan2(eyedir.x, az) / 1.5708; | |
return Vector2(0.5 + y * x * zs, 0.5 + y * 0.5 * zs); | |
# converts Right Ascension and Declanation to a direction vector | |
func ra_dec_to_vector(ra:float, dec:float) -> Vector3: | |
var result:Vector3 | |
# ra is in hours | |
# dec is in degrees | |
# convert to radians | |
var ra_radians:float = ra / 24.0 * PI * 2.0 | |
var dec_radians:float = deg_to_rad(dec) | |
var slice:Vector2 = Vector2(cos(dec_radians), sin(dec_radians)) | |
var side:Vector2 = Vector2(cos(-ra_radians), sin(-ra_radians)) * slice.x | |
result.y = slice.y | |
result.x = side.x | |
result.z = side.y | |
# TODO rotate for lat-long and time of day/year? | |
# convert to topocentric from geocentric? | |
return result | |
func ra_to_float(ra:String) -> float: | |
var split = ra.split_floats(" ") | |
#print(split.size(), ", ", ra) | |
return float(split[0]) + split[1]/60.0 * sign(split[0]) | |
func dec_to_float(dec:String) -> float: | |
var split = dec.split_floats(" ") | |
#print(split.size(), ", ", dec) | |
return float(split[0]) + split[1]/60.0 * sign(split[0]) | |
func mag_to_alpha(mag:float) -> float: | |
#var mag:float = float(mag_s) | |
const max_mag:float = -1.44 # brightest mag we could have, will be equivalent to 1.0 alpha | |
# for every 6 more than max_mag, we want 1/10th the alpha | |
return 1.0 / pow(10.0, (mag - max_mag) / 6.0) | |
func _run() -> void: | |
var star_positions = preload(bright_star_data) | |
var edge_stars:Array[Vector4] = [] | |
var star_count:int = 0 | |
var skip_count:int = 0 | |
var star_image:Image = Image.create(target_size, target_size, false, Image.FORMAT_RGBA8) | |
for i:int in range(0, star_positions.records.size() ): | |
var ra:float = ra_to_float(star_positions.records[i].RA) | |
var dec:float = dec_to_float(star_positions.records[i].DEC) | |
var star_dir:Vector3 = ra_dec_to_vector(ra, dec) | |
if star_dir.y < 0: # skip stars below horizon | |
continue | |
var pixel:Vector2i = test_inverse_pixel(star_dir) | |
if star_image.get_pixel(pixel.x, pixel.y).g > 0: | |
skip_count += 1 | |
continue | |
var star_pixel_pos:Vector2 = smooth_inverse_pixel(star_dir) | |
var offset:Vector2 = (star_pixel_pos - Vector2(pixel)) - Vector2(0.5, 0.5) | |
if abs(offset.x) > 0.45 || abs(offset.y) > 0.45: | |
print("found edge star") | |
edge_stars.append(Vector4(star_dir.x, star_dir.y, star_dir.z, star_positions.records[i].V)) | |
star_count += 1 | |
# shift from -1 to 1 range to 0 to 1 range | |
star_dir = star_dir * 0.5 + Vector3.ONE * 0.5 | |
var mag:float = mag_to_alpha(float(star_positions.records[i].V)) | |
var pixel_color:Color = Color(star_dir.x, star_dir.y, star_dir.z, mag) | |
star_image.set_pixel(pixel.x, pixel.y, pixel_color) | |
# do a pass to fill in adjacent pixels where the pixel is overlapping an edge | |
for edge_star in edge_stars: | |
var star_dir:Vector3 = Vector3(edge_star.x, edge_star.y, edge_star.z) | |
var pixel:Vector2i = test_inverse_pixel(star_dir) | |
var star_pixel_pos:Vector2 = smooth_inverse_pixel(star_dir) | |
var offset:Vector2 = (star_pixel_pos - Vector2(pixel)) - Vector2(0.5, 0.5) | |
var offset_pixel:Vector2i = pixel | |
if abs(offset.x) > abs(offset.y): | |
offset_pixel += Vector2i(sign(offset.x), 0) | |
else: | |
offset_pixel += Vector2i(0, sign(offset.y)) | |
if offset_pixel.x < 0 || offset_pixel.y < 0 || offset_pixel.x >= target_size || offset_pixel.y >= target_size: | |
print("offset star out of bounds") | |
continue | |
if star_image.get_pixel(offset_pixel.x, offset_pixel.y).g > 0: | |
print("skipping offset star") | |
continue | |
star_dir = star_dir * 0.5 + Vector3.ONE * 0.5 | |
var mag:float = mag_to_alpha(float(edge_star.w)) | |
var pixel_color:Color = Color(edge_star.x, edge_star.y, edge_star.z, mag) | |
star_image.set_pixel(offset_pixel.x, offset_pixel.y, pixel_color) | |
print(star_count, " ==> ", skip_count) | |
var star_positions_02 = preload(near_star_data) | |
# second list of stars, they had slightly different format | |
for i:int in range(0, star_positions_02.records.size() ): | |
var ra:float = (star_positions_02.records[i].RA) | |
var dec:float = (star_positions_02.records[i].Dec) | |
var star_dir:Vector3 = ra_dec_to_vector(ra, dec) | |
if star_dir.y < 0: # skip stars below horizon | |
continue | |
var pixel:Vector2i = test_inverse_pixel(star_dir) | |
if star_image.get_pixel(pixel.x, pixel.y).g > 0: | |
skip_count += 1 | |
continue | |
star_count += 1 | |
# shift from -1 to 1 range to 0 to 1 range | |
star_dir = star_dir * 0.5 + Vector3.ONE * 0.5 | |
# adding a bonus column to let me cheat a few stars that I want to ensure are visible | |
var mag:float = mag_to_alpha(float(star_positions_02.records[i].Vmag) + float(star_positions_02.records[i].Bonus)) | |
var pixel_color:Color = Color(star_dir.x, star_dir.y, star_dir.z, mag) | |
star_image.set_pixel(pixel.x, pixel.y, pixel_color) | |
print(star_count, ", ", skip_count) | |
star_image.save_png(target_skyamid) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shader_type sky; | |
// displays stars on skybox | |
// | |
uniform vec4 background_gradient_horizon:source_color = vec4(0.0, 0.0, 0.15, 1.0); | |
uniform vec4 background_gradient_top:source_color = vec4(0.0, 0.0, 0.0, 1.0); | |
// range of sizes for star | |
// basically in millionths? | |
uniform vec2 star_size_range = vec2(2, 10); | |
// texture that defines position and strength of every star | |
uniform sampler2D skyTexture:filter_nearest; | |
vec2 get_skyamid_uv(vec3 eyedir) { | |
float ax = abs(eyedir.x); | |
float xs = sign(eyedir.x); | |
float az = abs(eyedir.z); | |
float zs = sign(eyedir.z); | |
float ay = abs(eyedir.y); | |
float y = 1.0 - atan(ay, length(vec2(ax,az))) / 1.5708; | |
float x = 0.0; | |
if (ax > az) { | |
x = xs * atan(eyedir.z, ax) / 1.5708; | |
return vec2(0.5 + y * 0.5 * xs, 0.5 + y * x * xs); | |
} | |
else { | |
x = zs * atan(eyedir.x, az) / 1.5708; | |
return vec2(0.5 + y * x * zs, 0.5 + y * 0.5 * zs); | |
} | |
} | |
void sky() { | |
float adjusted_y = clamp(pow(EYEDIR.y, 1.0), 0.0 ,1.0); | |
vec3 background = mix(background_gradient_horizon.rgb, background_gradient_top.rgb, adjusted_y); | |
// pick pixel from skyamid | |
vec2 sky_uv = get_skyamid_uv(EYEDIR); | |
//sky_uv = round(sky_uv * 64.00); | |
vec4 sample = texture(skyTexture, sky_uv); | |
// use that for direction of star | |
float star_strength = mix(1.0 - star_size_range.x * 0.000001, 1.0 - star_size_range.y * 0.000001, sample.a); | |
vec3 star_dir = normalize(sample.xyz * 2.0 - vec3(1.0)); // assumes direction is directly | |
float aligned = smoothstep(star_strength, 1.00000001, dot(EYEDIR, star_dir)); | |
COLOR = background + aligned * sqrt(sample.a); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shader_type sky; | |
// displays stars as sky shader | |
// one star per vertical strip but with enough strips it passes first inspection | |
uniform vec4 background_gradient_horizon:source_color = vec4(0.0, 0.0, 0.15, 1.0); | |
uniform vec4 background_gradient_top:source_color = vec4(0.0, 0.0, 0.0, 1.0); | |
// number of vertical strips with one star in each | |
uniform float vertical_strips = 300.0; | |
// rangel of angle | |
uniform float vertical_scale:hint_range(0.0, 1.57, 0.01) = 1.57; | |
// power on vertical to adjust distribution | |
uniform float vertical_pow = 2.0; | |
// range of sizes for star | |
// basically in millionths? | |
uniform vec2 star_size_range = vec2(2, 10); | |
float random_height(float seed) { | |
return fract(tan(seed * 120.3) * 137.0 + tan(seed * 12.0) * 31.0); | |
} | |
void sky() { | |
float adjusted_y = clamp(pow(EYEDIR.y, 1.0), 0.0 ,1.0); | |
vec3 background = mix(background_gradient_horizon.rgb, background_gradient_top.rgb, adjusted_y); | |
// find vertical strip | |
float rounded_angle = round(atan(EYEDIR.x, EYEDIR.z) * vertical_strips / 2.0 / PI) / vertical_strips * 2.0 * PI; | |
// angle height of star in this strip | |
float star_angle = pow(random_height(rounded_angle), vertical_pow) * vertical_scale; | |
float star_strength = mix(1.0 - star_size_range.x * 0.000001, 1.0 - star_size_range.y * 0.000001, random_height(rounded_angle + 3.1)); | |
vec3 star_dir = normalize(vec3(sin(rounded_angle) * cos(star_angle), sin(star_angle), cos(rounded_angle) * cos(star_angle))); | |
float aligned = smoothstep(star_strength, 1.0, dot(EYEDIR, star_dir)); | |
COLOR = background + aligned; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment