Denser stars

This commit is contained in:
Joshua Barretto 2019-06-23 20:18:29 +01:00
parent ad2bc635f8
commit 397c909bd4
2 changed files with 16 additions and 11 deletions

View File

@ -52,29 +52,33 @@ float get_sun_diffuse(vec3 norm, float time_of_day) {
}
vec3 rand_offs(vec3 pos) {
return sin(pos * vec3(1473.7 * pos.z, 8891.1 * pos.x, 3813.3 * pos.y));
return sin(pos * vec3(1473.7 * pos.z + 472.3, 8891.1 * pos.x + 723.1, 3813.3 * pos.y + 982.5));
}
vec3 get_sky_color(vec3 dir, float time_of_day) {
// Stars
float star_scale = 60.0;
float dist = 1000.0;
float star_scale = 30.0;
float star = 0.0;
for (int i = 0; i < 2; i ++) {
for (int j = 0; j < 2; j ++) {
for (int k = 0; k < 2; k ++) {
// Star positions
vec3 pos = (floor(dir * star_scale) + vec3(i, j, k) - vec3(0.5)) / star_scale;
pos += rand_offs(pos) * 0.2;
dist = min(dist, length(normalize(pos) - dir));
// Noisy offsets
pos += 3.0 * rand_offs(pos) / star_scale;
// Find distance to fragment
float dist = length(normalize(pos) - dir);
// Star threshold
if (dist < 0.0015) {
star = 1.0;
}
}
}
}
float star;
if (dist < 0.0015) {
star = 1.0;
} else {
star = 0.0;
}
// Sky color

View File

@ -14,6 +14,7 @@ out vec3 f_pos;
void main() {
f_pos = v_pos;
// TODO: Make this position-independent to avoid rounding error jittering
gl_Position =
proj_mat *
view_mat *