gles-compatibility-layer/src/shaders/es2/main.fsh

51 lines
1.4 KiB
Plaintext
Raw Normal View History

2023-09-08 01:17:21 +00:00
#version 100
2023-08-05 01:58:43 +00:00
precision highp float;
// Texture
uniform bool u_has_texture;
uniform sampler2D u_texture_unit;
// Color
2023-09-08 01:17:21 +00:00
varying vec4 v_color;
varying vec4 v_texture_pos;
2023-08-05 01:58:43 +00:00
// Highlight Mode
uniform bool u_highlight_mode;
uniform vec4 u_highlight_mode_color;
// Alpha Test
uniform bool u_alpha_test;
// Fog
uniform bool u_fog;
uniform vec4 u_fog_color;
uniform bool u_fog_is_linear;
uniform float u_fog_start;
uniform float u_fog_end;
2023-09-08 01:17:21 +00:00
varying vec4 v_fog_eye_position;
2023-08-05 01:58:43 +00:00
// Main
void main(void) {
2023-09-08 01:17:21 +00:00
gl_FragColor = v_color;
2023-08-05 01:58:43 +00:00
// Texture
if (u_has_texture) {
vec4 texture_color = texture(u_texture_unit, v_texture_pos.xy);
if (u_highlight_mode) {
texture_color.rgb = u_highlight_mode_color.rgb;
texture_color.a *= u_highlight_mode_color.a;
2023-09-08 01:17:21 +00:00
gl_FragColor = texture_color;
2023-08-05 01:58:43 +00:00
} else {
2023-09-08 01:17:21 +00:00
gl_FragColor *= texture_color;
2023-08-05 01:58:43 +00:00
}
}
// Fog
if (u_fog) {
float fog_factor;
if (u_fog_is_linear) {
fog_factor = (u_fog_end - length(v_fog_eye_position)) / (u_fog_end - u_fog_start);
} else {
fog_factor = exp(-u_fog_start * length(v_fog_eye_position));
}
fog_factor = clamp(fog_factor, 0.0, 1.0);
2023-09-08 01:17:21 +00:00
gl_FragColor.rgb = mix(gl_FragColor, u_fog_color, 1.0 - fog_factor).rgb;
2023-08-05 01:58:43 +00:00
}
// Alpha Test
2023-09-08 01:17:21 +00:00
if (u_alpha_test && gl_FragColor.a <= 0.1) {
2023-08-05 01:58:43 +00:00
discard;
}
}