Commit e318469
authored
void_chromakey: Make the starfield scale-independent (#2050)
Previously the starfield was drawn differently in a 1280×720 viewport
(the base resolution) compared to a 3840x2160 viewport (300% scale,
fullscreen on a 4K monitor). This is because we calculated the position
of each vertex in screen pixel coordinates (i.e. ranging from (0, 0) to
(1280x720) in the first case, and (0, 0) to (3840, 2160) in the second,
and then divided element-wise by a constant (1920, 1080) (not updated
for the resolution change) to get a texture coordinate. So the
bottom-right pixel of the viewport corresponded to (1, 1) in the first
case and (3, 3) in the second.
Instead we can use SCREEN_UV to get, as the name suggests, a UV
coordinate for the pixel on the screen (or rather, the viewport, but
when fullscreened these are the same) ranging from (0, 0) in the
top-left corner and (1, 1) in the bottom-right.
The other use of the `resolution` uniform was to scale the x coordinate
so that stars appear square. This previously gave the wrong effect if
the viewport is not 16:9 aspect ratio: the stars would be stretched with
the aspect ratio. Happily Godot provides SCREEN_PIXEL_SIZE which is
defined to be the inverse of the screen resolution, so we can get the
true aspect ratio from this and scale by that instead. (In fact I had
left a comment to this effect...)
Resolves #11891 parent 7f9c1ba commit e318469
2 files changed
Lines changed: 2 additions & 13 deletions
File tree
- scenes/game_elements/props/void
- components
Lines changed: 2 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | 8 | | |
15 | 9 | | |
16 | 10 | | |
| |||
36 | 30 | | |
37 | 31 | | |
38 | 32 | | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | 33 | | |
43 | 34 | | |
44 | 35 | | |
45 | | - | |
46 | 36 | | |
47 | 37 | | |
48 | 38 | | |
49 | 39 | | |
50 | 40 | | |
51 | | - | |
52 | | - | |
| 41 | + | |
| 42 | + | |
53 | 43 | | |
54 | 44 | | |
55 | 45 | | |
| |||
Lines changed: 0 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
| |||
0 commit comments