cvr-props/Assets/test/quine.shader

121 lines
22 KiB
Text
Raw Normal View History

2024-08-11 12:24:31 +02:00
Shader "CrispyPin/Quine"
{
Properties {}
SubShader {
Tags { "RenderType" = "Opaque" }
LOD 100
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#define ROWS 105
#define COLS ROWS*2
struct appdata {
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f {
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert (appdata v) {
v2f o;
UNITY_SETUP_INSTANCE_ID(v);
UNITY_INITIALIZE_OUTPUT(v2f, o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
float3 bg(uint charx, uint chary) {
return ((charx + chary) & 1) * 0.03 + 0.03;
}
float3 frag (v2f i) : SV_Target {
// write as 'const uint text[] = {?};' before export
const uint text[] = {0x33484144,0x45520002,0x23524953,0x50593049,0x4e0f3155,0x494e4502,0x5f5b5f60,0x30524f50,0x45525449,0x4553005b,0x5d5f6033,0x55423348,0x41444552,0x005b5f60,0x60344147,0x53005b00,0x0232454e,0x44455234,0x59504502,0x001d0002,0x2f504151,0x55450200,0x5d5f6060,0x2c2f2400,0x1110105f,0x60603041,0x5353005b,0x5f606060,0x23273032,0x2f273221,0x2d5f6060,0x60035052,0x41474d41,0x00564552,0x54455800,0x56455254,0x5f606060,0x03505241,0x474d4100,0x46524147,0x4d454e54,0x00465241,0x475f5f60,0x60600349,0x4e434c55,0x44450002,0x354e4954,0x5923270e,0x4347494e,0x43025f5f,0x60606003,0x44454649,0x4e450032,0x2f373300,0x1110155f,0x60606003,0x44454649,0x4e450023,0x2f2c3300,0x322f3733,0x0a125f5f,0x60606053,0x54525543,0x54004150,0x50444154,0x41005b5f,0x60606060,0x464c4f41,0x54140056,0x45525445,0x58001a00,0x302f3329,0x34292f2e,0x1b5f6060,0x6060464c,0x4f415412,0x00555600,0x1a003425,0x38232f2f,0x3224101b,0x5f606060,0x60352e29,0x34393f36,0x25323425,0x383f292e,0x3035343f,0x292e3334,0x212e2325,0x3f29245f,0x6060605d,0x1b5f5f60,0x60605354,0x52554354,0x00561246,0x005b5f60,0x60606046,0x4c4f4154,0x12005556,0x001a0034,0x2538232f,0x2f322410,0x1b5f6060,0x6060464c,0x4f415414,0x00564552,0x54455800,0x1a003336,0x3f302f33,0x2934292f,0x2e1b5f60,0x60606035,0x2e293439,0x3f362532,0x3425383f,0x2f353430,0x35343f33,0x34253225,0x2f5f6060,0x605d1b5f,0x5f606060,0x56124600,0x56455254,0x00084150,0x50444154,0x41005609,0x005b5f60,0x60606056,0x1246004f,0x1b5f6060,0x6060352e,0x2934393f,0x33253435,0x303f292e,0x3334212e,0x23253f29,0x24085609,0x1b5f6060,0x6060352e,0x2934393f,0x292e2934,0x29212c29,0x3a253f2f,0x35343035,0x34085612,0x460c004f,0x091b5f60,0x60606035,0x2e293439,0x3f292e29,0x3429212c,0x293a253f,0x36253234,0x25383f2f,0x35343035,0x343f3334,0x2532252f,0x084f091b,0x5f606060,0x604f0e56,0x45525445,0x58001d00,0x354e4954,0x592f424a,0x45435434,0x4f234c49,0x50304f53,0x08560e56,0x45525445,0x58091b5f,0x60606060,0x4f0e5556,0x001d0056,0x0e55561b,0x5f606060,0x60524554,0x55524e00,0x4f1b5f60,0x60605d5f,0x5f606060,0x464c4f41,0x54130042,0x47085549,0x4e540043,0x48415258,0x0c005549,0x4e540043,0x48415259,0x09005b5f,0x60606060,0x52455455,0x524e0008,0x08434841,0x5258000b,0x00434841,0x52590900,0x06001109,0x000a0010,0x0e101300,0x0b00100e,0x10131b5f,0x6060605d,0x5f5f6060,0x60464c4f,0x41541300,0x46524147,0x00085612,0x46004909,0x001a0033,0x363f3441,0x52474554,0x005b5f60,0x6060600f,0x0f005752,0x49544500,0x41530007,0x434f4e53,0x54005549,0x4e540054,0x4558543b,0x3d001d00,0x5b1f5d1b,0x07004245,0x464f5245,0x00455850,0x4f52545f,0x60606060,0x434f4e53,0x54005549,0x4e540054,0x4558543b,0x3d001d00,0x5b1f5d1b,0x5f606060,0x60434f4e,0x53540055,0x494e5400,0x54455854,0x3f4c454e,0x001d0011,0x1412181b,0x5f606060,0x60434f4e,0x53540055,0x494e5400,0x424c4f42,0x3f535441,0x5254001d,0x00181312,0x1b5f5f60,0x60606043,0x4f4e5354,0x0055494e,0x5400464f,0x4e543f41,0x3b14183d,0x3b143d00,0x1d005b5b,0x100c100c,0x100c105d,0x0c5b100c,0x14101216,0x15191315,0x120c1110,0x11101517,0x11121818,0x0c161210,0x145d0c5b,0x100c100c,0x16101319,0x17191717,0x160c1617,0x11101818,0x165d0c5b,0x100c1911,0x14131016,0x1611140c,0x19111413,0x10161611,0x140c1514,0x5d0c5b14,0x10141212,0x16101418,0x0c111611,0x16191915,0x1113140c,0x11111214,0x12181610,0x14180c14,0x10141214,0x12101119,0x5d0c5b10,0x0c121011,0x17141512,0x14190c11,0x11131015,0x17131814,0x180c105d,0x0c5b100c,0x18151819,0x19131511,0x180c1910,0x17181312,0x1819110c,0x17121212,0x5d0c5b10,0x0c100c11,0x10101616,0x13121916,0x0c171819,0x1511165d,0x0c5b100c,0x12101211,0x11191211,0x160c1210,0x12111116,0x1110180c,0x11121311,0x125d0c5b,0x100c1810,0x18141518,0x1215120c,0x18101814,0x16141413,0x120c1310,0x19165d0c,0x5b100c11,0x10111313,0x11171613,0x120c1617,0x10101218,0x170c105d,0x0c5b100c,0x14101412,0x12161014,0x180c1115,0x17191113,0x140c105d,0x0c5b1210,0x11131216,0x1519120c,0x11151719,0x1013120c,0x100c105d,0x0c5b100c,0x100c1112,0x170c105d,0x0c5b100c,0x16111618,0x0c100c10,0x5d0c5b10,0x0c121011,0x17121015,0x17170c11,0x10181010,0x14151519,0x120c105d,0x0c5b100c,0x11161617,0x14141613,0x10100c11,0x16161714,0x15191914,0x170c1712,0x12125d0c,0x5b100c14,0x10141213,0x12131118,0x0c151014,0x18191515,0x11120c16,
const uint text_len = 1469;
const uint blob_start = 925;
const uint font_a[48][4] = {{0,0,0,0},{0,402659352,1010571288,6204},{0,0,603979776,6710886},{0,914306614,914306614,54},{404226048,1616995134,1124286048,404242019},{0,201745249,1130573848,0},{0,858993518,907832891,7222},{0,0,100663296,789516},{0,202119216,202116108,12312},{0,808458252,808464432,3096},{0,1013317632,6700287,0},{0,404226048,1579134,0},{201326592,1579032,0,0},{0,0,127,0},{0,6168,0,0},{0,201720577,1080045592,0},{0,1667446300,1667459947,7222},{0,404232318,504895512,6172},{0,100885375,1613764620,15971},{0,1616929598,1616919648,15971},{0,808464504,1010185087,12344},{0,1616929598,50544480,32515},{0,1667457854,50544483,7174},{0,202116108,1616916504,32611},{0,1667457854,1667448419,15971},{0,1616916510,1667464800,15971},{0,1579008,404226048,0},{0,1579020,404226048,0},{0,202911840,806882310,96},{0,2113929216,8257536,0},{0,806882310,202911840,6},{0,402659352,1664096280,15971},{0,2067465022,1667464059,62},{0,1667457891,912483199,2076},{0,1717986879,1717976678,16230},{0,54748732,1124270851,15462},{0,1717974559,1717986918,7990},{0,105277055,1175854614,32614},{0,101058063,1175854614,32614},{0,1667458652,1124270971,15462},{0,1667457891,1667465059,25443},{0,404232252,404232216,15384},{0,858993438,808464432,30768},{0,912680551,1714822686,26470},{0,105277055,101058054,3846},{0,1667457891,2139056995,25463},{0,1667457891,1870625651,25447},{0,1667457854,1667457891,15971},};
const uint font_b[49][4] = {{0,101058063,1717976582,16230},{812646400,1667988286,1667457891,15971},{0,1717986919,1717976630,16230},{0,1617126206,1661344816,15971},{0,404232252,1511528472,32382},{0,1667457854,1667457891,25443},{0,1664490504,1667457891,25443},{0,1803515702,1667459947,25443},{0,1043751779,910040092,25443},{0,404232252,1717976088,26214},{0,105079679,1630541836,32611},{0,202116156,202116108,15372},{0,946888768,50794012,1},{0,808464444,808464432,15408},{0,0,0,136066659},{16711680,0,0,0},{0,0,0,202119168},{0,858993518,1978430,0},{0,1717986878,102643302,1798},{0,50553662,4088579,0},{0,858993518,809252403,14384},{0,50553662,4088703,0},{0,101058063,637931270,7222},{808656384,858993470,7222067,0},{0,1717986919,104230502,1798},{0,404232252,1841176,6168},{1717976064,1616928864,7364704,24672},{0,506881639,107361822,1798},{0,404232252,404232216,7192},{0,1802201955,3637099,0},{0,1717986918,3892838,0},{0,1667457854,4088675,0},{101060352,1717986878,3892838,0},{808482816,858993470,7222067,0},{0,101058063,3894886,0},{0,472933182,4088582,0},{0,202140728,205458444,2060},{0,858993518,3355443,0},{0,1717976088,6710886,0},{0,1802207030,6513515,0},{0,471610979,6501916,0},{1613766400,1667457918,6513507,0},{0,201745279,8336152,0},{0,404232304,404229656,28696},{0,404232216,404226072,6168},{0,404232206,404254744,3608},{0,0,0,28219},{2131100672,1617192575,1616928864,96},{1073741824,2136492096,1078483071,64},};
float px = i.uv.x * COLS;
float py = i.uv.y * ROWS;
uint charx = px;
uint chary = py;
uint char_index = (charx + (ROWS -1 - chary) * COLS);
uint char = 4;
float3 color = float3(1,1,1);
if (char_index < blob_start) {
uint text_index = char_index>>2;
char = text[text_index];
uint byte_index = (char_index & 3);
if (byte_index == 0) { char >>= 24;}
else if (byte_index == 1) { char >>= 16;}
else if (byte_index == 2) { char >>= 8;}
}
else if (char_index < (blob_start + text_len * 11)) {
uint blob_index = char_index - blob_start;
uint number_index = (blob_index)/11;
uint digit_offset = (blob_index)%11;
if (digit_offset == 0) {
char = 16; // '0'
color = float3(1,0.5,0);
} else if (digit_offset == 1) {
char = 88; // 'x'
color = float3(1,0.5,0);
} else if (digit_offset == 10) {
char = 12; // ','
} else {
uint number = text[number_index];
uint nibble_offset = (((digit_offset - 2) & 7));
uint nibble = number >> ((7 - nibble_offset) * 4) & 0xf;
const uint hex_chars[16] = {16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 65, 66, 67, 68, 69, 70};
char = hex_chars[nibble];
color = float3(0,1,1);
}
} else {
char_index -= text_len * 11 - 1;
uint text_index = char_index>>2;
if (text_index > text_len) { return bg(charx, chary); }
char = text[text_index];
uint byte_index = (char_index & 3);
if (byte_index == 0) { char >>= 24;}
else if (byte_index == 1) { char >>= 16;}
else if (byte_index == 2) { char >>= 8;}
}
char &= 0xff;
uint tx = (px - charx)*8;
uint ty = (py - chary)*16;
uint section_index = ty>>2;
uint offset = tx + ((ty & 3)<<3);
float pixel = 0;
if (char < 48){
pixel = (font_a[char][section_index] >> offset) & 1;
} else {
pixel = (font_b[char-48][section_index] >> offset) & 1;
}
if (pixel) {
return color;
} else {
return bg(charx, chary);
}
}
ENDCG
}
}
}