Archived
1
Fork 0
This repository has been archived on 2025-04-12. You can view files and clone it, but cannot push or open issues or pull requests.
prism/engine/shaders/sky.frag.glsl

48 lines
1.2 KiB
Text
Raw Normal View History

2021-05-09 20:04:41 -04:00
#include "atmosphere.glsl"
layout (location = 0) in vec2 in_uv;
layout (location = 0) out vec4 out_color;
layout(push_constant, binding = 1) uniform PushConstant{
mat4 view;
vec4 sun_position_fov;
float aspect;
};
vec3 sky_ray(const vec2 uv) {
const float d = 0.5 / tan(sun_position_fov.w / 2.0);
return normalize(vec3((uv.x - 0.5) * aspect,
uv.y - 0.5,
d));
}
void main() {
const vec3 color = atmosphere(
// ray direction
normalize(mat3(view) * sky_ray(in_uv)),
// ray origin
vec3(0, 6372e3, 0),
// position of the sun in world space (this will be normalized)
sun_position_fov.xyz,
// intensity of the sun
22.0,
// radius of the plant in meters
6371e3,
// radius of the atmosphere in meters
6471e3,
// Rayleigh scattering coefficient
vec3(5.5e-6, 13.0e-6, 22.4e-6),
// Mie scattering coefficient
21e-6,
// Rayleigh scale height
8e3,
// Mie scale height
1.2e3,
// Mie preferred scattering direction
0.758
);
out_color = vec4(color, 1.0);
}