Compare commits

..

No commits in common. "d470f0098721e2bed8c9fc4f8cf6366954839ea3" and "7071a0189db795a30e1e1ffa04d90b0de212d5f1" have entirely different histories.

3 changed files with 21 additions and 57 deletions

View file

@ -77,9 +77,7 @@ 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}

View file

@ -1,9 +1,8 @@
Shader "CrispyPin/QRCode" {
Properties {
[HideInInspector]
_("",2D)=""{}
_Version("Version", Range(1, 40)) = 1
_TimeSlider("Time", Range(0, 250)) = 0
_("",2D)=""
_Version("Version", Integer) = 1
}
SubShader {
Tags { "RenderType"="Opaque" }
@ -12,19 +11,13 @@ CGPROGRAM
#pragma surface s Standard
struct Input{float2 uv_;};
uint _Version;
float _TimeSlider;
#define VERSION _Version
#define WIDTH (17 + VERSION * 4)
#define PIXEL_WIDTH WIDTH
// #define PIXEL_WIDTH 177
#define ALIGNERS ((VERSION / 7) + 2)
#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
@ -47,24 +40,24 @@ CGPROGRAM
#define WHITE 1
#define BLACK 0
#define PINK float3(1, .3, .5)
#define BLUE float3(0, .4, .7)
#define CYAN float3(0,1,1)
#define PINK float4(1, .3, .5, 1)
#define BLUE float4(0, .4, .7, 1)
float3 finder_pattern(uint x, uint y) {
float4 finder_pattern(uint x, uint y) {
if (x < 6 && x > 0 && y < 6 && y > 0) return !(x < 5 && x > 1 && y < 5 && y > 1);
return (x > 6 || y > 6);
}
float3 main (float2 uv){
float4 main (float2 uv){
const uint data[] = {0x68656c6c,0x6f20776f,0x726c6421};
uv.y = 1 - uv.y;
uv = uv * 1.5 - 0.25;
// Quiet zone
if (uv.x < 0 || uv.x > 1 || uv.y < 0 || uv.y > 1) return 1;
uint px = uv.x * PIXEL_WIDTH;
uint py = uv.y * PIXEL_WIDTH;
uint px = uv.x * WIDTH;
uint py = uv.y * WIDTH;
// Finder patterns
if (px < 8 && py < 8) return finder_pattern(px, py);
@ -84,14 +77,14 @@ CGPROGRAM
&& (px < WIDTH - 13 || py > 12) // top right
&& (py < WIDTH - 13 || px > 12) // bottom left
) {
uint x = px + ALIGNER_SPACING - 4;
uint y = py + ALIGNER_SPACING - 4;
if (px > 12) x -= MISALIGNMENT;
if (py > 12) y -= MISALIGNMENT;
x %= ALIGNER_SPACING;
y %= ALIGNER_SPACING;
if (x < 5 && y < 5) {
return (x < 4 && x > 0 && y < 4 && y > 0 && !(x == 2 && y == 2));
uint x = px + ALIGNER_SPACING - 4 - MISALIGNMENT;
uint y = py + ALIGNER_SPACING - 4 - MISALIGNMENT;
if (px < 15) x += MISALIGNMENT;
if (py < 15) y += MISALIGNMENT;
uint ax = x % ALIGNER_SPACING;
uint ay = y % ALIGNER_SPACING;
if (ax < 5 && ay < 5) {
return (ax < 4 && ax > 0 && ay < 4 && ay > 0 && !(ax == 2 && ay == 2));
}
}
@ -107,38 +100,11 @@ CGPROGRAM
// bottom
if (px == 8 && py > WIDTH - 8) return (FORMAT_BITS & (1 << py + 15 - WIDTH)) == 0;
// 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;
uint column = (WIDTH - px - (px > 6))/2;
uint direction_up = column & 1;
// 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.);
// return float3((px/8 + py/8) & 1, (px/2 + py/2) & 1, (px/4 + py/4) & 1, 1);
// return float4((px/8 + py/8) & 1, (px/2 + py/2) & 1, (px/4 + py/4) & 1, 1);
// return direction_up;
return 0.5;
}

View file

@ -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: 1, z: 1}
m_LocalPosition: {x: 0, y: 0.45, z: 1}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []