/** * QUIK: User Interface Kit * Copyright (C) 2023 Halit Utku Maden, et al. */ #version 130 in vec2 fv2TexPos; in vec4 fv4Color; in float ffTexLayer; out vec4 fragColor; uniform int iEnableSdf; uniform int iEnableTexture; uniform int iAlphaDiscard; uniform float fSdfThreshold = 0.5; uniform sampler2D tx2d; const float fAlphaThreshold = 0.01; vec4 getTexture() { if (iEnableTexture == 3) { // return texture(tx2dArray, vec3(fv2TexPos, ffTexLayer)); } else if (iEnableSdf == 1) { vec2 texelSz = 1.0/vec2(textureSize(tx2d, 0)); vec2 txCoord2 = fv2TexPos + texelSz * (1 - mod(fv2TexPos, texelSz)); return texture(tx2d, txCoord2); } else { return texture(tx2d, fv2TexPos); } } void main(void) { vec4 albedo = fv4Color; if (iEnableTexture != 0) { vec4 value = getTexture(); if (iEnableSdf != 0) { value = vec4(vec3(1.0), smoothstep(fSdfThreshold-0.1, fSdfThreshold+0.1, value.r)); } if (iAlphaDiscard != 0 && value.a <= fAlphaThreshold) { discard; } albedo = albedo * value; } fragColor = albedo; }