diff options
| -rwxr-xr-x | 3ner.shader | 10 | ||||
| -rwxr-xr-x | Scripts/gen_atlas | 6 | ||||
| -rwxr-xr-x | features.cginc | 1 | ||||
| -rwxr-xr-x | globals.cginc | 5 | ||||
| -rw-r--r-- | letter_grid.cginc | 45 |
5 files changed, 44 insertions, 23 deletions
diff --git a/3ner.shader b/3ner.shader index 710d456..4627ba0 100755 --- a/3ner.shader +++ b/3ner.shader @@ -1049,18 +1049,26 @@ Shader "yum_food/3ner" _Letter_Grid_Data_Row_1("Cell data row 1", Vector) = (0, 0, 0, 0) _Letter_Grid_Data_Row_2("Cell data row 2", Vector) = (0, 0, 0, 0) _Letter_Grid_Data_Row_3("Cell data row 3", Vector) = (0, 0, 0, 0) + [IntRange] _Letter_Grid_UV_Channel("UV Channel", Range(0, 3)) = 0 _Letter_Grid_UV_Scale_Offset("UV scale/offset", Vector) = (1, 1, 0, 0) _Letter_Grid_Padding("Padding", Float) = 0.02 _Letter_Grid_Color("Color", Color) = (1, 1, 1, 1) _Letter_Grid_Metallic("Metallic", Range(0, 1)) = 0 _Letter_Grid_Roughness("Roughness", Range(0 ,1)) = 0.5 _Letter_Grid_Emission("Emission", Range(0 ,1)) = 0.0 - _Letter_Grid_Mask("Mask", 2D) = "white" {} _Letter_Grid_Global_Offset("Global offset", Float) = 0 _Letter_Grid_Screen_Px_Range("Screen px range (from msdfgen)", Float) = 10 _Letter_Grid_Min_Screen_Px_Range("Minimum screen px range", Float) = 1 _Letter_Grid_Blurriness("Blurriness", Float) = 0.5 _Letter_Grid_Alpha_Threshold("Alpha threshold", Range(0, 1)) = 0.5 + + //ifex _Letter_Grid_Animate_Enabled==0 + [HideInInspector] m_start_Letter_Grid_Animate("Animate", Float) = 0 + [ThryToggle(_LETTER_GRID_ANIMATE)] _Letter_Grid_Animate_Enabled("Enable", Float) = 0 + _Letter_Grid_Animate_Speed("Speed", Range(0, 1)) = 0.1 + [HideInInspector] m_end_Letter_Grid_Animate("Animate", Float) = 0 + //endex + [HideInInspector] m_end_Letter_Grid("Letter grid", Float) = 0 //endex diff --git a/Scripts/gen_atlas b/Scripts/gen_atlas index a3fac72..7400013 100755 --- a/Scripts/gen_atlas +++ b/Scripts/gen_atlas @@ -69,9 +69,9 @@ CHAR_RANGES = [ (0x0370, 0x03ff), # greek and coptic (0x0400, 0x04ff), # cyrillic (0x0500, 0x052f), # cyrillic supplement - (0x0530, 0x058f), # armenian - (0x0590, 0x05ff), # hebrew - (0x0600, 0x06ff), # arabic + #(0x0530, 0x058f), # armenian + #(0x0590, 0x05ff), # hebrew + #(0x0600, 0x06ff), # arabic ] def calculate_grid_size(char_ranges): diff --git a/features.cginc b/features.cginc index 61b59e0..ab81cb2 100755 --- a/features.cginc +++ b/features.cginc @@ -228,6 +228,7 @@ //ifex _Letter_Grid_Enabled==0 #pragma shader_feature_local _LETTER_GRID +#pragma shader_feature_local _LETTER_GRID_ANIMATE //endex #endif // __FEATURES_INC diff --git a/globals.cginc b/globals.cginc index e567177..44a71c9 100755 --- a/globals.cginc +++ b/globals.cginc @@ -579,6 +579,7 @@ float4 _Letter_Grid_Data_Row_0; float4 _Letter_Grid_Data_Row_1; float4 _Letter_Grid_Data_Row_2; float4 _Letter_Grid_Data_Row_3; +int _Letter_Grid_UV_Channel; float4 _Letter_Grid_UV_Scale_Offset; float _Letter_Grid_Padding; float4 _Letter_Grid_Color; @@ -593,4 +594,8 @@ float _Letter_Grid_Blurriness; float _Letter_Grid_Alpha_Threshold; #endif // _LETTER_GRID +#if defined(_LETTER_GRID_ANIMATE) +float _Letter_Grid_Animate_Speed; +#endif // _LETTER_GRID_ANIMATE + #endif // __GLOBALS_INC 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 - |
