rusting_engine 2.7.0

Vulkan 3D game engine with GPU-accelerated physics for massive physics-heavy scenes
// Rusting shader packs, version 1: the sky as scene and sky programs see
// it. The includer declares `shadow` (with `environment` and `sky[4]`),
// `environment_map` and the `camera` push constants. Hooks guard use with
// #ifdef RUSTING_SKY_LUT; vertex, shadow, composite, particle and final
// hooks do not have it.
#ifndef RUSTING_SKY_LUT
#define RUSTING_SKY_LUT 1
#include "sky.glsl"
// The procedural sky settings: [0] direction toward the sun and the cosine
// of the disc's radius, [1] sun colour times brightness and haze, [2]
// ground albedo and the sky mode, [3] cloud drift xz, cover, darkness.
vec4 sky_param(int i) {
    return shadow.sky[i];
}
// Light arriving from `direction`: the bound environment map (a pack's
// sky LUT, the sky bake or the scene's environment texture) at mip `lod`
// times its intensity, else the ambient hemisphere.
vec3 sky_lut_lod(vec3 direction, float lod) {
    if (shadow.environment.x > 0.5) {
        vec2 uv = vec2(
            atan(direction.z, direction.x) / (2.0 * 3.14159265) + 0.5,
            acos(clamp(direction.y, -1.0, 1.0)) / 3.14159265
        );
        // Keep the poles off the opposite edge a repeating sampler wraps to,
        // measured on the coarser of the two mips a trilinear lookup blends.
        float half_texel =
            0.5 / float(textureSize(environment_map, int(ceil(lod))).y);
        uv.y = clamp(uv.y, half_texel, 1.0 - half_texel);
        return textureLod(environment_map, uv, lod).rgb * shadow.environment.y;
    }
    return mix(
        camera.ground_ambient.rgb,
        camera.ambient.rgb,
        direction.y * 0.5 + 0.5
    );
}
vec3 sky_lut_at(vec3 direction) {
    return sky_lut_lod(direction, 0.0);
}
#endif