Use get_uniform_location for wider compatibility

This commit is contained in:
Héctor Ramón Jiménez 2020-05-22 05:52:11 +02:00
parent 1b287cddaf
commit 6f71a8e3d5
7 changed files with 93 additions and 48 deletions

View file

@ -1,15 +1,15 @@
#version 450
#version 330
layout(location = 2) uniform float u_Screen_Height;
uniform float u_ScreenHeight;
layout(location = 0) in vec4 v_Color;
layout(location = 1) in vec4 v_BorderColor;
layout(location = 2) in vec2 v_Pos;
layout(location = 3) in vec2 v_Scale;
layout(location = 4) in float v_BorderRadius;
layout(location = 5) in float v_BorderWidth;
in vec4 v_Color;
in vec4 v_BorderColor;
in vec2 v_Pos;
in vec2 v_Scale;
in float v_BorderRadius;
in float v_BorderWidth;
layout(location = 0) out vec4 o_Color;
out vec4 o_Color;
float distance(in vec2 frag_coord, in vec2 position, in vec2 size, float radius)
{
@ -22,8 +22,8 @@ float distance(in vec2 frag_coord, in vec2 position, in vec2 size, float radius)
vec2 bottom_right_distance = frag_coord - bottom_right;
vec2 distance = vec2(
max(max(top_left_distance.x, bottom_right_distance.x), 0),
max(max(top_left_distance.y, bottom_right_distance.y), 0)
max(max(top_left_distance.x, bottom_right_distance.x), 0.0),
max(max(top_left_distance.y, bottom_right_distance.y), 0.0)
);
return sqrt(distance.x * distance.x + distance.y * distance.y);
@ -32,11 +32,11 @@ float distance(in vec2 frag_coord, in vec2 position, in vec2 size, float radius)
void main() {
vec4 mixed_color;
vec2 fragCoord = vec2(gl_FragCoord.x, u_Screen_Height - gl_FragCoord.y);
vec2 fragCoord = vec2(gl_FragCoord.x, u_ScreenHeight - gl_FragCoord.y);
// TODO: Remove branching (?)
if(v_BorderWidth > 0) {
float internal_border = max(v_BorderRadius - v_BorderWidth, 0);
float internal_border = max(v_BorderRadius - v_BorderWidth, 0.0);
float internal_distance = distance(
fragCoord,
@ -64,7 +64,7 @@ void main() {
);
float radius_alpha =
1.0 - smoothstep(max(v_BorderRadius - 0.5, 0), v_BorderRadius + 0.5, d);
1.0 - smoothstep(max(v_BorderRadius - 0.5, 0.0), v_BorderRadius + 0.5, d);
o_Color = vec4(mixed_color.xyz, mixed_color.w * radius_alpha);
}