| 1 |
#pragma clang diagnostic ignored "-Wmissing-prototypes" |
| 2 |
#pragma clang diagnostic ignored "-Wmissing-braces" |
| 3 |
|
| 4 |
#include <metal_stdlib> |
| 5 |
#include <simd/simd.h> |
| 6 |
|
| 7 |
using namespace metal; |
| 8 |
|
| 9 |
template<typename T, size_t Num> |
| 10 |
struct spvUnsafeArray |
| 11 |
{ |
| 12 |
T elements[Num ? Num : 1]; |
| 13 |
|
| 14 |
thread T& operator [] (size_t pos) thread |
| 15 |
{ |
| 16 |
return elements[pos]; |
| 17 |
} |
| 18 |
constexpr const thread T& operator [] (size_t pos) const thread |
| 19 |
{ |
| 20 |
return elements[pos]; |
| 21 |
} |
| 22 |
|
| 23 |
device T& operator [] (size_t pos) device |
| 24 |
{ |
| 25 |
return elements[pos]; |
| 26 |
} |
| 27 |
constexpr const device T& operator [] (size_t pos) const device |
| 28 |
{ |
| 29 |
return elements[pos]; |
| 30 |
} |
| 31 |
|
| 32 |
constexpr const constant T& operator [] (size_t pos) const constant |
| 33 |
{ |
| 34 |
return elements[pos]; |
| 35 |
} |
| 36 |
|
| 37 |
threadgroup T& operator [] (size_t pos) threadgroup |
| 38 |
{ |
| 39 |
return elements[pos]; |
| 40 |
} |
| 41 |
constexpr const threadgroup T& operator [] (size_t pos) const threadgroup |
| 42 |
{ |
| 43 |
return elements[pos]; |
| 44 |
} |
| 45 |
}; |
| 46 |
|
| 47 |
struct type_View |
| 48 |
{ |
| 49 |
float4x4 View_TranslatedWorldToClip; |
| 50 |
float4x4 View_WorldToClip; |
| 51 |
float4x4 View_ClipToWorld; |
| 52 |
float4x4 View_TranslatedWorldToView; |
| 53 |
float4x4 View_ViewToTranslatedWorld; |
| 54 |
float4x4 View_TranslatedWorldToCameraView; |
| 55 |
float4x4 View_CameraViewToTranslatedWorld; |
| 56 |
float4x4 View_ViewToClip; |
| 57 |
float4x4 View_ViewToClipNoAA; |
| 58 |
float4x4 View_ClipToView; |
| 59 |
float4x4 View_ClipToTranslatedWorld; |
| 60 |
float4x4 View_SVPositionToTranslatedWorld; |
| 61 |
float4x4 View_ScreenToWorld; |
| 62 |
float4x4 View_ScreenToTranslatedWorld; |
| 63 |
packed_float3 View_ViewForward; |
| 64 |
float PrePadding_View_908; |
| 65 |
packed_float3 View_ViewUp; |
| 66 |
float PrePadding_View_924; |
| 67 |
packed_float3 View_ViewRight; |
| 68 |
float PrePadding_View_940; |
| 69 |
packed_float3 View_HMDViewNoRollUp; |
| 70 |
float PrePadding_View_956; |
| 71 |
packed_float3 View_HMDViewNoRollRight; |
| 72 |
float PrePadding_View_972; |
| 73 |
float4 View_InvDeviceZToWorldZTransform; |
| 74 |
float4 View_ScreenPositionScaleBias; |
| 75 |
packed_float3 View_WorldCameraOrigin; |
| 76 |
float PrePadding_View_1020; |
| 77 |
packed_float3 View_TranslatedWorldCameraOrigin; |
| 78 |
float PrePadding_View_1036; |
| 79 |
packed_float3 View_WorldViewOrigin; |
| 80 |
float PrePadding_View_1052; |
| 81 |
packed_float3 View_PreViewTranslation; |
| 82 |
float PrePadding_View_1068; |
| 83 |
float4x4 View_PrevProjection; |
| 84 |
float4x4 View_PrevViewProj; |
| 85 |
float4x4 View_PrevViewRotationProj; |
| 86 |
float4x4 View_PrevViewToClip; |
| 87 |
float4x4 View_PrevClipToView; |
| 88 |
float4x4 View_PrevTranslatedWorldToClip; |
| 89 |
float4x4 View_PrevTranslatedWorldToView; |
| 90 |
float4x4 View_PrevViewToTranslatedWorld; |
| 91 |
float4x4 View_PrevTranslatedWorldToCameraView; |
| 92 |
float4x4 View_PrevCameraViewToTranslatedWorld; |
| 93 |
packed_float3 View_PrevWorldCameraOrigin; |
| 94 |
float PrePadding_View_1724; |
| 95 |
packed_float3 View_PrevWorldViewOrigin; |
| 96 |
float PrePadding_View_1740; |
| 97 |
packed_float3 View_PrevPreViewTranslation; |
| 98 |
float PrePadding_View_1756; |
| 99 |
float4x4 View_PrevInvViewProj; |
| 100 |
float4x4 View_PrevScreenToTranslatedWorld; |
| 101 |
float4x4 View_ClipToPrevClip; |
| 102 |
float4 View_TemporalAAJitter; |
| 103 |
float4 View_GlobalClippingPlane; |
| 104 |
float2 View_FieldOfViewWideAngles; |
| 105 |
float2 View_PrevFieldOfViewWideAngles; |
| 106 |
float4 View_ViewRectMin; |
| 107 |
float4 View_ViewSizeAndInvSize; |
| 108 |
float4 View_BufferSizeAndInvSize; |
| 109 |
float4 View_BufferBilinearUVMinMax; |
| 110 |
int View_NumSceneColorMSAASamples; |
| 111 |
float View_PreExposure; |
| 112 |
float View_OneOverPreExposure; |
| 113 |
float PrePadding_View_2076; |
| 114 |
float4 View_DiffuseOverrideParameter; |
| 115 |
float4 View_SpecularOverrideParameter; |
| 116 |
float4 View_NormalOverrideParameter; |
| 117 |
float2 View_RoughnessOverrideParameter; |
| 118 |
float View_PrevFrameGameTime; |
| 119 |
float View_PrevFrameRealTime; |
| 120 |
float View_OutOfBoundsMask; |
| 121 |
float PrePadding_View_2148; |
| 122 |
float PrePadding_View_2152; |
| 123 |
float PrePadding_View_2156; |
| 124 |
packed_float3 View_WorldCameraMovementSinceLastFrame; |
| 125 |
float View_CullingSign; |
| 126 |
float View_NearPlane; |
| 127 |
float View_AdaptiveTessellationFactor; |
| 128 |
float View_GameTime; |
| 129 |
float View_RealTime; |
| 130 |
float View_DeltaTime; |
| 131 |
float View_MaterialTextureMipBias; |
| 132 |
float View_MaterialTextureDerivativeMultiply; |
| 133 |
uint View_Random; |
| 134 |
uint View_FrameNumber; |
| 135 |
uint View_StateFrameIndexMod8; |
| 136 |
uint View_StateFrameIndex; |
| 137 |
float View_CameraCut; |
| 138 |
float View_UnlitViewmodeMask; |
| 139 |
float PrePadding_View_2228; |
| 140 |
float PrePadding_View_2232; |
| 141 |
float PrePadding_View_2236; |
| 142 |
float4 View_DirectionalLightColor; |
| 143 |
packed_float3 View_DirectionalLightDirection; |
| 144 |
float PrePadding_View_2268; |
| 145 |
float4 View_TranslucencyLightingVolumeMin[2]; |
| 146 |
float4 View_TranslucencyLightingVolumeInvSize[2]; |
| 147 |
float4 View_TemporalAAParams; |
| 148 |
float4 View_CircleDOFParams; |
| 149 |
float View_DepthOfFieldSensorWidth; |
| 150 |
float View_DepthOfFieldFocalDistance; |
| 151 |
float View_DepthOfFieldScale; |
| 152 |
float View_DepthOfFieldFocalLength; |
| 153 |
float View_DepthOfFieldFocalRegion; |
| 154 |
float View_DepthOfFieldNearTransitionRegion; |
| 155 |
float View_DepthOfFieldFarTransitionRegion; |
| 156 |
float View_MotionBlurNormalizedToPixel; |
| 157 |
float View_bSubsurfacePostprocessEnabled; |
| 158 |
float View_GeneralPurposeTweak; |
| 159 |
float View_DemosaicVposOffset; |
| 160 |
float PrePadding_View_2412; |
| 161 |
packed_float3 View_IndirectLightingColorScale; |
| 162 |
float View_HDR32bppEncodingMode; |
| 163 |
packed_float3 View_AtmosphericFogSunDirection; |
| 164 |
float View_AtmosphericFogSunPower; |
| 165 |
float View_AtmosphericFogPower; |
| 166 |
float View_AtmosphericFogDensityScale; |
| 167 |
float View_AtmosphericFogDensityOffset; |
| 168 |
float View_AtmosphericFogGroundOffset; |
| 169 |
float View_AtmosphericFogDistanceScale; |
| 170 |
float View_AtmosphericFogAltitudeScale; |
| 171 |
float View_AtmosphericFogHeightScaleRayleigh; |
| 172 |
float View_AtmosphericFogStartDistance; |
| 173 |
float View_AtmosphericFogDistanceOffset; |
| 174 |
float View_AtmosphericFogSunDiscScale; |
| 175 |
float View_AtmosphericFogSunDiscHalfApexAngleRadian; |
| 176 |
float PrePadding_View_2492; |
| 177 |
float4 View_AtmosphericFogSunDiscLuminance; |
| 178 |
uint View_AtmosphericFogRenderMask; |
| 179 |
uint View_AtmosphericFogInscatterAltitudeSampleNum; |
| 180 |
uint PrePadding_View_2520; |
| 181 |
uint PrePadding_View_2524; |
| 182 |
float4 View_AtmosphericFogSunColor; |
| 183 |
packed_float3 View_NormalCurvatureToRoughnessScaleBias; |
| 184 |
float View_RenderingReflectionCaptureMask; |
| 185 |
float4 View_AmbientCubemapTint; |
| 186 |
float View_AmbientCubemapIntensity; |
| 187 |
float View_SkyLightParameters; |
| 188 |
float PrePadding_View_2584; |
| 189 |
float PrePadding_View_2588; |
| 190 |
float4 View_SkyLightColor; |
| 191 |
float4 View_SkyIrradianceEnvironmentMap[7]; |
| 192 |
float View_MobilePreviewMode; |
| 193 |
float View_HMDEyePaddingOffset; |
| 194 |
float View_ReflectionCubemapMaxMip; |
| 195 |
float View_ShowDecalsMask; |
| 196 |
uint View_DistanceFieldAOSpecularOcclusionMode; |
| 197 |
float View_IndirectCapsuleSelfShadowingIntensity; |
| 198 |
float PrePadding_View_2744; |
| 199 |
float PrePadding_View_2748; |
| 200 |
packed_float3 View_ReflectionEnvironmentRoughnessMixingScaleBiasAndLargestWeight; |
| 201 |
int View_StereoPassIndex; |
| 202 |
float4 View_GlobalVolumeCenterAndExtent[4]; |
| 203 |
float4 View_GlobalVolumeWorldToUVAddAndMul[4]; |
| 204 |
float View_GlobalVolumeDimension; |
| 205 |
float View_GlobalVolumeTexelSize; |
| 206 |
float View_MaxGlobalDistance; |
| 207 |
float PrePadding_View_2908; |
| 208 |
int2 View_CursorPosition; |
| 209 |
float View_bCheckerboardSubsurfaceProfileRendering; |
| 210 |
float PrePadding_View_2924; |
| 211 |
packed_float3 View_VolumetricFogInvGridSize; |
| 212 |
float PrePadding_View_2940; |
| 213 |
packed_float3 View_VolumetricFogGridZParams; |
| 214 |
float PrePadding_View_2956; |
| 215 |
float2 View_VolumetricFogSVPosToVolumeUV; |
| 216 |
float View_VolumetricFogMaxDistance; |
| 217 |
float PrePadding_View_2972; |
| 218 |
packed_float3 View_VolumetricLightmapWorldToUVScale; |
| 219 |
float PrePadding_View_2988; |
| 220 |
packed_float3 View_VolumetricLightmapWorldToUVAdd; |
| 221 |
float PrePadding_View_3004; |
| 222 |
packed_float3 View_VolumetricLightmapIndirectionTextureSize; |
| 223 |
float View_VolumetricLightmapBrickSize; |
| 224 |
packed_float3 View_VolumetricLightmapBrickTexelSize; |
| 225 |
float View_StereoIPD; |
| 226 |
float View_IndirectLightingCacheShowFlag; |
| 227 |
float View_EyeToPixelSpreadAngle; |
| 228 |
}; |
| 229 |
|
| 230 |
struct type_PrimitiveDither |
| 231 |
{ |
| 232 |
float PrimitiveDither_LODFactor; |
| 233 |
}; |
| 234 |
|
| 235 |
struct type_PrimitiveFade |
| 236 |
{ |
| 237 |
float2 PrimitiveFade_FadeTimeScaleBias; |
| 238 |
}; |
| 239 |
|
| 240 |
struct type_Material |
| 241 |
{ |
| 242 |
float4 Material_VectorExpressions[9]; |
| 243 |
float4 Material_ScalarExpressions[3]; |
| 244 |
}; |
| 245 |
|
| 246 |
constant float _98 = {}; |
| 247 |
constant float _103 = {}; |
| 248 |
|
| 249 |
struct main0_out |
| 250 |
{ |
| 251 |
float4 out_var_SV_Target0 [[color(0)]]; |
| 252 |
float gl_FragDepth [[depth(less)]]; |
| 253 |
}; |
| 254 |
|
| 255 |
struct main0_in |
| 256 |
{ |
| 257 |
float4 in_var_TEXCOORD6 [[user(locn0)]]; |
| 258 |
float4 in_var_TEXCOORD7 [[user(locn1)]]; |
| 259 |
float4 in_var_TEXCOORD10_centroid [[user(locn2)]]; |
| 260 |
float4 in_var_TEXCOORD11_centroid [[user(locn3)]]; |
| 261 |
float4 in_var_TEXCOORD0_0 [[user(locn4)]]; |
| 262 |
}; |
| 263 |
|
| 264 |
fragment main0_out main0(main0_in in [[stage_in]], constant type_View& View [[buffer(0)]], constant type_PrimitiveDither& PrimitiveDither [[buffer(1)]], constant type_PrimitiveFade& PrimitiveFade [[buffer(2)]], constant type_Material& Material [[buffer(3)]], texture2d<float> Material_Texture2D_0 [[texture(0)]], texture2d<float> Material_Texture2D_3 [[texture(1)]], sampler Material_Texture2D_0Sampler [[sampler(0)]], sampler Material_Texture2D_3Sampler [[sampler(1)]], float4 gl_FragCoord [[position]]) |
| 265 |
{ |
| 266 |
main0_out out = {}; |
| 267 |
spvUnsafeArray<float4, 1> in_var_TEXCOORD0 = {}; |
| 268 |
in_var_TEXCOORD0[0] = in.in_var_TEXCOORD0_0; |
| 269 |
float2 _135 = gl_FragCoord.xy - View.View_ViewRectMin.xy; |
| 270 |
float4 _140 = float4(_103, _103, gl_FragCoord.z, 1.0) * float4(gl_FragCoord.w); |
| 271 |
float4 _144 = View.View_SVPositionToTranslatedWorld * float4(gl_FragCoord.xyz, 1.0); |
| 272 |
float3 _148 = _144.xyz / float3(_144.w); |
| 273 |
float3 _149 = _148 - float3(View.View_PreViewTranslation); |
| 274 |
float3 _151 = normalize(-_148); |
| 275 |
float3 _152 = _151 * float3x3(in.in_var_TEXCOORD10_centroid.xyz, cross(in.in_var_TEXCOORD11_centroid.xyz, in.in_var_TEXCOORD10_centroid.xyz) * float3(in.in_var_TEXCOORD11_centroid.w), in.in_var_TEXCOORD11_centroid.xyz); |
| 276 |
float _170 = mix(Material.Material_ScalarExpressions[0].y, Material.Material_ScalarExpressions[0].z, fast::min(fast::max(abs(dot(_151, in.in_var_TEXCOORD11_centroid.xyz)), 0.0), 1.0)); |
| 277 |
float _171 = floor(_170); |
| 278 |
float _172 = 1.0 / _170; |
| 279 |
float2 _174 = (float2(Material.Material_ScalarExpressions[0].x) * ((_152.xy * float2(-1.0)) / float2(_152.z))) * float2(_172); |
| 280 |
float2 _175 = dfdx(float2(in_var_TEXCOORD0[0].x, in_var_TEXCOORD0[0].y)); |
| 281 |
float2 _176 = dfdy(float2(in_var_TEXCOORD0[0].x, in_var_TEXCOORD0[0].y)); |
| 282 |
float _180_copy; |
| 283 |
float2 _183; |
| 284 |
_183 = float2(0.0); |
| 285 |
float _188; |
| 286 |
float _211; |
| 287 |
float2 _212; |
| 288 |
float _180 = 1.0; |
| 289 |
int _185 = 0; |
| 290 |
float _187 = 1.0; |
| 291 |
float _189 = 1.0; |
| 292 |
for (;;) |
| 293 |
{ |
| 294 |
if (float(_185) < (_171 + 2.0)) |
| 295 |
{ |
| 296 |
_188 = Material_Texture2D_0.sample(Material_Texture2D_0Sampler, (float2(in_var_TEXCOORD0[0].x, in_var_TEXCOORD0[0].y) + _183), gradient2d(_175, _176)).y; |
| 297 |
if (_180 < _188) |
| 298 |
{ |
| 299 |
float _201 = _188 - _180; |
| 300 |
float _203 = _201 / ((_189 - _187) + _201); |
| 301 |
_211 = (_189 * _203) + (_180 * (1.0 - _203)); |
| 302 |
_212 = _183 - (float2(_203) * _174); |
| 303 |
break; |
| 304 |
} |
| 305 |
_180_copy = _180; |
| 306 |
_180 -= _172; |
| 307 |
_183 += _174; |
| 308 |
_185++; |
| 309 |
_187 = _188; |
| 310 |
_189 = _180_copy; |
| 311 |
continue; |
| 312 |
} |
| 313 |
else |
| 314 |
{ |
| 315 |
_211 = _98; |
| 316 |
_212 = _183; |
| 317 |
break; |
| 318 |
} |
| 319 |
} |
| 320 |
float4 _218 = Material_Texture2D_0.sample(Material_Texture2D_0Sampler, (float2(in_var_TEXCOORD0[0].x, in_var_TEXCOORD0[0].y) + _212.xy), bias(View.View_MaterialTextureMipBias)); |
| 321 |
float2 _229 = _135 + float2(View.View_TemporalAAParams.x); |
| 322 |
float _237 = float((uint(_229.x) + (2u * uint(_229.y))) % 5u); |
| 323 |
float2 _238 = _135 * float2(0.015625); |
| 324 |
float4 _242 = Material_Texture2D_3.sample(Material_Texture2D_3Sampler, _238, bias(View.View_MaterialTextureMipBias)); |
| 325 |
float4 _254 = Material_Texture2D_3.sample(Material_Texture2D_3Sampler, _238, bias(View.View_MaterialTextureMipBias)); |
| 326 |
float3 _272 = float3(_212, (1.0 - _211) * Material.Material_ScalarExpressions[0].x); |
| 327 |
float2 _275 = dfdx(float2(in_var_TEXCOORD0[0].x, in_var_TEXCOORD0[0].y)); |
| 328 |
float2 _276 = abs(_275); |
| 329 |
float3 _279 = dfdx(_149); |
| 330 |
float2 _283 = dfdy(float2(in_var_TEXCOORD0[0].x, in_var_TEXCOORD0[0].y)); |
| 331 |
float2 _284 = abs(_283); |
| 332 |
float3 _287 = dfdy(_149); |
| 333 |
if (PrimitiveDither.PrimitiveDither_LODFactor != 0.0) |
| 334 |
{ |
| 335 |
if (abs(PrimitiveDither.PrimitiveDither_LODFactor) > 0.001000000047497451305389404296875) |
| 336 |
{ |
| 337 |
float _317 = fract(cos(dot(floor(gl_FragCoord.xy), float2(347.834503173828125, 3343.28369140625))) * 1000.0); |
| 338 |
if ((float((PrimitiveDither.PrimitiveDither_LODFactor < 0.0) ? ((PrimitiveDither.PrimitiveDither_LODFactor + 1.0) > _317) : (PrimitiveDither.PrimitiveDither_LODFactor < _317)) - 0.001000000047497451305389404296875) < 0.0) |
| 339 |
{ |
| 340 |
discard_fragment(); |
| 341 |
} |
| 342 |
} |
| 343 |
} |
| 344 |
if ((((_218.z + ((fast::min(fast::max(1.0 - (_218.x * Material.Material_ScalarExpressions[2].y), 0.0), 1.0) + ((_237 + (_242.x * Material.Material_ScalarExpressions[2].z)) * 0.16666667163372039794921875)) + (-0.5))) * ((fast::clamp((View.View_RealTime * PrimitiveFade.PrimitiveFade_FadeTimeScaleBias.x) + PrimitiveFade.PrimitiveFade_FadeTimeScaleBias.y, 0.0, 1.0) + ((_237 + _254.x) * 0.16666667163372039794921875)) + (-0.5))) - 0.33329999446868896484375) < 0.0) |
| 345 |
{ |
| 346 |
discard_fragment(); |
| 347 |
} |
| 348 |
float2 _351 = ((((in.in_var_TEXCOORD6.xy / float2(in.in_var_TEXCOORD6.w)) - View.View_TemporalAAJitter.xy) - ((in.in_var_TEXCOORD7.xy / float2(in.in_var_TEXCOORD7.w)) - View.View_TemporalAAJitter.zw)) * float2(0.2495000064373016357421875)) + float2(0.49999237060546875); |
| 349 |
out.gl_FragDepth = fast::min(_140.z / (_140.w + (sqrt(dot(_272, _272)) / (fast::max(sqrt(dot(_276, _276)) / sqrt(dot(_279, _279)), sqrt(dot(_284, _284)) / sqrt(dot(_287, _287))) / abs(dot(float3x3(View.View_ViewToTranslatedWorld[0].xyz, View.View_ViewToTranslatedWorld[1].xyz, View.View_ViewToTranslatedWorld[2].xyz) * float3(0.0, 0.0, 1.0), _151))))), gl_FragCoord.z); |
| 350 |
out.out_var_SV_Target0 = float4(_351.x, _351.y, float2(0.0).x, float2(0.0).y); |
| 351 |
return out; |
| 352 |
} |
| 353 |
|