1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <metal_stdlib>
using namespace metal;
struct Params {
float bias;
};
struct _fs_main_Input {
float2 uv [[user(locn0)]];
float2 shadow_uv [[user(locn1)]];
};
struct _fs_main_Output {
float4 _value [[user(locn0)]];
};
fragment _fs_main_Output fs_main(_fs_main_Input input [[stage_in]],
constant Params& params [[buffer(0)]],
texture2d<float> diffuse_tex_tex [[texture(0)]],
sampler diffuse_tex_samp [[sampler(0)]],
depth2d<float> shadow_map_tex [[texture(1)]],
sampler shadow_map_samp [[sampler(1)]]) {
_fs_main_Output __luma_output;
float4 mip_color = diffuse_tex_tex.sample(diffuse_tex_samp, input.uv, level(params.bias));
float shadow = shadow_map_tex.sample_compare(shadow_map_samp, input.shadow_uv, 0.5);
__luma_output._value = float4((mip_color.rgb * shadow), mip_color.a);
return __luma_output;
}