#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

// Vulkan-specific uniform block for scale
#ifdef VULKAN
layout(set = 1, binding = 1) uniform ufBlock
{
    uniform vec4 uf_fragCoordScale;
};
#else
// OpenGL uniform for scale
uniform vec2 uf_fragCoordScale;
#endif

// Texture Sampler Bindings
TEXTURE_LAYOUT(0, 1, 0) uniform sampler2D textureUnitPS0;
TEXTURE_LAYOUT(1, 1, 1) uniform sampler2D textureUnitPS1;

// Input/Output for vertex to fragment
layout(location = 0) in vec4 passParameterSem133;
layout(location = 1) in vec4 passParameterSem134;
layout(location = 2) in vec4 passParameterSem135;
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;
}

// Main Function
void main() {
    // Export the calculated color value (currently from R5f)
    passPixelColor0 = vec4(R5f.x, R5f.y, R5f.z, R5f.w);
}
