diff options
author | 2020-05-22 05:52:11 +0200 | |
---|---|---|
committer | 2020-05-22 05:55:28 +0200 | |
commit | 6f71a8e3d5e47ab05653315b0d44b35af6a20338 (patch) | |
tree | 57cbc1f7aa836b021da7ec1e1a05f86b63c35148 /glow/src/shader | |
parent | 1b287cddaf1951bbd65e60996eea6d356c131c1f (diff) | |
download | iced-6f71a8e3d5e47ab05653315b0d44b35af6a20338.tar.gz iced-6f71a8e3d5e47ab05653315b0d44b35af6a20338.tar.bz2 iced-6f71a8e3d5e47ab05653315b0d44b35af6a20338.zip |
Use `get_uniform_location` for wider compatibility
Diffstat (limited to 'glow/src/shader')
-rw-r--r-- | glow/src/shader/quad.frag | 28 | ||||
-rw-r--r-- | glow/src/shader/quad.vert | 34 | ||||
-rw-r--r-- | glow/src/shader/triangle.frag | 9 | ||||
-rw-r--r-- | glow/src/shader/triangle.vert | 8 |
4 files changed, 40 insertions, 39 deletions
diff --git a/glow/src/shader/quad.frag b/glow/src/shader/quad.frag index 17e7216f..cea36bdc 100644 --- a/glow/src/shader/quad.frag +++ b/glow/src/shader/quad.frag @@ -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); } diff --git a/glow/src/shader/quad.vert b/glow/src/shader/quad.vert index 2d2ebc3d..d37b5c8d 100644 --- a/glow/src/shader/quad.vert +++ b/glow/src/shader/quad.vert @@ -1,7 +1,7 @@ -#version 450 +#version 330 -layout(location = 0) uniform mat4 u_Transform; -layout(location = 1) uniform float u_Scale; +uniform mat4 u_Transform; +uniform float u_Scale; layout(location = 0) in vec2 i_Pos; layout(location = 1) in vec2 i_Scale; @@ -10,12 +10,12 @@ layout(location = 3) in vec4 i_BorderColor; layout(location = 4) in float i_BorderRadius; layout(location = 5) in float i_BorderWidth; -layout(location = 0) out vec4 o_Color; -layout(location = 1) out vec4 o_BorderColor; -layout(location = 2) out vec2 o_Pos; -layout(location = 3) out vec2 o_Scale; -layout(location = 4) out float o_BorderRadius; -layout(location = 5) out float o_BorderWidth; +out vec4 v_Color; +out vec4 v_BorderColor; +out vec2 v_Pos; +out vec2 v_Scale; +out float v_BorderRadius; +out float v_BorderWidth; const vec2 positions[4] = vec2[]( vec2(0.0, 0.0), @@ -25,7 +25,7 @@ const vec2 positions[4] = vec2[]( ); void main() { - vec2 v_Pos = positions[gl_VertexID]; + vec2 q_Pos = positions[gl_VertexID]; vec2 p_Pos = i_Pos * u_Scale; vec2 p_Scale = i_Scale * u_Scale; @@ -36,12 +36,12 @@ void main() { vec4(p_Pos - vec2(0.5, 0.5), 0.0, 1.0) ); - o_Color = i_Color; - o_BorderColor = i_BorderColor; - o_Pos = p_Pos; - o_Scale = p_Scale; - o_BorderRadius = i_BorderRadius * u_Scale; - o_BorderWidth = i_BorderWidth * u_Scale; + v_Color = i_Color; + v_BorderColor = i_BorderColor; + v_Pos = p_Pos; + v_Scale = p_Scale; + v_BorderRadius = i_BorderRadius * u_Scale; + v_BorderWidth = i_BorderWidth * u_Scale; - gl_Position = u_Transform * i_Transform * vec4(v_Pos, 0.0, 1.0); + gl_Position = u_Transform * i_Transform * vec4(q_Pos, 0.0, 1.0); } diff --git a/glow/src/shader/triangle.frag b/glow/src/shader/triangle.frag index e39c45e7..d186784a 100644 --- a/glow/src/shader/triangle.frag +++ b/glow/src/shader/triangle.frag @@ -1,8 +1,9 @@ -#version 450 +#version 330 -layout(location = 0) in vec4 i_Color; -layout(location = 0) out vec4 o_Color; +in vec4 v_Color; + +out vec4 o_Color; void main() { - o_Color = i_Color; + o_Color = v_Color; } diff --git a/glow/src/shader/triangle.vert b/glow/src/shader/triangle.vert index cfa4e995..5723436a 100644 --- a/glow/src/shader/triangle.vert +++ b/glow/src/shader/triangle.vert @@ -1,13 +1,13 @@ -#version 450 +#version 330 -layout(location = 0) uniform mat4 u_Transform; +uniform mat4 u_Transform; layout(location = 0) in vec2 i_Position; layout(location = 1) in vec4 i_Color; -layout(location = 0) out vec4 o_Color; +out vec4 v_Color; void main() { gl_Position = u_Transform * vec4(i_Position, 0.0, 1.0); - o_Color = i_Color; + v_Color = i_Color; } |