switch to a monochrome texture for the font rendering
This commit is contained in:
parent
5b83619f7a
commit
27f256a7c5
3 changed files with 22 additions and 28 deletions
|
@ -49,7 +49,7 @@ const StagingTexture = struct {
|
||||||
.Height = size.y,
|
.Height = size.y,
|
||||||
.MipLevels = 1,
|
.MipLevels = 1,
|
||||||
.ArraySize = 1,
|
.ArraySize = 1,
|
||||||
.Format = .B8G8R8A8_UNORM,
|
.Format = .A8_UNORM,
|
||||||
.SampleDesc = .{ .Count = 1, .Quality = 0 },
|
.SampleDesc = .{ .Count = 1, .Quality = 0 },
|
||||||
.Usage = .DEFAULT,
|
.Usage = .DEFAULT,
|
||||||
.BindFlags = .{ .RENDER_TARGET = 1 },
|
.BindFlags = .{ .RENDER_TARGET = 1 },
|
||||||
|
@ -70,7 +70,7 @@ const StagingTexture = struct {
|
||||||
const props = win32.D2D1_RENDER_TARGET_PROPERTIES{
|
const props = win32.D2D1_RENDER_TARGET_PROPERTIES{
|
||||||
.type = .DEFAULT,
|
.type = .DEFAULT,
|
||||||
.pixelFormat = .{
|
.pixelFormat = .{
|
||||||
.format = .B8G8R8A8_UNORM,
|
.format = .A8_UNORM,
|
||||||
.alphaMode = .PREMULTIPLIED,
|
.alphaMode = .PREMULTIPLIED,
|
||||||
},
|
},
|
||||||
.dpiX = 0,
|
.dpiX = 0,
|
||||||
|
|
|
@ -678,7 +678,7 @@ const GlyphTexture = struct {
|
||||||
.Height = size.y,
|
.Height = size.y,
|
||||||
.MipLevels = 1,
|
.MipLevels = 1,
|
||||||
.ArraySize = 1,
|
.ArraySize = 1,
|
||||||
.Format = .B8G8R8A8_UNORM,
|
.Format = .A8_UNORM,
|
||||||
.SampleDesc = .{ .Count = 1, .Quality = 0 },
|
.SampleDesc = .{ .Count = 1, .Quality = 0 },
|
||||||
.Usage = .DEFAULT,
|
.Usage = .DEFAULT,
|
||||||
.BindFlags = .{ .SHADER_RESOURCE = 1 },
|
.BindFlags = .{ .SHADER_RESOURCE = 1 },
|
||||||
|
|
|
@ -8,8 +8,8 @@ cbuffer GridConfig : register(b0)
|
||||||
struct Cell
|
struct Cell
|
||||||
{
|
{
|
||||||
uint glyph_index;
|
uint glyph_index;
|
||||||
uint background;
|
uint bg;
|
||||||
uint foreground;
|
uint fg;
|
||||||
// todo: underline flags, single/double/curly/dotted/dashed
|
// todo: underline flags, single/double/curly/dotted/dashed
|
||||||
// todo: underline color
|
// todo: underline color
|
||||||
};
|
};
|
||||||
|
@ -35,40 +35,31 @@ float4 UnpackRgba(uint packed)
|
||||||
return unpacked;
|
return unpacked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float3 Pixel(float2 pos, float4 bg, float4 fg, float glyph_texel)
|
||||||
|
{
|
||||||
|
return lerp(bg.rgb, fg.rgb, fg.a * glyph_texel);
|
||||||
|
}
|
||||||
|
|
||||||
float4 PixelMain(float4 sv_pos : SV_POSITION) : SV_TARGET {
|
float4 PixelMain(float4 sv_pos : SV_POSITION) : SV_TARGET {
|
||||||
uint2 grid_pos = sv_pos.xy / cell_size;
|
uint col = sv_pos.x / cell_size.x;
|
||||||
uint index = grid_pos.y * col_count + grid_pos.x;
|
uint row = sv_pos.y / cell_size.y;
|
||||||
|
uint cell_index = row * col_count + col;
|
||||||
|
|
||||||
const uint DEBUG_MODE_NONE = 0;
|
const uint DEBUG_MODE_NONE = 0;
|
||||||
const uint DEBUG_MODE_CHECKERBOARD = 1;
|
|
||||||
const uint DEBUG_MODE_GLYPH_TEXTURE = 2;
|
const uint DEBUG_MODE_GLYPH_TEXTURE = 2;
|
||||||
|
|
||||||
const uint DEBUG_MODE = DEBUG_MODE_NONE;
|
const uint DEBUG_MODE = DEBUG_MODE_NONE;
|
||||||
//const uint DEBUG_MODE = DEBUG_MODE_CHECKERBOARD;
|
|
||||||
// const uint DEBUG_MODE = DEBUG_MODE_GLYPH_TEXTURE;
|
// const uint DEBUG_MODE = DEBUG_MODE_GLYPH_TEXTURE;
|
||||||
|
|
||||||
if (DEBUG_MODE == DEBUG_MODE_CHECKERBOARD) {
|
Cell cell = cells[cell_index];
|
||||||
uint cell_count = col_count * row_count;
|
float4 bg = UnpackRgba(cell.bg);
|
||||||
float strength = float(index) / float(cell_count);
|
float4 fg = UnpackRgba(cell.fg);
|
||||||
uint checker = (grid_pos.x + grid_pos.y) % 2;
|
|
||||||
if (checker == 0) {
|
|
||||||
float shade = 1.0 - strength;
|
|
||||||
return float4(shade,shade,shade,1);
|
|
||||||
}
|
|
||||||
return float4(0,0,0,1);
|
|
||||||
}
|
|
||||||
|
|
||||||
Cell cell = cells[index];
|
|
||||||
float4 bg_color = UnpackRgba(cell.background);
|
|
||||||
float4 fg_color = UnpackRgba(cell.foreground);
|
|
||||||
|
|
||||||
if (DEBUG_MODE == DEBUG_MODE_GLYPH_TEXTURE) {
|
if (DEBUG_MODE == DEBUG_MODE_GLYPH_TEXTURE) {
|
||||||
float4 glyph_texel = glyph_texture.Load(int3(sv_pos.xy, 0));
|
float4 glyph_texel = glyph_texture.Load(int3(sv_pos.xy, 0));
|
||||||
return lerp(bg_color, fg_color, glyph_texel);
|
return lerp(bg, fg, glyph_texel.a);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint2 cell_pixel = uint2(sv_pos.xy) % cell_size;
|
|
||||||
|
|
||||||
uint texture_width, texture_height;
|
uint texture_width, texture_height;
|
||||||
glyph_texture.GetDimensions(texture_width, texture_height);
|
glyph_texture.GetDimensions(texture_width, texture_height);
|
||||||
uint2 texture_size = uint2(texture_width, texture_height);
|
uint2 texture_size = uint2(texture_width, texture_height);
|
||||||
|
@ -78,7 +69,10 @@ float4 PixelMain(float4 sv_pos : SV_POSITION) : SV_TARGET {
|
||||||
cell.glyph_index % cells_per_row,
|
cell.glyph_index % cells_per_row,
|
||||||
cell.glyph_index / cells_per_row
|
cell.glyph_index / cells_per_row
|
||||||
);
|
);
|
||||||
|
uint2 cell_pixel = uint2(sv_pos.xy) % cell_size;
|
||||||
uint2 texture_coord = glyph_cell_pos * cell_size + cell_pixel;
|
uint2 texture_coord = glyph_cell_pos * cell_size + cell_pixel;
|
||||||
float4 glyph_texel = glyph_texture.Load(int3(texture_coord, 0));
|
float4 glyph_texel = glyph_texture.Load(int3(texture_coord, 0));
|
||||||
return lerp(bg_color, fg_color, glyph_texel.a);
|
|
||||||
|
float2 pos = sv_pos.xy / (cell_size * float2(col_count, row_count));
|
||||||
|
return float4(Pixel(pos, bg, fg, glyph_texel.a), 1.0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue