cakefoot/src/shaders/shader.frag

32 lines
1.2 KiB
GLSL

#version 300 es
/* >> Cakefoot by https://foam.shampoo.ooo/ << */
/* The precision declaration is required by OpenGL ES */
precision mediump float;
in vec2 fragment_uv;
in vec4 ex_color;
uniform sampler2D model_texture;
uniform int uv_transformation;
uniform float coordinate_bound;
uniform bool texture_enabled;
uniform vec4 color_addition;
out vec4 output_color;
void main()
{
/* Use the input flag to modify the color output. If the flag is enabled, the texture value will be used. Otherwise, the color value will
* be used.
*
* Not sure why the micro adjustment to the UV value is necessary. Without it, the texture is displayed with missing pixels when positioned
* at its start point. Something related to reading the texel at the boundary versus the center. But adjusting the UV into the center of the
* texels causes pixels at the borders to display incorrectly. Maybe related to half pixel adjustment https://gamedev.stackexchange.com/a/49585
*/
// output_color = float(texture_enabled) * texture(model_texture, fragment_uv + 0.00001);
output_color = float(texture_enabled) * (texture(model_texture, fragment_uv) + color_addition);
output_color += (1.0 - float(texture_enabled)) * (ex_color + color_addition);
}