qr shader: cleanup

This commit is contained in:
Crispy 2024-08-22 00:30:31 +02:00
parent b6aba3db61
commit 84c2721d2c

View file

@ -9,14 +9,6 @@ Properties {
[Enum(Low,1, Medium,0, Quartile,3, High,2)] _ECLevel("EC Level (must match data)", Integer) = 1
[IntRange] _Mask("Mask type", Range(0, 7)) = 1
_FrameSize("Frame size", Range(0, 2)) = 0.1
[Header(Debugging controls)]
[Space]
[Toggle] _DisableMask("Hide mask", Integer) = 0
[Toggle] _Animate("Animate debug worm", Integer) = 0
_AnimationSpeed("Speed", Range(1, 100)) = 0
_TimeSlider("Time", Range(0, 200)) = 0
_TimeSliderCoarse("Time Coarse", Range(0, 250)) = 0
}
SubShader {
Tags { "RenderType"="Opaque" }
@ -29,12 +21,6 @@ CGPROGRAM
uint _ECLevel;
float _FrameSize;
bool _DisableMask;
bool _Animate;
float _TimeSlider;
float _TimeSliderCoarse;
float _AnimationSpeed;
#define EC_LEVEL _ECLevel
#define MASK_TYPE _Mask
#define VERSION _Version
@ -45,10 +31,7 @@ CGPROGRAM
#define ALIGNER_SPACING (ALIGNER_SPACING_IDEAL + ALIGNER_SPACING_IDEAL % 2)
#define MISALIGNMENT ((WIDTH - 13) - ALIGNER_SPACING * ALIGNERS)
#define ALIGNER_COUNT ((ALIGNERS * ALIGNERS - 3) * (VERSION > 1))
#define BIT_COUNT (WIDTH * WIDTH - 225 - (WIDTH - 17)*2 - 25 * ALIGNER_COUNT + 10*(ALIGNERS-2)*(ALIGNERS>2) - 36 * (VERSION > 6))
#define TIME_MANUAL (_TimeSlider + _TimeSliderCoarse*100)
#define TIME (uint)(_Animate ? _Time.y * _AnimationSpeed + TIME_MANUAL : TIME_MANUAL)
// #define BIT_COUNT (WIDTH * WIDTH - 225 - (WIDTH - 17)*2 - 25 * ALIGNER_COUNT + 10*(ALIGNERS-2)*(ALIGNERS>2) - 36 * (VERSION > 6))
static const uint FORMAT_BIT_SETS[32] = {0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0, 0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976, 0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b, 0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed};
#define FORMAT_BITS_RAW ((EC_LEVEL << 3) | MASK_TYPE)
@ -192,12 +175,9 @@ CGPROGRAM
if (px < 9) {
if (passed_up>0) passed_up -= 1;
if (passed_down>(ALIGNERS-2)) passed_down-=1;
// if (passed_down>0) return 5;
// if (passed_up>0) return 5;
if (tiny_columns == 0) {
bit_index -= passed_up*10;
} else if (tiny_columns == 1) {
// bit_index += 16;
bit_index -= passed_down*10;
bit_index -= (ALIGNERS-2)*10;
} else if (tiny_columns == 2) {
@ -248,10 +228,7 @@ CGPROGRAM
if (direction_up) {
bit_index -= passed_up*5;
uint progress = (y_relative - 4) % ALIGNER_SPACING;
if (y_relative - 4 >= ALIGNER_SPACING*(ALIGNERS-1)) {
progress = 999;
}
if (progress < 5) {
if (progress < 5 && y_relative - 4 < ALIGNER_SPACING*(ALIGNERS-1)) {
bit_index -= progress+1;
}
if (py < 9) {
@ -272,10 +249,7 @@ CGPROGRAM
}
uint progress = (py - ALIGNER_GRID_Y_START) % ALIGNER_SPACING;
if (py < WIDTH-((ALIGNERS-1)*ALIGNER_SPACING+4)) {
progress = 999;
}
if (progress < 5) {
if (progress < 5 && py >= WIDTH-((ALIGNERS-1)*ALIGNER_SPACING+4)) {
bit_index -= progress;
bit_index += 4;
}
@ -318,22 +292,7 @@ CGPROGRAM
break;
}
uint bit = ((data[bit_index/32] >> (31-(bit_index % 32))) & 1);
if (!_DisableMask) {
bit ^= mask;
}
return !bit;
// bit index debugging worm
// uint worm = TIME % BIT_COUNT - bit_index;
// worm %= 200;
// const uint length = 6;
// if (worm == 0) return float3(3,0,0);
// if (worm < length) return lerp(PINK, BLUE, (worm/(float)length));
// if (bit_index >= BIT_COUNT) return float3(1,0,0);
// // #define BIT_COUNT 24
// return (float)(bit_index%BIT_COUNT)/(float)BIT_COUNT;
return bit == mask;
}
void s (Input IN, inout SurfaceOutputStandard o) { o.Albedo = main(IN.uv_); }