alex/beta-minecraft-rust
Minecraft Beta 1.7.3 Rewrite
BRANCH 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
root crates client shaders gui.slang
struct Vertex
{
float2 position;
float2 uv;
uint color;
int texture;
};
struct Push
{
Vertex* vertices;
float2 size;
};
[[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;
nointerpolation int texture : TEXCOORD1;
};
[shader("vertex")]
Varyings vertexMain(uint index : SV_VulkanVertexID)
{
Vertex v = push.vertices[index];
Varyings o;
o.position = float4(v.position.x / push.size.x * 2.0 - 1.0, 1.0 - v.position.y / push.size.y * 2.0, 1.0, 1.0);
o.uv = v.uv;
o.color = unpackUnorm4x8ToFloat(v.color);
o.texture = v.texture;
return o;
}
// Texture flags: smooth sampling, and darkening the screen by the texel color (`GL_ZERO`,
// `GL_ONE_MINUS_SRC_COLOR`) for gray textures.
static const int BLUR = 1 << 16;
static const int DARKEN = 1 << 17;
// The crosshair's inverting blend: transparent texels must leave the screen unchanged.
static const int INVERT = 1 << 18;
[shader("fragment")]
float4 fragmentMain(Varyings i) : SV_Target
{
float4 color = i.color;
if (i.texture >= 0)
{
uint sampler = (i.texture & BLUR) != 0 ? 1 : 0;
color *= textures[NonUniformResourceIndex(i.texture & 0xffff)].Sample(samplers[NonUniformResourceIndex(sampler)], i.uv);
}
if (i.texture >= 0 && (i.texture & DARKEN) != 0)
return float4(0.0, 0.0, 0.0, color.r);
if (i.texture >= 0 && (i.texture & INVERT) != 0)
return float4(color.a >= 0.1 ? color.rgb : float3(0.0), 0.0);
return color;
}