#version 450 layout(binding = 0) uniform sampler2D tex; layout(binding = 0) uniform samplerCube dstex; layout(std140, binding = 0) uniform shading_state { vec4 diffuse; float fog_density; } s; const vec3 sky_color = vec3(0.35, 0.5, 0.65); layout(location = 0) in vec3 pos; layout(location = 1) in vec2 tex_coord; layout(location = 2) in vec3 world_normal; layout(location = 0) out vec4 color; void main() { vec4 itexel = texture(dstex, normalize(world_normal)); vec4 texel = texture(tex, tex_coord); vec3 object_color = s.diffuse.xyz * texel.xyz * itexel.xyz; float dist = -pos.z; float fog = clamp(exp(-s.fog_density * dist), 0.0, 1.0); color.xyz = mix(sky_color, object_color, fog); color.w = 1.0; }