Theme

alex/beta-minecraft-rust

Minecraft Beta 1.7.3 Rewrite

BRANCH main
main
SNAPSHOT Draw terrain GPU-driven from packed per-section buffers with GPU occlusion culling, add a render distance slider (2-128) with a quad/disk shape, cut chunk bookkeeping at high render distances, and fix a light underflow at y=0
DOWNLOAD
Download file

root / crates / client / shaders / sky.slang

// Sky planes, sunrise fan, sun and moon. Positions are relative to the camera.

struct SkyVertex
{
    float3 position;
    float2 uv;
    uint color;  // RGBA8
};

struct Push
{
    float4x4 viewProjection;
    SkyVertex* vertices;
    float4 fogColor;
    float4 camera;
    float fogStart;
    float fogEnd;
    uint fog;
    int texture;  // negative for untextured
};

[[vk::push_constant]] Push push;
[[vk::binding(0, 0)]] Texture2D textures[];
[[vk::binding(1, 0)]] SamplerState samplers[];

struct Varyings
{
    float4 position : SV_Position;
    float2 uv : TEXCOORD0;
    float4 color : COLOR0;
    float distance : TEXCOORD1;
};

[shader("vertex")]
Varyings vertexMain(uint vertexIndex : SV_VulkanVertexID)
{
    SkyVertex v = push.vertices[vertexIndex];
    Varyings o;
    o.position = mul(push.viewProjection, float4(v.position, 1.0));
    o.uv = v.uv;
    o.color = unpackUnorm4x8ToFloat(v.color);
    o.distance = length(v.position - push.camera.xyz);
    return o;
}

[shader("fragment")]
float4 fragmentMain(Varyings i) : SV_Target
{
    float4 color = i.color;
    if (push.texture >= 0)
        color *= textures[push.texture].Sample(samplers[0], i.uv);
    if (push.fog != 0)
    {
        // A negative start selects GL_EXP fog with the negated start as density
        float fog = push.fogStart < 0.0
            ? exp(push.fogStart * i.distance)
            : saturate((push.fogEnd - i.distance) / (push.fogEnd - push.fogStart));
        color.rgb = lerp(push.fogColor.rgb, color.rgb, fog);
    }
    return color;
}