LumixEngine/data/pipelines/cubemap_sky.shd
2020-09-23 01:09:09 +02:00

37 lines
No EOL
932 B
Text

include "pipelines/common.glsl"
vertex_shader [[
layout (location = 0) out vec2 v_uv;
void main()
{
gl_Position = fullscreenQuad(gl_VertexID, v_uv);
}
]]
fragment_shader [[
layout (location = 0) in vec2 v_uv;
layout (location = 0) out vec4 o_color;
layout (binding = 0) uniform samplerCube u_sky;
float getFogFactorSky(float cam_height, vec3 eye_dir, float fog_density, float fog_bottom, float fog_height)
{
if(eye_dir.y == 0) return 1.0;
float to_top = max(0, (fog_bottom + fog_height) - cam_height);
float avg_y = (fog_bottom + fog_height + cam_height) * 0.5;
float avg_density = fog_density * saturate(1 - (avg_y - fog_bottom) / fog_height);
float res = exp(-pow(avg_density * to_top / eye_dir.y, 2));
res = 1 - saturate(res - (1-min(0.2, eye_dir.y)*5));
return res;
}
void main()
{
vec3 eye_dir = getWorldNormal(v_uv);
o_color.rgb = texture(u_sky, eye_dir).rgb;
o_color.a = 1;
}
]]