Add Font shader;

This commit is contained in:
bjorn 2022-06-20 18:17:37 -07:00
parent de6edaef31
commit 3df9aea3fd
5 changed files with 29 additions and 3 deletions

View File

@ -1,6 +1,8 @@
#include "shaders/unlit.vert.h"
#include "shaders/unlit.frag.h"
#include "shaders/font.frag.h"
#include "shaders/lovr.glsl.h"
#define LOCATION_POSITION 10

24
etc/shaders/font.frag Normal file
View File

@ -0,0 +1,24 @@
#version 460
#extension GL_EXT_multiview : require
#extension GL_GOOGLE_include_directive : require
#extension GL_EXT_samplerless_texture_functions : require
#include "lovr.glsl"
float screenPxRange() {
vec2 screenTexSize = vec2(1.) / fwidth(FragUV);
return max(.5 * dot(Material.sdfRange, screenTexSize), 1.);
}
float median(float r, float g, float b) {
return max(min(r, g), min(max(r, g), b));
}
void main() {
vec3 msdf = texture(sampler2D(Texture, Sampler), FragUV).rgb;
float sdf = median(msdf.r, msdf.g, msdf.b);
float screenPxDistance = screenPxRange() * (sdf - .5);
float alpha = clamp(screenPxDistance + .5, 0., 1.);
if (alpha <= 0.) discard;
PixelColors[0] = vec4(FragColor.rgb, alpha);
}

View File

@ -22,6 +22,7 @@ struct MaterialData {
vec4 glow;
vec2 uvShift;
vec2 uvScale;
vec2 sdfRange;
float metalness;
float roughness;
float clearcoat;
@ -31,7 +32,6 @@ struct MaterialData {
float normalScale;
float alphaCutoff;
float pointSize;
float sdfRange;
};
layout(set = 1, binding = 0) uniform MaterialBlock { MaterialData Material; };

View File

@ -99,6 +99,7 @@ typedef struct {
float glow[4];
float uvShift[2];
float uvScale[2];
float sdfRange[2];
float metalness;
float roughness;
float clearcoat;
@ -108,7 +109,6 @@ typedef struct {
float normalScale;
float alphaCutoff;
float pointSize;
float sdfRange;
uint32_t texture;
uint32_t glowTexture;
uint32_t occlusionTexture;

View File

@ -291,6 +291,7 @@ typedef struct {
float glow[4];
float uvShift[2];
float uvScale[2];
float sdfRange[2];
float metalness;
float roughness;
float clearcoat;
@ -300,7 +301,6 @@ typedef struct {
float normalScale;
float alphaCutoff;
float pointSize;
float sdfRange;
} MaterialData;
typedef struct {