cbuffer _125 { int2 _125_offset : packoffset(c0); int _125_level : packoffset(c0.z); }; Texture2D tex : register(t0); SamplerState _tex_sampler : register(s0); static float4 gl_FragCoord; static float4 fragColor; static float2 vUV; struct SPIRV_Cross_Input { float2 vUV : TEXCOORD0; float4 gl_FragCoord : SV_Position; }; struct SPIRV_Cross_Output { float4 fragColor : SV_Target0; }; float4 toLinear(float4 sRGB_A) { float a = sRGB_A.w; float rcpA = 1.0f / ((a != 0.0f) ? a : 1.0f); float3 sRGB = sRGB_A.xyz * rcpA; bool3 cutoff = bool3(sRGB.x < 0.040449999272823333740234375f.xxx.x, sRGB.y < 0.040449999272823333740234375f.xxx.y, sRGB.z < 0.040449999272823333740234375f.xxx.z); float3 higher = pow((abs(sRGB) + 0.054999999701976776123046875f.xxx) / 1.05499994754791259765625f.xxx, 2.400000095367431640625f.xxx); float3 lower = sRGB / 12.9200000762939453125f.xxx; return float4(float3(cutoff.x ? lower.x : higher.x, cutoff.y ? lower.y : higher.y, cutoff.z ? lower.z : higher.z) * a, a); } float4 fromLinear(float4 linearRGB_A) { float a = linearRGB_A.w; float rcpA = 1.0f / ((a != 0.0f) ? a : 1.0f); float3 linearRGB = linearRGB_A.xyz * rcpA; bool3 cutoff = bool3(linearRGB.x < 0.003130800090730190277099609375f.xxx.x, linearRGB.y < 0.003130800090730190277099609375f.xxx.y, linearRGB.z < 0.003130800090730190277099609375f.xxx.z); float3 higher = (1.05499994754791259765625f.xxx * pow(abs(linearRGB), 0.4166666567325592041015625f.xxx)) - 0.054999999701976776123046875f.xxx; float3 lower = linearRGB * 12.9200000762939453125f.xxx; return float4(float3(cutoff.x ? lower.x : higher.x, cutoff.y ? lower.y : higher.y, cutoff.z ? lower.z : higher.z) * a, a); } void frag_main() { int side = 1 << _125_level; float4 color = 0.0f.xxxx; int2 coord = (side.xx * int2(gl_FragCoord.xy)) + _125_offset; for (int y = 0; y < side; y++) { for (int x = 0; x < side; x++) { float4 t1 = tex.Load(int3(coord + int2(x, y), 0)); float4 param = t1; color += toLinear(param); } } float4 param_1 = color * (1.0f / float(side * side)); fragColor = fromLinear(param_1); } SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input) { gl_FragCoord = stage_input.gl_FragCoord; vUV = stage_input.vUV; frag_main(); SPIRV_Cross_Output stage_output; stage_output.fragColor = fragColor; return stage_output; }