tweak renderer API
This commit is contained in:
parent
177e52b0d0
commit
2014c67bfd
10 changed files with 424 additions and 247 deletions
21
resources/shaders/source/font.frag.glsl
Normal file
21
resources/shaders/source/font.frag.glsl
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#version 450
|
||||
|
||||
layout(set = 3, binding = 0) uniform Viewport {
|
||||
ivec2 view;
|
||||
};
|
||||
layout(set = 2, binding = 0) uniform sampler2D tx;
|
||||
|
||||
layout(location = 0) in vec2 uv;
|
||||
layout(location = 1) in vec4 color;
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
ivec2 ts = textureSize(tx, 0);
|
||||
vec2 fts = vec2(float(ts.x), float(ts.y));
|
||||
vec2 real_uv = uv / fts;
|
||||
|
||||
vec4 opacity = texture(tx, real_uv);
|
||||
fragColor = vec4(color.rgb, color.a*opacity.r);
|
||||
}
|
||||
35
resources/shaders/source/msdf.frag.glsl
Normal file
35
resources/shaders/source/msdf.frag.glsl
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#version 450
|
||||
|
||||
layout(set = 3, binding = 0) uniform Viewport {
|
||||
ivec2 view;
|
||||
};
|
||||
layout(set = 2, binding = 0) uniform sampler2D tx;
|
||||
|
||||
const float PX_RANGE = 4.0f;
|
||||
|
||||
layout(location = 0) in vec2 uv;
|
||||
layout(location = 1) in vec4 color;
|
||||
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
|
||||
float screen_px_range(vec2 uv) {
|
||||
vec2 unit_range = vec2(PX_RANGE)/vec2(textureSize(tx, 0));
|
||||
vec2 texel_size = vec2(1.0)/fwidth(uv);
|
||||
return max(0.5*dot(unit_range, texel_size), 1.0);
|
||||
}
|
||||
|
||||
float median(float r, float g, float b) {
|
||||
return max(min(r, g), min(max(r, g), b));
|
||||
}
|
||||
|
||||
void main() {
|
||||
ivec2 ts = textureSize(tx, 0);
|
||||
vec2 fts = vec2(float(ts.x), float(ts.y));
|
||||
vec2 real_uv = uv / fts;
|
||||
|
||||
vec3 msd = texture(tx, real_uv).rgb;
|
||||
float sd = median(msd.r, msd.g, msd.b);
|
||||
float distance = screen_px_range(real_uv)*(sd - 0.5);
|
||||
float opacity = clamp(distance + 0.5, 0.0, 1.0);
|
||||
fragColor = color * opacity;
|
||||
}
|
||||
|
|
@ -1,5 +1,9 @@
|
|||
#version 450
|
||||
|
||||
layout(set = 3, binding = 0) uniform Viewport {
|
||||
ivec2 view;
|
||||
};
|
||||
|
||||
layout(location = 0) in vec4 color;
|
||||
layout(location = 1) in vec2 local_position;
|
||||
layout(location = 2) in vec2 global_position;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
layout(set = 1, binding = 0) uniform Viewport {
|
||||
ivec2 view;
|
||||
ivec2 off;
|
||||
};
|
||||
|
||||
layout(location = 0) in ivec2 position;
|
||||
|
|
@ -16,17 +15,12 @@ layout(location = 3) out float radius;
|
|||
|
||||
void main()
|
||||
{
|
||||
// per vertex shift
|
||||
vec2 shift;
|
||||
shift.x = float(off.x) / view.x;
|
||||
shift.y = -(float(off.y) / view.y);
|
||||
|
||||
// vertex position
|
||||
vec2 pos;
|
||||
pos.x = float(position.x)*2.0 / view.x - 1.0;
|
||||
pos.y = -(float(position.y)*2.0 / view.y - 1.0);
|
||||
|
||||
gl_Position = vec4(pos+shift, 0.0, 1.0);
|
||||
gl_Position = vec4(pos, 0.0, 1.0);
|
||||
|
||||
local_position = vec2(sign(uv));
|
||||
global_position = gl_Position.xy;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
#version 450
|
||||
|
||||
layout(set = 3, binding = 0) uniform Viewport {
|
||||
ivec2 view;
|
||||
};
|
||||
|
||||
layout(location = 0) in vec2 uv;
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
layout(set = 1, binding = 0) uniform Viewport {
|
||||
ivec2 view;
|
||||
ivec2 not_needed;
|
||||
};
|
||||
|
||||
layout(location = 0) in ivec2 position;
|
||||
|
|
@ -10,6 +9,7 @@ layout(location = 1) in ivec2 in_uv;
|
|||
layout(location = 2) in ivec4 color;
|
||||
|
||||
layout(location = 0) out vec2 out_uv;
|
||||
layout(location = 1) out vec4 out_color;
|
||||
|
||||
void main()
|
||||
{
|
||||
|
|
@ -19,4 +19,5 @@ void main()
|
|||
gl_Position = vec4(pos, 0.0, 1.0);
|
||||
|
||||
out_uv = vec2(float(in_uv.x), float(in_uv.y));
|
||||
out_color = vec4(color) / 255.0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue