qr shader: correct data bit layout for rightmost column of aligners, making it work up to QR 6

This commit is contained in:
Crispy 2024-08-17 23:44:40 +02:00
parent e0fd6f2613
commit f51e0dff07
3 changed files with 61 additions and 34 deletions

View file

@ -10,7 +10,8 @@ Material:
m_Name: QRCode m_Name: QRCode
m_Shader: {fileID: 4800000, guid: 4bdd5767586f3a92993efea8febe2aa2, type: 3} m_Shader: {fileID: 4800000, guid: 4bdd5767586f3a92993efea8febe2aa2, type: 3}
m_ValidKeywords: [] m_ValidKeywords: []
m_InvalidKeywords: [] m_InvalidKeywords:
- _DISABLEMASK_ON
m_LightmapFlags: 4 m_LightmapFlags: 4
m_EnableInstancingVariants: 0 m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0 m_DoubleSidedGI: 0
@ -61,7 +62,7 @@ Material:
m_Scale: {x: 1, y: 1} m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0} m_Offset: {x: 0, y: 0}
m_Ints: m_Ints:
- _DisableMask: 0 - _DisableMask: 1
- _Version: 15 - _Version: 15
m_Floats: m_Floats:
- _BumpScale: 1 - _BumpScale: 1
@ -79,9 +80,9 @@ Material:
- _SmoothnessTextureChannel: 0 - _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1 - _SpecularHighlights: 1
- _SrcBlend: 1 - _SrcBlend: 1
- _TimeSlider: 0 - _TimeSlider: 95
- _UVSec: 0 - _UVSec: 0
- _Version: 1 - _Version: 6
- _ZWrite: 1 - _ZWrite: 1
m_Colors: m_Colors:
- _Color: {r: 1, g: 1, b: 1, a: 1} - _Color: {r: 1, g: 1, b: 1, a: 1}

View file

