port font shaders to new texture format
This commit is contained in:
parent
83b933f8a7
commit
10e74c620d
4 changed files with 314 additions and 181 deletions
|
|
@ -12,7 +12,14 @@ input View {
|
||||||
}
|
}
|
||||||
|
|
||||||
input Font {
|
input Font {
|
||||||
image2D pages[8]
|
image2D page0,
|
||||||
|
image2D page1,
|
||||||
|
image2D page2,
|
||||||
|
image2D page3,
|
||||||
|
image2D page4,
|
||||||
|
image2D page5,
|
||||||
|
image2D page6,
|
||||||
|
image2D page7
|
||||||
}
|
}
|
||||||
|
|
||||||
stage vertex vert(
|
stage vertex vert(
|
||||||
|
|
@ -31,20 +38,20 @@ stage fragment frag(
|
||||||
fragment in { float4 color, float2 uv, float page })
|
fragment in { float4 color, float2 uv, float page })
|
||||||
{
|
{
|
||||||
int page = int(in.page);
|
int page = int(in.page);
|
||||||
float4 msdf_sample = texture(input.font.pages[0], in.uv.xy);
|
float4 msdf_sample = texture(input.font.page0, in.uv.xy);
|
||||||
if(page == 1) { msdf_sample = texture(input.font.pages[1], in.uv.xy); }
|
if(page == 1) { msdf_sample = texture(input.font.page1, in.uv.xy); }
|
||||||
if(page == 2) { msdf_sample = texture(input.font.pages[2], in.uv.xy); }
|
if(page == 2) { msdf_sample = texture(input.font.page2, in.uv.xy); }
|
||||||
if(page == 3) { msdf_sample = texture(input.font.pages[3], in.uv.xy); }
|
if(page == 3) { msdf_sample = texture(input.font.page3, in.uv.xy); }
|
||||||
if(page == 4) { msdf_sample = texture(input.font.pages[4], in.uv.xy); }
|
if(page == 4) { msdf_sample = texture(input.font.page4, in.uv.xy); }
|
||||||
if(page == 5) { msdf_sample = texture(input.font.pages[5], in.uv.xy); }
|
if(page == 5) { msdf_sample = texture(input.font.page5, in.uv.xy); }
|
||||||
if(page == 6) { msdf_sample = texture(input.font.pages[6], in.uv.xy); }
|
if(page == 6) { msdf_sample = texture(input.font.page6, in.uv.xy); }
|
||||||
if(page == 7) { msdf_sample = texture(input.font.pages[7], in.uv.xy); }
|
if(page == 7) { msdf_sample = texture(input.font.page7, in.uv.xy); }
|
||||||
|
|
||||||
float r = msdf_sample.r;
|
float r = msdf_sample.r;
|
||||||
float g = msdf_sample.g;
|
float g = msdf_sample.g;
|
||||||
float b = msdf_sample.b;
|
float b = msdf_sample.b;
|
||||||
float median = max(min(r, g), min(max(r, g), b));
|
float median = max(min(r, g), min(max(r, g), b));
|
||||||
float opacity = float(median > 0.5);
|
float opacity = step(0.5, median);
|
||||||
|
|
||||||
stage.color[0] = float4(in.color.rgb, in.color.a * opacity);
|
stage.color[0] = float4(in.color.rgb, in.color.a * opacity);
|
||||||
}
|
}
|
||||||
|
|
@ -21,43 +21,107 @@ material_basis = {
|
||||||
winding = "counter_clockwise"
|
winding = "counter_clockwise"
|
||||||
layers = ["default"]
|
layers = ["default"]
|
||||||
inputs = {
|
inputs = {
|
||||||
font.pages = {
|
font.page0 = {
|
||||||
type = "image"
|
type = "image"
|
||||||
count = 8
|
value = {
|
||||||
value = [
|
|
||||||
{
|
|
||||||
type = "image2D"
|
type = "image2D"
|
||||||
sampler_state = "linear_repeat"
|
sampler_state = "linear_repeat"
|
||||||
}
|
}
|
||||||
{
|
}
|
||||||
|
font.page1 = {
|
||||||
|
type = "image"
|
||||||
|
value = {
|
||||||
type = "image2D"
|
type = "image2D"
|
||||||
sampler_state = "linear_repeat"
|
sampler_state = "linear_repeat"
|
||||||
}
|
}
|
||||||
{
|
}
|
||||||
|
font.page2 = {
|
||||||
|
type = "image"
|
||||||
|
value = {
|
||||||
type = "image2D"
|
type = "image2D"
|
||||||
sampler_state = "linear_repeat"
|
sampler_state = "linear_repeat"
|
||||||
}
|
}
|
||||||
{
|
}
|
||||||
|
font.page3 = {
|
||||||
|
type = "image"
|
||||||
|
value = {
|
||||||
type = "image2D"
|
type = "image2D"
|
||||||
sampler_state = "linear_repeat"
|
sampler_state = "linear_repeat"
|
||||||
}
|
}
|
||||||
{
|
}
|
||||||
|
font.page4 = {
|
||||||
|
type = "image"
|
||||||
|
value = {
|
||||||
type = "image2D"
|
type = "image2D"
|
||||||
sampler_state = "linear_repeat"
|
sampler_state = "linear_repeat"
|
||||||
}
|
}
|
||||||
{
|
}
|
||||||
|
font.page5 = {
|
||||||
|
type = "image"
|
||||||
|
value = {
|
||||||
type = "image2D"
|
type = "image2D"
|
||||||
sampler_state = "linear_repeat"
|
sampler_state = "linear_repeat"
|
||||||
}
|
}
|
||||||
{
|
}
|
||||||
|
font.page6 = {
|
||||||
|
type = "image"
|
||||||
|
value = {
|
||||||
type = "image2D"
|
type = "image2D"
|
||||||
sampler_state = "linear_repeat"
|
sampler_state = "linear_repeat"
|
||||||
}
|
}
|
||||||
{
|
}
|
||||||
|
font.page7 = {
|
||||||
|
type = "image"
|
||||||
|
value = {
|
||||||
type = "image2D"
|
type = "image2D"
|
||||||
sampler_state = "linear_repeat"
|
sampler_state = "linear_repeat"
|
||||||
}
|
}
|
||||||
]
|
}
|
||||||
}
|
// font.pages = {
|
||||||
|
// type = "image"
|
||||||
|
// count = 8
|
||||||
|
// value = [
|
||||||
|
// {
|
||||||
|
// type = "image2D"
|
||||||
|
// sampler_state = "linear_repeat"
|
||||||
|
// image = "luxe: image/empty"
|
||||||
|
// }
|
||||||
|
// {
|
||||||
|
// type = "image2D"
|
||||||
|
// sampler_state = "linear_repeat"
|
||||||
|
// image = "luxe: image/empty"
|
||||||
|
// }
|
||||||
|
// {
|
||||||
|
// type = "image2D"
|
||||||
|
// sampler_state = "linear_repeat"
|
||||||
|
// image = "luxe: image/empty"
|
||||||
|
// }
|
||||||
|
// {
|
||||||
|
// type = "image2D"
|
||||||
|
// sampler_state = "linear_repeat"
|
||||||
|
// image = "luxe: image/empty"
|
||||||
|
// }
|
||||||
|
// {
|
||||||
|
// type = "image2D"
|
||||||
|
// sampler_state = "linear_repeat"
|
||||||
|
// image = "luxe: image/empty"
|
||||||
|
// }
|
||||||
|
// {
|
||||||
|
// type = "image2D"
|
||||||
|
// sampler_state = "linear_repeat"
|
||||||
|
// image = "luxe: image/empty"
|
||||||
|
// }
|
||||||
|
// {
|
||||||
|
// type = "image2D"
|
||||||
|
// sampler_state = "linear_repeat"
|
||||||
|
// image = "luxe: image/empty"
|
||||||
|
// }
|
||||||
|
// {
|
||||||
|
// type = "image2D"
|
||||||
|
// sampler_state = "linear_repeat"
|
||||||
|
// image = "luxe: image/empty"
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -12,7 +12,14 @@ input View {
|
||||||
}
|
}
|
||||||
|
|
||||||
input Font {
|
input Font {
|
||||||
image2D pages[8]
|
image2D page0,
|
||||||
|
image2D page1,
|
||||||
|
image2D page2,
|
||||||
|
image2D page3,
|
||||||
|
image2D page4,
|
||||||
|
image2D page5,
|
||||||
|
image2D page6,
|
||||||
|
image2D page7
|
||||||
}
|
}
|
||||||
|
|
||||||
input UI {
|
input UI {
|
||||||
|
|
@ -124,21 +131,20 @@ stage fragment frag(
|
||||||
}
|
}
|
||||||
|
|
||||||
int page = int(in.page);
|
int page = int(in.page);
|
||||||
float4 msdf_sample = texture(input.font.pages[0], in.uv.xy);
|
float4 msdf_sample = texture(input.font.page0, in.uv.xy);
|
||||||
if(page == 1) { msdf_sample = texture(input.font.pages[1], in.uv.xy); }
|
if(page == 1) { msdf_sample = texture(input.font.page1, in.uv.xy); }
|
||||||
if(page == 2) { msdf_sample = texture(input.font.pages[2], in.uv.xy); }
|
if(page == 2) { msdf_sample = texture(input.font.page2, in.uv.xy); }
|
||||||
if(page == 3) { msdf_sample = texture(input.font.pages[3], in.uv.xy); }
|
if(page == 3) { msdf_sample = texture(input.font.page3, in.uv.xy); }
|
||||||
if(page == 4) { msdf_sample = texture(input.font.pages[4], in.uv.xy); }
|
if(page == 4) { msdf_sample = texture(input.font.page4, in.uv.xy); }
|
||||||
if(page == 5) { msdf_sample = texture(input.font.pages[5], in.uv.xy); }
|
if(page == 5) { msdf_sample = texture(input.font.page5, in.uv.xy); }
|
||||||
if(page == 6) { msdf_sample = texture(input.font.pages[6], in.uv.xy); }
|
if(page == 6) { msdf_sample = texture(input.font.page6, in.uv.xy); }
|
||||||
if(page == 7) { msdf_sample = texture(input.font.pages[7], in.uv.xy); }
|
if(page == 7) { msdf_sample = texture(input.font.page7, in.uv.xy); }
|
||||||
|
|
||||||
float r = msdf_sample.r;
|
float r = msdf_sample.r;
|
||||||
float g = msdf_sample.g;
|
float g = msdf_sample.g;
|
||||||
float b = msdf_sample.b;
|
float b = msdf_sample.b;
|
||||||
float median = max(min(r, g), min(max(r, g), b));
|
float median = max(min(r, g), min(max(r, g), b));
|
||||||
float opacity = float(median > 0.5);
|
float opacity = step(0.5, median);
|
||||||
|
|
||||||
stage.color[0] = float4(in.color.rgb, in.color.a * opacity * mask.a);
|
stage.color[0] = float4(in.color.rgb, in.color.a * opacity * mask.a);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -28,44 +28,100 @@ material_basis = {
|
||||||
sampler_state = "nearest_clamp"
|
sampler_state = "nearest_clamp"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
font.pages = {
|
font.page0 = {
|
||||||
type = "image"
|
type = "image"
|
||||||
count = 8
|
value = {
|
||||||
value = [
|
|
||||||
{
|
|
||||||
type = "image2D"
|
type = "image2D"
|
||||||
sampler_state = "linear_repeat"
|
sampler_state = "linear_repeat"
|
||||||
}
|
}
|
||||||
{
|
}
|
||||||
|
font.page1 = {
|
||||||
|
type = "image"
|
||||||
|
value = {
|
||||||
type = "image2D"
|
type = "image2D"
|
||||||
sampler_state = "linear_repeat"
|
sampler_state = "linear_repeat"
|
||||||
}
|
}
|
||||||
{
|
}
|
||||||
|
font.page2 = {
|
||||||
|
type = "image"
|
||||||
|
value = {
|
||||||
type = "image2D"
|
type = "image2D"
|
||||||
sampler_state = "linear_repeat"
|
sampler_state = "linear_repeat"
|
||||||
}
|
}
|
||||||
{
|
}
|
||||||
|
font.page3 = {
|
||||||
|
type = "image"
|
||||||
|
value = {
|
||||||
type = "image2D"
|
type = "image2D"
|
||||||
sampler_state = "linear_repeat"
|
sampler_state = "linear_repeat"
|
||||||
}
|
}
|
||||||
{
|
}
|
||||||
|
font.page4 = {
|
||||||
|
type = "image"
|
||||||
|
value = {
|
||||||
type = "image2D"
|
type = "image2D"
|
||||||
sampler_state = "linear_repeat"
|
sampler_state = "linear_repeat"
|
||||||
}
|
}
|
||||||
{
|
}
|
||||||
|
font.page5 = {
|
||||||
|
type = "image"
|
||||||
|
value = {
|
||||||
type = "image2D"
|
type = "image2D"
|
||||||
sampler_state = "linear_repeat"
|
sampler_state = "linear_repeat"
|
||||||
}
|
}
|
||||||
{
|
}
|
||||||
|
font.page6 = {
|
||||||
|
type = "image"
|
||||||
|
value = {
|
||||||
type = "image2D"
|
type = "image2D"
|
||||||
sampler_state = "linear_repeat"
|
sampler_state = "linear_repeat"
|
||||||
}
|
}
|
||||||
{
|
}
|
||||||
|
font.page7 = {
|
||||||
|
type = "image"
|
||||||
|
value = {
|
||||||
type = "image2D"
|
type = "image2D"
|
||||||
sampler_state = "linear_repeat"
|
sampler_state = "linear_repeat"
|
||||||
}
|
}
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
// font.pages = {
|
||||||
|
// type = "image"
|
||||||
|
// count = 8
|
||||||
|
// value = [
|
||||||
|
// {
|
||||||
|
// type = "image2D"
|
||||||
|
// sampler_state = "linear_repeat"
|
||||||
|
// }
|
||||||
|
// {
|
||||||
|
// type = "image2D"
|
||||||
|
// sampler_state = "linear_repeat"
|
||||||
|
// }
|
||||||
|
// {
|
||||||
|
// type = "image2D"
|
||||||
|
// sampler_state = "linear_repeat"
|
||||||
|
// }
|
||||||
|
// {
|
||||||
|
// type = "image2D"
|
||||||
|
// sampler_state = "linear_repeat"
|
||||||
|
// }
|
||||||
|
// {
|
||||||
|
// type = "image2D"
|
||||||
|
// sampler_state = "linear_repeat"
|
||||||
|
// }
|
||||||
|
// {
|
||||||
|
// type = "image2D"
|
||||||
|
// sampler_state = "linear_repeat"
|
||||||
|
// }
|
||||||
|
// {
|
||||||
|
// type = "image2D"
|
||||||
|
// sampler_state = "linear_repeat"
|
||||||
|
// }
|
||||||
|
// {
|
||||||
|
// type = "image2D"
|
||||||
|
// sampler_state = "linear_repeat"
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
|
// }
|
||||||
ui.canvas_size = {
|
ui.canvas_size = {
|
||||||
type = "float2"
|
type = "float2"
|
||||||
value = [1 1]
|
value = [1 1]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue