mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-30 18:53:25 +00:00
102 lines
2.8 KiB
Plaintext
102 lines
2.8 KiB
Plaintext
---
|
|
source: tests/snapshots.rs
|
|
expression: msl
|
|
---
|
|
#include <metal_stdlib>
|
|
#include <simd/simd.h>
|
|
|
|
typedef metal::uint4 type;
|
|
|
|
struct Globals {
|
|
type num_lights;
|
|
};
|
|
|
|
typedef metal::float4x4 type1;
|
|
|
|
typedef metal::float4 type2;
|
|
|
|
struct Light {
|
|
type1 proj;
|
|
type2 pos;
|
|
type2 color;
|
|
};
|
|
|
|
typedef Light type3[1];
|
|
|
|
struct Lights {
|
|
type3 data;
|
|
};
|
|
|
|
typedef metal::depth2d_array<float, metal::access::sample> type4;
|
|
|
|
typedef metal::sampler type5;
|
|
|
|
typedef uint type6;
|
|
|
|
typedef float type7;
|
|
|
|
typedef metal::float2 type8;
|
|
|
|
typedef metal::float3 type9;
|
|
|
|
typedef bool type10;
|
|
|
|
constexpr constant float const_0f = 0.0;
|
|
constexpr constant float const_1f = 1.0;
|
|
constexpr constant float const_0_50f = 0.5;
|
|
constexpr constant float const_n0_50f = -0.5;
|
|
constexpr constant float const_0_05f = 0.05;
|
|
constexpr constant type9 c_ambient = type9(const_0_05f, const_0_05f, const_0_05f);
|
|
constexpr constant unsigned c_max_lights = 10u;
|
|
constexpr constant unsigned const_0u = 0u;
|
|
constexpr constant unsigned const_1u = 1u;
|
|
type7 fetch_shadow(
|
|
type6 light_id,
|
|
type2 homogeneous_coords,
|
|
type4 t_shadow,
|
|
type5 sampler_shadow
|
|
) {
|
|
if ((homogeneous_coords.w <= const_0f)) {
|
|
return const_1f;
|
|
}
|
|
float expr15 = (const_1f / homogeneous_coords.w);
|
|
return t_shadow.sample_compare(sampler_shadow, (((metal::float2(homogeneous_coords.x, homogeneous_coords.y) * metal::float2(const_0_50f, const_n0_50f)) * expr15) + metal::float2(const_0_50f, const_0_50f)), static_cast<int>(light_id), (homogeneous_coords.z * expr15));
|
|
}
|
|
|
|
struct fs_mainInput {
|
|
type9 in_normal_fs [[user(loc0)]];
|
|
type2 in_position_fs [[user(loc1)]];
|
|
};
|
|
|
|
struct fs_mainOutput {
|
|
type2 out_color_fs [[color(0)]];
|
|
};
|
|
|
|
fragment fs_mainOutput fs_main(
|
|
fs_mainInput input [[stage_in]],
|
|
constant Globals& u_globals [[buffer(0)]],
|
|
constant Lights& s_lights [[buffer(1)]],
|
|
type4 t_shadow [[texture(0)]],
|
|
type5 sampler_shadow [[sampler(0)]]
|
|
) {
|
|
fs_mainOutput output;
|
|
type9 color1 = c_ambient;
|
|
type6 i = const_0u;
|
|
bool loop_init = true;
|
|
while(true) {
|
|
if (!loop_init) {
|
|
i = (i + const_1u);
|
|
}
|
|
loop_init = false;
|
|
if ((i >= metal::min(u_globals.num_lights.x, c_max_lights))) {
|
|
break;
|
|
}
|
|
Light expr18 = s_lights.data[i];
|
|
type7 expr21 = fetch_shadow(i, (expr18.proj * input.in_position_fs), t_shadow, sampler_shadow);
|
|
color1 = (color1 + ((expr21 * metal::max(const_0f, metal::dot(metal::normalize(input.in_normal_fs), metal::normalize((metal::float3(expr18.pos.x, expr18.pos.y, expr18.pos.z) - metal::float3(input.in_position_fs.x, input.in_position_fs.y, input.in_position_fs.z)))))) * metal::float3(expr18.color.x, expr18.color.y, expr18.color.z)));
|
|
}
|
|
output.out_color_fs = metal::float4(color1, const_1f);
|
|
return output;
|
|
}
|
|
|