diff --git a/Assets/test/QRCode.mat b/Assets/test/QRCode.mat index 68b50ec..c9b6cac 100644 --- a/Assets/test/QRCode.mat +++ b/Assets/test/QRCode.mat @@ -77,7 +77,9 @@ Material: - _SmoothnessTextureChannel: 0 - _SpecularHighlights: 1 - _SrcBlend: 1 + - _TimeSlider: 0 - _UVSec: 0 + - _Version: 1 - _ZWrite: 1 m_Colors: - _Color: {r: 1, g: 1, b: 1, a: 1} diff --git a/Assets/test/QRCode.shader b/Assets/test/QRCode.shader index f6e0b77..3645021 100644 --- a/Assets/test/QRCode.shader +++ b/Assets/test/QRCode.shader @@ -3,6 +3,7 @@ Properties { [HideInInspector] _("",2D)=""{} _Version("Version", Range(1, 40)) = 1 + _TimeSlider("Time", Range(0, 250)) = 0 } SubShader { Tags { "RenderType"="Opaque" } @@ -11,6 +12,7 @@ CGPROGRAM #pragma surface s Standard struct Input{float2 uv_;}; uint _Version; + float _TimeSlider; #define VERSION _Version #define WIDTH (17 + VERSION * 4) @@ -20,6 +22,9 @@ CGPROGRAM #define ALIGNER_SPACING_IDEAL ((WIDTH - 13) / (ALIGNERS-1)) #define ALIGNER_SPACING (ALIGNER_SPACING_IDEAL + ALIGNER_SPACING_IDEAL % 2) #define MISALIGNMENT ((WIDTH - 13) - ALIGNER_SPACING * ALIGNERS) + #define BIT_COUNT (WIDTH * WIDTH - 225 - (WIDTH - 17)*2) + #define TIME (_Time.y*24) + // #define TIME (uint)(_TimeSlider) #define EC_LEVEL_L 1 #define EC_LEVEL_M 0 @@ -44,6 +49,7 @@ CGPROGRAM #define BLACK 0 #define PINK float3(1, .3, .5) #define BLUE float3(0, .4, .7) + #define CYAN float3(0,1,1) float3 finder_pattern(uint x, uint y) { if (x < 6 && x > 0 && y < 6 && y > 0) return !(x < 5 && x > 1 && y < 5 && y > 1); @@ -101,8 +107,34 @@ CGPROGRAM // bottom if (px == 8 && py > WIDTH - 8) return (FORMAT_BITS & (1 << py + 15 - WIDTH)) == 0; - uint column = (WIDTH - px - (px > 6))/2; - uint direction_up = column & 1; + // data bit layout + uint column = (WIDTH - px - (px < 6)-1)/2; + uint direction_up = column % 2 == 0; + uint full_columns = column > 4 ? column - 4 : 0; + full_columns = min(full_columns, VERSION*2); + // the 4 columns under the right finder + uint short_columns = min(column, 4); + // between the left two finder patterns + uint tiny_columns = column > (VERSION*2 + 4) ? column - (VERSION*2 + 4) : 0; + uint bit_index = full_columns * (WIDTH - 1) * 2; + bit_index += short_columns * (WIDTH - 9) * 2; + bit_index += tiny_columns * (WIDTH - 17) * 2; + bit_index += (px + (px < 6)) % 2; + + if (direction_up) { + bit_index += (WIDTH - py - 1 - (py < 7)) * 2; + } else {// direction down + const uint diff = (full_columns == 0) ? 9 : (py > 6); + bit_index += (py - diff)*2; + } + if (px < 9) bit_index -= 16; // rightmost tiny column + + // debugging worm + uint worm = abs(TIME % BIT_COUNT - bit_index); + const uint length = 4; + if (worm < length) return CYAN * (worm/(float)length); + return (float)(bit_index%BIT_COUNT)/(float)BIT_COUNT; + // return lerp(BLUE, PINK, column / (WIDTH/2.)); return lerp(BLUE, PINK, (px+py)&1); // return float3((px%5)/5., (px/10+py/10)&1, (py%5)/5.); diff --git a/Assets/test/TestProps.unity b/Assets/test/TestProps.unity index 982416b..e6c90d1 100644 --- a/Assets/test/TestProps.unity +++ b/Assets/test/TestProps.unity @@ -1360,7 +1360,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1500710831} m_LocalRotation: {x: 0, y: 1, z: 0, w: 0} - m_LocalPosition: {x: 0, y: 0.45, z: 1} + m_LocalPosition: {x: 0, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: []