| 1 |
#include <metal_stdlib> |
| 2 |
#include <simd/simd.h> |
| 3 |
|
| 4 |
using namespace metal; |
| 5 |
|
| 6 |
struct UBO |
| 7 |
{ |
| 8 |
float4 uScale; |
| 9 |
float3 uCamPos; |
| 10 |
float2 uPatchSize; |
| 11 |
float2 uMaxTessLevel; |
| 12 |
float uDistanceMod; |
| 13 |
float4 uFrustum[6]; |
| 14 |
}; |
| 15 |
|
| 16 |
struct main0_patchOut |
| 17 |
{ |
| 18 |
float2 vOutPatchPosBase; |
| 19 |
float4 vPatchLods; |
| 20 |
}; |
| 21 |
|
| 22 |
struct main0_in |
| 23 |
{ |
| 24 |
float2 vPatchPosBase [[attribute(0)]]; |
| 25 |
}; |
| 26 |
|
| 27 |
kernel void main0(main0_in in [[stage_in]], constant UBO& _41 [[buffer(0)]], uint gl_InvocationID [[thread_index_in_threadgroup]], uint gl_PrimitiveID [[threadgroup_position_in_grid]], constant uint* spvIndirectParams [[buffer(29)]], device main0_patchOut* spvPatchOut [[buffer(27)]], device MTLQuadTessellationFactorsHalf* spvTessLevel [[buffer(26)]], threadgroup main0_in* gl_in [[threadgroup(0)]]) |
| 28 |
{ |
| 29 |
device main0_patchOut& patchOut = spvPatchOut[gl_PrimitiveID]; |
| 30 |
if (gl_InvocationID < spvIndirectParams[0]) |
| 31 |
gl_in[gl_InvocationID] = in; |
| 32 |
threadgroup_barrier(mem_flags::mem_threadgroup); |
| 33 |
if (gl_InvocationID >= 1) |
| 34 |
return; |
| 35 |
float2 _431 = (gl_in[0].vPatchPosBase - float2(10.0)) * _41.uScale.xy; |
| 36 |
float2 _441 = ((gl_in[0].vPatchPosBase + _41.uPatchSize) + float2(10.0)) * _41.uScale.xy; |
| 37 |
float3 _446 = float3(_431.x, -10.0, _431.y); |
| 38 |
float3 _451 = float3(_441.x, 10.0, _441.y); |
| 39 |
float4 _467 = float4((_446 + _451) * 0.5, 1.0); |
| 40 |
float3 _514 = float3(length(_451 - _446) * (-0.5)); |
| 41 |
bool _516 = any(float3(dot(_41.uFrustum[0], _467), dot(_41.uFrustum[1], _467), dot(_41.uFrustum[2], _467)) <= _514); |
| 42 |
bool _526; |
| 43 |
if (!_516) |
| 44 |
{ |
| 45 |
_526 = any(float3(dot(_41.uFrustum[3], _467), dot(_41.uFrustum[4], _467), dot(_41.uFrustum[5], _467)) <= _514); |
| 46 |
} |
| 47 |
else |
| 48 |
{ |
| 49 |
_526 = _516; |
| 50 |
} |
| 51 |
if (!(!_526)) |
| 52 |
{ |
| 53 |
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[0] = half(-1.0); |
| 54 |
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[1] = half(-1.0); |
| 55 |
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[2] = half(-1.0); |
| 56 |
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[3] = half(-1.0); |
| 57 |
spvTessLevel[gl_PrimitiveID].insideTessellationFactor[0] = half(-1.0); |
| 58 |
spvTessLevel[gl_PrimitiveID].insideTessellationFactor[1] = half(-1.0); |
| 59 |
} |
| 60 |
else |
| 61 |
{ |
| 62 |
patchOut.vOutPatchPosBase = gl_in[0].vPatchPosBase; |
| 63 |
float2 _681 = (gl_in[0].vPatchPosBase + (float2(-0.5) * _41.uPatchSize)) * _41.uScale.xy; |
| 64 |
float2 _710 = (gl_in[0].vPatchPosBase + (float2(0.5, -0.5) * _41.uPatchSize)) * _41.uScale.xy; |
| 65 |
float _729 = fast::clamp(log2((length(_41.uCamPos - float3(_710.x, 0.0, _710.y)) + 9.9999997473787516355514526367188e-05) * _41.uDistanceMod), 0.0, _41.uMaxTessLevel.x); |
| 66 |
float2 _739 = (gl_in[0].vPatchPosBase + (float2(1.5, -0.5) * _41.uPatchSize)) * _41.uScale.xy; |
| 67 |
float2 _768 = (gl_in[0].vPatchPosBase + (float2(-0.5, 0.5) * _41.uPatchSize)) * _41.uScale.xy; |
| 68 |
float _787 = fast::clamp(log2((length(_41.uCamPos - float3(_768.x, 0.0, _768.y)) + 9.9999997473787516355514526367188e-05) * _41.uDistanceMod), 0.0, _41.uMaxTessLevel.x); |
| 69 |
float2 _797 = (gl_in[0].vPatchPosBase + (float2(0.5) * _41.uPatchSize)) * _41.uScale.xy; |
| 70 |
float _816 = fast::clamp(log2((length(_41.uCamPos - float3(_797.x, 0.0, _797.y)) + 9.9999997473787516355514526367188e-05) * _41.uDistanceMod), 0.0, _41.uMaxTessLevel.x); |
| 71 |
float2 _826 = (gl_in[0].vPatchPosBase + (float2(1.5, 0.5) * _41.uPatchSize)) * _41.uScale.xy; |
| 72 |
float _845 = fast::clamp(log2((length(_41.uCamPos - float3(_826.x, 0.0, _826.y)) + 9.9999997473787516355514526367188e-05) * _41.uDistanceMod), 0.0, _41.uMaxTessLevel.x); |
| 73 |
float2 _855 = (gl_in[0].vPatchPosBase + (float2(-0.5, 1.5) * _41.uPatchSize)) * _41.uScale.xy; |
| 74 |
float2 _884 = (gl_in[0].vPatchPosBase + (float2(0.5, 1.5) * _41.uPatchSize)) * _41.uScale.xy; |
| 75 |
float _903 = fast::clamp(log2((length(_41.uCamPos - float3(_884.x, 0.0, _884.y)) + 9.9999997473787516355514526367188e-05) * _41.uDistanceMod), 0.0, _41.uMaxTessLevel.x); |
| 76 |
float2 _913 = (gl_in[0].vPatchPosBase + (float2(1.5) * _41.uPatchSize)) * _41.uScale.xy; |
| 77 |
float _614 = dot(float4(_787, _816, fast::clamp(log2((length(_41.uCamPos - float3(_855.x, 0.0, _855.y)) + 9.9999997473787516355514526367188e-05) * _41.uDistanceMod), 0.0, _41.uMaxTessLevel.x), _903), float4(0.25)); |
| 78 |
float _620 = dot(float4(fast::clamp(log2((length(_41.uCamPos - float3(_681.x, 0.0, _681.y)) + 9.9999997473787516355514526367188e-05) * _41.uDistanceMod), 0.0, _41.uMaxTessLevel.x), _729, _787, _816), float4(0.25)); |
| 79 |
float _626 = dot(float4(_729, fast::clamp(log2((length(_41.uCamPos - float3(_739.x, 0.0, _739.y)) + 9.9999997473787516355514526367188e-05) * _41.uDistanceMod), 0.0, _41.uMaxTessLevel.x), _816, _845), float4(0.25)); |
| 80 |
float _632 = dot(float4(_816, _845, _903, fast::clamp(log2((length(_41.uCamPos - float3(_913.x, 0.0, _913.y)) + 9.9999997473787516355514526367188e-05) * _41.uDistanceMod), 0.0, _41.uMaxTessLevel.x)), float4(0.25)); |
| 81 |
float4 _633 = float4(_614, _620, _626, _632); |
| 82 |
patchOut.vPatchLods = _633; |
| 83 |
float4 _940 = exp2(-fast::min(_633, _633.yzwx)) * _41.uMaxTessLevel.y; |
| 84 |
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[0] = half(_940.x); |
| 85 |
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[1] = half(_940.y); |
| 86 |
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[2] = half(_940.z); |
| 87 |
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[3] = half(_940.w); |
| 88 |
float _948 = _41.uMaxTessLevel.y * exp2(-fast::min(fast::min(fast::min(_614, _620), fast::min(_626, _632)), _816)); |
| 89 |
spvTessLevel[gl_PrimitiveID].insideTessellationFactor[0] = half(_948); |
| 90 |
spvTessLevel[gl_PrimitiveID].insideTessellationFactor[1] = half(_948); |
| 91 |
} |
| 92 |
} |
| 93 |
|