diff options
Diffstat (limited to 'letter_grid.cginc')
| -rw-r--r-- | letter_grid.cginc | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/letter_grid.cginc b/letter_grid.cginc index 61c147b..50b4ee3 100644 --- a/letter_grid.cginc +++ b/letter_grid.cginc @@ -1,6 +1,7 @@ #ifndef __LETTER_GRID_INC #define __LETTER_GRID_INC +#include "audiolink.cginc" #include "disinfo.cginc" #include "features.cginc" #include "globals.cginc" @@ -20,14 +21,15 @@ struct LetterGridOutput { LetterGridOutput LetterGrid(v2f i) { LetterGridOutput output; - int2 cell_pos; int2 font_res = int2(round(_Letter_Grid_Tex_Res_X), round(_Letter_Grid_Tex_Res_Y)); int2 grid_res = int2(round(_Letter_Grid_Res_X), round(_Letter_Grid_Res_Y)); - float2 cell_uv; // uv within each letter cell float4 scoff = _Letter_Grid_UV_Scale_Offset; - float2 uv = ((i.uv01.xy - 0.5) - scoff.zw) * scoff.xy + 0.5; + float2 base_uv = get_uv_by_channel(i, _Letter_Grid_UV_Channel); + float2 uv = ((base_uv - 0.5) - scoff.zw) * scoff.xy + 0.5; + int2 cell_pos; + float2 cell_uv; // uv within each letter cell bool in_box = getBoxLoc(uv, 0, 1, grid_res, _Letter_Grid_Padding, cell_pos, cell_uv); // Extract char from _Letter_Grid_Data_Row_0 et al using cell_pos. @@ -43,32 +45,38 @@ LetterGridOutput LetterGrid(v2f i) { cell_pos.y - 2), cell_pos.y/2); c += _Letter_Grid_Global_Offset; +#if defined(_LETTER_GRID_ANIMATE) + // Sweep cells left-to-right, then top-to-bottom. One full sweep takes + // _Letter_Grid_Animate_Speed seconds, so each slot updates once per sweep. + int slot_count = max(grid_res.x * grid_res.y, 1); + int slot_index = cell_pos.y * grid_res.x + cell_pos.x; + int sweep_step = (int)floor((_Time.y * _Letter_Grid_Animate_Speed) * slot_count); + int slot_change_count = (sweep_step + slot_count - slot_index) / slot_count; + + int glyph_count = max(font_res.x * font_res.y, 1); + int base_char = (int)round(c); + uint rand_u = hash31_u32(uint3( + (uint)slot_index, + (uint)slot_change_count, + asuint(base_char))); + c = (float)(rand_u % glyph_count); +#endif float3 msd = renderInBox(c, uv, cell_uv, _Letter_Grid_Texture, font_res).rgb; float sd = median(msd); - // Calculate screen pixel range float screen_px_range; { float2 tex_size = float2(_Letter_Grid_Texture_TexelSize.zw); - float2 real_cell_size = floor(tex_size / grid_res); // size of cell in texels - float2 unit_range = _Letter_Grid_Screen_Px_Range / real_cell_size; - float2 screen_tex_size = 1 / fwidth(cell_uv); + float2 glyph_tex_size = tex_size / float2(font_res); + float2 unit_range = _Letter_Grid_Screen_Px_Range / glyph_tex_size; + float2 screen_tex_size = 1.0 / max(fwidth(cell_uv), float2(1e-4, 1e-4)); screen_px_range = max(0.5 * dot(unit_range, screen_tex_size), _Letter_Grid_Min_Screen_Px_Range); } float screen_px_distance = screen_px_range * (sd - _Letter_Grid_Alpha_Threshold); - float smooth_range = (length(grid_res) / sqrt(screen_px_range)) * _Letter_Grid_Blurriness; - float op = smoothstep(-smooth_range, smooth_range, screen_px_distance); - - // Sample mask if enabled - #if defined(_LETTER_GRID_MASK) - float mask = _Letter_Grid_Mask.Sample(linear_repeat_s, i.uv01.xy).r; - #else - float mask = 1.0; - #endif - - op *= mask; + float edge_softness = max(exp2((_Letter_Grid_Blurriness - 0.5) * 2.0), 1e-4); + float op = saturate(screen_px_distance / edge_softness + 0.5); // Apply blending to output output.albedo = float4(_Letter_Grid_Color.rgb, op * in_box); @@ -82,4 +90,3 @@ LetterGridOutput LetterGrid(v2f i) { #endif // _LETTER_GRID #endif // __LETTER_GRID_INC - |
