use mln_gfx::shaders::source::MslSource;
use crate::render::terrain::msl::ground_height;
pub(crate) const VERTEX_TEXEL: MslSource = MslSource {
vertex_main_function: r"vertexMain",
fragment_main_function: r"fragmentMain",
source: r"
struct FragmentStage {
float4 position [[position, invariant]];
float4 color;
};
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]] MLN_VERTEX_BINDINGS) {
return {
.position = float4(float2(vertx.pos_texel.xy), 0.0, 1.0),
.color = image.read(uint2(vertx.pos_texel.zw)),
};
}
half4 fragment fragmentMain(FragmentStage in [[stage_in]] MLN_FRAGMENT_BINDINGS) {
return half4(in.color);
}
",
fast_math: true,
};
pub(crate) const TERRAIN_PROBE: MslSource = MslSource {
vertex_main_function: r"vertexMain",
fragment_main_function: r"fragmentMain",
source: concat!(
ground_height!(),
r"
struct FragmentStage {
float4 position [[position, invariant]];
float height [[flat]];
};
FragmentStage vertex vertexMain(thread const VertexStage vertx [[stage_in]] MLN_VERTEX_BINDINGS) {
return {
.position = float4(vertx.pos.xy, 0.0, 1.0),
.height = ground_height(vertx.pos.zw, vertx.dem_coords, ground_dem, terrain),
};
}
float4 fragment fragmentMain(FragmentStage in [[stage_in]] MLN_FRAGMENT_BINDINGS) {
const uint bits = as_type<uint>(in.height);
const uint4 bytes = uint4(bits, bits >> 8, bits >> 16, bits >> 24) & uint4(255);
return float4(bytes) / 255.0;
}
"
),
fast_math: false,
};