Debian Codegraph @

third_party/spirv-cross/reference/shaders-msl/frag/texture-cube-array.ios.emulate-cube-array.frag

raw
1 #pragma clang diagnostic ignored "-Wmissing-prototypes"
2
3 #include <metal_stdlib>
4 #include <simd/simd.h>
5
6 using namespace metal;
7
8 struct main0_out
9 {
10 float4 FragColor [[color(0)]];
11 };
12
13 struct main0_in
14 {
15 float4 vUV [[user(locn0)]];
16 };
17
18 static inline __attribute__((always_inline))
19 float3 spvCubemapTo2DArrayFace(float3 P)
20 {
21 float3 Coords = abs(P.xyz);
22 float CubeFace = 0;
23 float ProjectionAxis = 0;
24 float u = 0;
25 float v = 0;
26 if (Coords.x >= Coords.y && Coords.x >= Coords.z)
27 {
28 CubeFace = P.x >= 0 ? 0 : 1;
29 ProjectionAxis = Coords.x;
30 u = P.x >= 0 ? -P.z : P.z;
31 v = -P.y;
32 }
33 else if (Coords.y >= Coords.x && Coords.y >= Coords.z)
34 {
35 CubeFace = P.y >= 0 ? 2 : 3;
36 ProjectionAxis = Coords.y;
37 u = P.x;
38 v = P.y >= 0 ? P.z : -P.z;
39 }
40 else
41 {
42 CubeFace = P.z >= 0 ? 4 : 5;
43 ProjectionAxis = Coords.z;
44 u = P.z >= 0 ? P.x : -P.x;
45 v = -P.y;
46 }
47 u = 0.5 * (u/ProjectionAxis + 1);
48 v = 0.5 * (v/ProjectionAxis + 1);
49 return float3(u, v, CubeFace);
50 }
51
52 fragment main0_out main0(main0_in in [[stage_in]], texturecube<float> cubeSampler [[texture(0)]], texture2d_array<float> cubeArraySampler [[texture(1)]], texture2d_array<float> texArraySampler [[texture(2)]], sampler cubeSamplerSmplr [[sampler(0)]], sampler cubeArraySamplerSmplr [[sampler(1)]], sampler texArraySamplerSmplr [[sampler(2)]])
53 {
54 main0_out out = {};
55 float4 a = cubeSampler.sample(cubeSamplerSmplr, in.vUV.xyz);
56 float4 b = cubeArraySampler.sample(cubeArraySamplerSmplr, spvCubemapTo2DArrayFace(in.vUV.xyz).xy, uint(spvCubemapTo2DArrayFace(in.vUV.xyz).z) + (uint(round(in.vUV.w)) * 6u));
57 float4 c = texArraySampler.sample(texArraySamplerSmplr, in.vUV.xyz.xy, uint(round(in.vUV.xyz.z)));
58 out.FragColor = (a + b) + c;
59 return out;
60 }
61