2021-07-14 18:43:51 +00:00
|
|
|
#include <metal_stdlib>
|
|
|
|
|
|
|
|
using namespace metal;
|
2021-08-23 21:45:23 +00:00
|
|
|
|
|
|
|
template<typename T, int N, int M>
|
|
|
|
inline auto operator*(matrix<T, N, M> lhs, packed_vec<T, N> rhs) {
|
|
|
|
return lhs * vec<T, N>(rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T, int N, int M>
|
|
|
|
inline auto operator*(packed_vec<T, M> lhs, matrix<T, N, M> rhs) {
|
|
|
|
return vec<T, M>(lhs) * rhs;
|
|
|
|
}
|
|
|
|
|
2021-07-14 18:43:51 +00:00
|
|
|
struct S {
|
|
|
|
/* 0x0000 */ packed_float3 v;
|
|
|
|
/* 0x000c */ uint i;
|
|
|
|
};
|
|
|
|
|
|
|
|
float3 Bad(uint index, float3 rd) {
|
|
|
|
float3 normal = float3(0.0f);
|
|
|
|
normal[index] = -(sign(rd[index]));
|
|
|
|
return normalize(normal);
|
|
|
|
}
|
|
|
|
|
2021-08-04 22:15:28 +00:00
|
|
|
void tint_symbol_inner(device S& io, uint idx) {
|
2021-07-14 18:43:51 +00:00
|
|
|
io.v = Bad(io.i, io.v);
|
2021-08-04 22:15:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
kernel void tint_symbol(uint idx [[thread_index_in_threadgroup]], device S& io [[buffer(0)]]) {
|
|
|
|
tint_symbol_inner(io, idx);
|
2021-07-14 18:43:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|