#version 430
#extension GL_ARB_texture_gather : enable
#extension GL_ARB_separate_shader_objects : enable

// shader %08x%08x
// start of shader inputs/outputs, predetermined by Cemu. Do not touch

#ifdef VULKAN
#define ATTR_LAYOUT(__vkSet, __location) layout(set = __vkSet, location = __location)
#define UNIFORM_BUFFER_LAYOUT(__glLocation, __vkSet, __vkLocation) layout(set = __vkSet, binding = __vkLocation, std140)
#define TEXTURE_LAYOUT(__glLocation, __vkSet, __vkLocation) layout(set = __vkSet, binding = __vkLocation)
#define GET_FRAGCOORD() vec4(gl_FragCoord.xy * uf_fragCoordScale.xy, gl_FragCoord.zw)
#else
#define ATTR_LAYOUT(__vkSet, __location) layout(location = __location)
#define UNIFORM_BUFFER_LAYOUT(__glLocation, __vkSet, __vkLocation) layout(binding = __glLocation, std140) 
#define TEXTURE_LAYOUT(__glLocation, __vkSet, __vkLocation) layout(binding = __glLocation)
#define GET_FRAGCOORD() vec4(gl_FragCoord.xy * uf_fragCoordScale, gl_FragCoord.zw)
#endif

#ifdef VULKAN
layout(set = 1, binding = 1) uniform ufBlock {
    uniform ivec4 uf_remappedPS[3];
    uniform vec4 uf_fragCoordScale;
};
#else
uniform ivec4 uf_remappedPS[3];
uniform vec2 uf_fragCoordScale;
#endif

TEXTURE_LAYOUT(0, 1, 0) uniform sampler2D textureUnitPS0;

layout(location = 0) in vec4 passParameterSem128;
layout(location = 1) in vec4 passParameterSem129;
layout(location = 0) out vec4 passPixelColor0;

// Helper functions
int clampFI32(int v) {
    if (v == 0x7FFFFFFF)
        return floatBitsToInt(1.0);
    else if (v == 0xFFFFFFFF)
        return floatBitsToInt(0.0);
    return floatBitsToInt(clamp(intBitsToFloat(v), 0.0, 1.0));
}

float mul_nonIEEE(float a, float b) {
    if (a == 0.0 || b == 0.0) return 0.0;
    return a * b;
}

void main() {
    // Final export
    passPixelColor0 = vec4(intBitsToFloat(R0i.x), intBitsToFloat(R0i.y), intBitsToFloat(R0i.z), intBitsToFloat(0.0));
}