@ -6,7 +6,8 @@ Properties {
_Mask("Mask type", Range(0, 7)) = 1 _Mask("Mask type", Range(0, 7)) = 1
[Toggle] [Toggle]
_DisableMask("Hide mask", Integer) = 0 _DisableMask("Hide mask", Integer) = 0
_TimeSlider("Time", Range(0, 250)) = 0 // _TimeSlider("Time", Range(150, 300)) = 0
_TimeSlider("Time", Range(0, 300)) = 0
} }
SubShader { SubShader {
Tags { "RenderType"="Opaque" } Tags { "RenderType"="Opaque" }
@ -27,9 +28,9 @@ CGPROGRAM
#define ALIGNER_SPACING_IDEAL ((WIDTH - 13) / (ALIGNERS-1)) #define ALIGNER_SPACING_IDEAL ((WIDTH - 13) / (ALIGNERS-1))
#define ALIGNER_SPACING (ALIGNER_SPACING_IDEAL + ALIGNER_SPACING_IDEAL % 2) #define ALIGNER_SPACING (ALIGNER_SPACING_IDEAL + ALIGNER_SPACING_IDEAL % 2)
#define MISALIGNMENT ((WIDTH - 13) - ALIGNER_SPACING * ALIGNERS) #define MISALIGNMENT ((WIDTH - 13) - ALIGNER_SPACING * ALIGNERS)
#define BIT_COUNT (WIDTH * WIDTH - 225 - (WIDTH - 17)*2) #define BIT_COUNT (WIDTH * WIDTH - 225 - (WIDTH - 17)*2 - 25 * (ALIGNERS * ALIGNERS - 3) * (VERSION > 1))
#define TIME (_Time.y*24) #define TIME (_Time.y*24)
// #define TIME (uint)(_TimeSlider) #define TIME (uint)(_TimeSlider)
#define EC_LEVEL_L 1 #define EC_LEVEL_L 1
#define EC_LEVEL_M 0 #define EC_LEVEL_M 0
@ -45,13 +46,6 @@ CGPROGRAM
#define FORMAT_BITS_RAW ((EC_LEVEL << 3) | MASK_TYPE) #define FORMAT_BITS_RAW ((EC_LEVEL << 3) | MASK_TYPE)
#define FORMAT_BITS FORMAT_BIT_SETS[FORMAT_BITS_RAW] #define FORMAT_BITS FORMAT_BIT_SETS[FORMAT_BITS_RAW]
/*
v = 15
width = 77
aligners = 4
spacing = (77-13)/3
*/
#define WHITE 1 #define WHITE 1
#define BLACK 0 #define BLACK 0
#define PINK float3(1, .3, .5) #define PINK float3(1, .3, .5)
@ -63,13 +57,19 @@ CGPROGRAM
} }
float3 main (float2 uv){ float3 main (float2 uv){
// hell_o wo_rld! // "hell", "o wo", "rld!"
const uint data[] = {0x68656c6c,0x6f20776f,0x726c6421}; const uint data[] = {0x68656c6c,0x6f20776f,0x726c6421,
const uint data_len = 12; // 4 bits 0 padding to align to byte (4 bit ECI_MODE is inserted before data and length)
// then ec11ec11... until some version-specific length reached?
// then EC data
0x0ec11ec1, 0x1ec2d631, 0x95423722, 0xe0000000
};
const uint data_len = 3*4;
const uint total_len = 7*4;
uv.y = 1 - uv.y; uv.y = 1 - uv.y;
uv = uv * 1.5 - 0.25; uv = uv * 1.5 - 0.25;
// Quiet zone // Quiet zone/frame
if (uv.x < 0 || uv.x > 1 || uv.y < 0 || uv.y > 1) return 2; if (uv.x < 0 || uv.x > 1 || uv.y < 0 || uv.y > 1) return 1.2;
uint px = uv.x * PIXEL_WIDTH; uint px = uv.x * PIXEL_WIDTH;
uint py = uv.y * PIXEL_WIDTH; uint py = uv.y * PIXEL_WIDTH;
@ -128,22 +128,48 @@ CGPROGRAM
bit_index += short_columns * (WIDTH - 9) * 2; bit_index += short_columns * (WIDTH - 9) * 2;
bit_index += tiny_columns * (WIDTH - 17) * 2; bit_index += tiny_columns * (WIDTH - 17) * 2;
bit_index += (px + (px < 6)) % 2; bit_index += (px + (px < 6)) % 2;
uint column_progress;
if (direction_up)
column_progress = WIDTH - py - 1 - (py < 7);
else
column_progress = py - ((full_columns == 0) ? 9 : (py > 6));
bit_index += column_progress * 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 if (px < 9) bit_index -= 16; // rightmost tiny column
// data bit layout - aligners
if (VERSION > 1 && column > 1) {
// aligners always cover a half column to the left and two full columns to the right
// outer aligners are always 4 from all edges
// rightmost column of aligners
uint passed_up = (column_progress - 9 + ALIGNER_SPACING) / ALIGNER_SPACING;
if (column == 2) {
bit_index -= passed_up * 10;
} else if (column == 3) {
uint passed_down = (column_progress) / ALIGNER_SPACING;
bit_index -= (passed_down + ALIGNERS - 1) * 10;
} else if (column == 4) {
bit_index -= (ALIGNERS - 1) * 20;
uint offset = (column_progress + ALIGNER_SPACING - 3) % ALIGNER_SPACING;
if (offset < 6) {
bit_index -= offset;
}
bit_index -= passed_up * 5;
} else {
bit_index -= (ALIGNERS-1)*25;
}
}
// data // data
uint bit = 0; uint bit = 0;
if (bit_index < 4){ if (bit_index < 4){
bit = (ECI_MODE >> (3-bit_index))&1; bit = (ECI_MODE >> (3-bit_index))&1;
} else if (bit_index < 12) { } else if (bit_index < 12) {
bit = (data_len >> (7 - (bit_index - 4))) & 1; bit = (data_len >> (7 - (bit_index - 4))) & 1;
} else if (bit_index < data_len*8 + 12){ } else if (bit_index < total_len*8 + 12){
uint data_bit_index = bit_index - 12; uint data_bit_index = bit_index - 12;
bit = ((data[data_bit_index/32] >> (31-(data_bit_index % 32))) & 1); bit = ((data[data_bit_index/32] >> (31-(data_bit_index % 32))) & 1);
} }
@ -180,13 +206,13 @@ CGPROGRAM
bit ^= mask; bit ^= mask;
} }
return !bit; // return !bit;
// // bit index debugging worm // bit index debugging worm
// uint worm = abs(TIME % BIT_COUNT - bit_index); uint worm = abs(TIME % BIT_COUNT - bit_index);
// const uint length = 4; const uint length = 4;
// if (worm < length) return BLUE * (worm/(float)length); if (worm < length) return BLUE * (worm/(float)length);
// return (float)(bit_index%BIT_COUNT)/(float)BIT_COUNT; return (float)(bit_index%BIT_COUNT)/(float)BIT_COUNT;
} }
void s (Input IN, inout SurfaceOutputStandard o) { o.Albedo = main(IN.uv_); } void s (Input IN, inout SurfaceOutputStandard o) { o.Albedo = main(IN.uv_); }

View file

@ -1573,8 +1573,8 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
type: 3 type: 3
objectId: 9fee86b2-a9bd-46a3-a364-5f94506c4253 objectId: 51d54682-361a-48db-a259-e88b486e5fcd
randomNum: 24356558 randomNum: 22473440
unityVersion: 2021.3.41f1 unityVersion: 2021.3.41f1
cckVersion: 3.10:132 cckVersion: 3.10:132
--- !u!114 &1905057117 --- !u!114 &1905057117