new dithering shaders

This commit is contained in:
minjaesong
2021-10-06 11:13:44 +09:00
parent 2c6dc8750a
commit fb13922ad9
11 changed files with 235 additions and 123 deletions

View File

@@ -1,3 +1,8 @@
/**
* Blue Noise texture created by Christoph Peters, released under CC0
* http://momentsingraphics.de/BlueNoise.html
*/
#version 120
#ifdef GL_ES
precision mediump float;
@@ -8,46 +13,70 @@ varying vec4 v_color;
varying vec2 v_texCoords;
uniform sampler2D u_texture;
int bayerR[256] = int[](
120, 34, 248, 6, 116, 70, 252, 98, 124, 52, 104, 162, 37, 128, 99, 69,
225, 85, 138, 102, 47, 209, 191, 140, 19, 181, 11, 143, 253, 24, 204, 151,
167, 16, 195, 236, 159, 26, 173, 60, 84, 202, 223, 115, 88, 183, 235, 45,
108, 62, 177, 75, 126, 89, 232, 35, 244, 154, 43, 169, 59, 76, 2, 132,
251, 210, 22, 219, 149, 1, 113, 215, 125, 71, 27, 240, 212, 148, 197, 95,
157, 53, 119, 39, 246, 200, 51, 161, 100, 194, 136, 107, 15, 122, 227, 30,
83, 189, 144, 97, 64, 184, 81, 10, 176, 18, 228, 91, 186, 40, 65, 175,
8, 241, 229, 14, 165, 134, 221, 254, 145, 66, 207, 54, 164, 247, 139, 112,
46, 129, 73, 201, 109, 29, 94, 44, 121, 33, 242, 150, 5, 78, 205, 222,
103, 170, 23, 214, 153, 58, 234, 193, 168, 86, 114, 180, 130, 96, 25, 185,
57, 147, 87, 42, 249, 178, 3, 127, 211, 72, 12, 220, 199, 38, 158, 255,
0, 218, 192, 117, 137, 77, 101, 21, 156, 230, 49, 105, 61, 237, 74, 123,
179, 231, 67, 32, 163, 198, 243, 63, 142, 187, 250, 172, 17, 141, 208, 93,
133, 20, 106, 238, 13, 50, 216, 111, 28, 41, 90, 118, 155, 190, 31, 48,
160, 80, 146, 203, 92, 131, 182, 82, 166, 206, 135, 4, 79, 233, 110, 245,
213, 188, 56, 171, 224, 36, 152, 7, 226, 239, 68, 196, 217, 55, 174, 9
);
int bayerG[256] = int[](
162, 246, 7, 109, 125, 241, 180, 198, 32, 159, 187, 18, 219, 175, 90, 200,
129, 223, 94, 54, 217, 20, 149, 98, 247, 71, 143, 104, 232, 40, 2, 114,
60, 23, 156, 196, 38, 80, 231, 58, 118, 215, 11, 204, 55, 150, 254, 186,
206, 74, 234, 139, 173, 106, 130, 3, 177, 43, 89, 164, 126, 78, 99, 29,
170, 88, 117, 12, 252, 65, 203, 161, 225, 138, 250, 191, 22, 179, 216, 142,
242, 49, 188, 31, 213, 47, 184, 26, 76, 34, 110, 64, 239, 46, 120, 8,
220, 132, 163, 102, 151, 86, 116, 244, 100, 153, 209, 15, 85, 227, 157, 68,
96, 19, 201, 72, 229, 5, 140, 218, 59, 194, 123, 172, 135, 199, 107, 36,
146, 176, 53, 249, 124, 193, 171, 21, 45, 236, 1, 93, 52, 27, 185, 245,
81, 224, 111, 16, 39, 63, 95, 158, 82, 182, 141, 253, 214, 73, 167, 6,
61, 208, 155, 137, 181, 212, 243, 128, 230, 112, 66, 37, 152, 115, 235, 127,
192, 30, 91, 238, 77, 105, 9, 33, 202, 17, 165, 222, 10, 205, 97, 44,
251, 169, 0, 50, 197, 160, 144, 57, 75, 189, 101, 131, 84, 178, 24, 145,
121, 103, 133, 221, 25, 119, 255, 174, 226, 148, 42, 248, 56, 195, 228, 70,
211, 183, 62, 233, 87, 41, 207, 92, 113, 4, 210, 168, 28, 108, 154, 14,
79, 35, 147, 190, 166, 69, 13, 134, 51, 237, 83, 122, 67, 136, 240, 48
);
int bayerB[256] = int[](
166, 21, 186, 232, 50, 196, 126, 89, 191, 71, 134, 251, 87, 205, 129, 52,
113, 70, 88, 155, 110, 78, 34, 147, 177, 107, 49, 7, 161, 103, 181, 2,
252, 198, 143, 216, 25, 170, 224, 60, 242, 29, 213, 121, 234, 35, 146, 221,
45, 122, 12, 58, 97, 247, 117, 15, 200, 95, 140, 183, 73, 194, 64, 94,
28, 160, 235, 180, 203, 136, 46, 157, 80, 167, 229, 56, 23, 245, 133, 169,
228, 82, 105, 39, 72, 0, 188, 220, 127, 9, 40, 154, 111, 86, 13, 206,
53, 142, 249, 128, 214, 151, 90, 238, 66, 104, 250, 208, 174, 223, 119, 187,
69, 6, 193, 24, 168, 55, 112, 20, 175, 192, 76, 135, 1, 47, 156, 100,
149, 210, 116, 85, 227, 33, 254, 207, 43, 144, 30, 96, 63, 199, 233, 27,
240, 41, 163, 65, 182, 138, 99, 159, 120, 231, 215, 164, 244, 125, 79, 179,
108, 217, 92, 246, 11, 197, 74, 4, 59, 84, 16, 109, 185, 38, 14, 137,
57, 18, 130, 153, 48, 123, 171, 241, 202, 132, 178, 51, 145, 222, 91, 201,
172, 75, 190, 31, 236, 218, 106, 37, 152, 26, 248, 209, 5, 68, 158, 255,
8, 225, 114, 204, 83, 22, 67, 184, 226, 93, 77, 124, 102, 239, 118, 44,
98, 148, 61, 176, 101, 162, 141, 54, 115, 165, 42, 195, 173, 32, 189, 139,
211, 243, 36, 131, 3, 253, 212, 10, 237, 17, 219, 150, 62, 19, 230, 81
);
// "steps" of R, G and B. Must be integer && equal or greater than 2
uniform float rcount = 64.0;
uniform float gcount = 64.0;
uniform float bcount = 64.0;
uniform float acount = 1.0;
/*int bayer[7 * 7] = int[](
32,42,10,27,37,5,15,
1,18,28,45,13,23,40,
26,36,4,14,31,48,9,
44,12,22,39,0,17,34,
20,30,47,8,25,35,3,
38,6,16,33,43,11,21,
7,24,41,2,19,29,46
); // I kind of accidentally create it...
float bayerSize = 7.0;*/
/*int bayer[9 * 9] = int[](
50,71,2,23,44,56,77,17,29,
72,12,33,45,66,6,18,39,60,
22,43,55,76,16,28,49,70,1,
53,65,5,26,38,59,80,11,32,
75,15,27,48,69,0,21,42,54,
25,37,58,79,10,31,52,64,4,
47,68,8,20,41,62,74,14,35,
78,9,30,51,63,3,24,36,57,
19,40,61,73,13,34,46,67,7
); // I kind of accidentally create it...
float bayerSize = 9.0;*/
//int bayer[25 * 25] = int[](165,530,106,302,540,219,477,100,231,417,314,223,424,37,207,434,326,22,448,338,111,454,523,278,579,334,19,410,495,57,352,158,318,598,109,509,157,524,282,606,83,225,539,163,234,607,313,206,71,470,251,608,216,135,275,609,415,29,451,204,397,21,373,107,462,348,482,120,362,508,33,147,572,388,142,447,77,345,565,439,104,215,546,279,69,567,311,585,258,177,17,266,601,55,428,270,461,331,26,560,164,271,486,186,16,336,457,150,342,471,245,161,56,396,496,555,385,146,321,190,526,97,182,511,297,429,553,49,374,536,263,575,43,501,124,368,538,450,121,309,84,210,449,561,79,356,610,256,378,58,105,315,156,244,423,118,183,408,220,611,15,198,293,596,221,375,581,39,238,500,287,14,437,139,595,227,403,590,478,68,612,295,517,87,312,413,515,78,433,13,476,134,340,414,160,466,213,547,324,456,542,141,12,335,214,357,11,381,242,469,159,265,383,176,545,285,197,503,108,576,51,387,98,200,34,358,489,277,570,96,441,554,123,534,52,556,112,605,330,70,392,613,28,288,361,232,602,300,502,267,102,195,399,152,484,264,166,289,427,192,298,407,25,249,520,114,233,444,543,170,498,131,452,66,562,310,586,54,531,346,42,614,354,23,588,491,151,468,353,187,483,369,153,85,425,10,276,371,174,420,32,459,222,304,136,421,103,458,230,339,67,260,578,93,544,9,280,594,327,248,582,472,50,615,254,537,359,91,600,475,212,525,168,558,128,455,370,179,301,405,209,467,48,442,127,355,184,332,481,126,286,175,436,273,31,377,306,36,412,294,616,8,473,60,603,116,347,532,191,568,61,522,90,218,391,592,62,514,122,552,149,617,241,513,81,202,272,557,333,226,507,255,72,305,402,229,418,296,551,7,411,317,236,416,337,480,64,389,132,350,487,404,89,162,435,44,419,618,113,505,20,604,138,465,188,493,133,580,6,169,259,320,548,193,593,40,178,512,364,591,144,319,196,386,261,351,205,384,76,269,38,349,208,504,440,99,490,5,426,243,322,574,281,4,237,460,527,3,549,155,577,47,533,316,619,394,519,82,268,325,566,199,299,119,529,75,400,125,492,344,86,217,308,463,80,395,284,474,117,201,95,235,422,620,143,45,372,597,453,343,185,479,247,569,171,409,584,129,365,239,488,94,224,438,559,283,541,18,194,401,516,262,148,41,250,621,24,329,92,446,27,291,485,35,622,180,535,379,30,341,443,145,363,494,246,101,445,550,390,499,115,432,521,211,623,253,528,189,430,307,53,323,130,624,172,46,589,292,63,599,328,203,74,290,181,376,274,140,393,59,367,88,380,137,506,252,571,431,240,497,382,228,464,167,398,2,573,366,518,1,583,73,563,303,510,154,564,257,587,65,406,173,0,360,110);
int bayer[14 * 14] = int[](131,187,8,78,50,18,134,89,155,102,29,95,184,73,22,86,113,171,142,105,34,166,9,60,151,128,40,110,168,137,45,28,64,188,82,54,124,189,80,13,156,56,7,61,186,121,154,6,108,177,24,100,38,176,93,123,83,148,96,17,88,133,44,145,69,161,139,72,30,181,115,27,163,47,178,65,164,14,120,48,5,127,153,52,190,58,126,81,116,21,106,77,173,92,191,63,99,12,76,144,4,185,37,149,192,39,135,23,117,31,170,132,35,172,103,66,129,79,3,97,57,159,70,141,53,94,114,20,49,158,19,146,169,122,183,11,104,180,2,165,152,87,182,118,91,42,67,25,84,147,43,85,125,68,16,136,71,10,193,112,160,138,51,111,162,26,194,46,174,107,41,143,33,74,1,101,195,15,75,140,109,90,32,62,157,98,167,119,179,59,36,130,175,55,0,150);
float bayerSize = 14.0;
float bayerSize = 16.0;
float bayerDivider = bayerSize * bayerSize;
float quant = 63.0; // 64 steps -> 63.0; 256 steps -> 255.0
vec4 quantizer = vec4(quant);
vec4 quantizerDivider = vec4(1.0 / quant);
vec2 boolean = vec2(0.0, 1.0);
vec4 halfvec = vec4(0.5);
vec4 gammaIn(vec4 col) {
return pow(col, vec4(2.2));
@@ -57,30 +86,23 @@ vec4 gammaOut(vec4 col) {
return pow(col, vec4(1.0 / 2.2));
}
vec4 nearestColour(vec4 incolor) {
vec4 rgbaCounts = vec4(rcount, gcount, bcount, acount);
vec4 color = incolor;
color.r = floor((rgbaCounts.r - 1.0) * color.r + 0.5) / (rgbaCounts.r - 1.0);
color.g = floor((rgbaCounts.g - 1.0) * color.g + 0.5) / (rgbaCounts.g - 1.0);
color.b = floor((rgbaCounts.b - 1.0) * color.b + 0.5) / (rgbaCounts.b - 1.0);
color.a = 1.0;//floor((rgbaCounts.a - 1.0) * color.a + 0.5) / (rgbaCounts.a - 1.0);
return color;
vec4 nearestColour(vec4 inColor) {
return floor(quantizer * inColor + halfvec) * quantizerDivider;
}
void main(void) {
float spread = 1.0 / (0.299 * (rcount - 1.0) + 0.587 * (gcount - 1.0) + 0.114 * (bcount - 1.0)); // this spread value is optimised one -- try your own values for various effects!
// create texture coordinates based on pixelSize //
vec4 inColor = (texture2D(u_texture, v_texCoords));
vec4 inColor = v_color * (texture2D(u_texture, v_texCoords));
vec2 entry = mod(gl_FragCoord.xy, vec2(bayerSize, bayerSize));
gl_FragColor = nearestColour(inColor + spread * (bayer[int(entry.y) * int(bayerSize) + int(entry.x)] / bayerDivider - 0.5));
//gl_FragColor = nearestColour(inColor);
//gl_FragColor = inColor;
vec4 bayerThreshold = vec4(
bayerR[int(entry.y) * int(bayerSize) + int(entry.x)] / bayerDivider - 0.5,
bayerG[int(entry.y) * int(bayerSize) + int(entry.x)] / bayerDivider - 0.5,
bayerB[int(entry.y) * int(bayerSize) + int(entry.x)] / bayerDivider - 0.5,
0.5
);
vec4 selvec = nearestColour(inColor + bayerThreshold * quantizerDivider);
gl_FragColor = selvec * boolean.yyyx + inColor * boolean.xxxy;
}

View File

@@ -14,77 +14,100 @@ uniform vec3 bottomColor;
uniform float parallax = 0.0; // +1.0: all top col, -1.0: all bototm col, 0.0: normal grad
uniform float parallax_size = 1.0/3.0; // 0: no parallax
// "steps" of R, G and B. Must be integer && equal or greater than 2
uniform float rcount = 64.0; // it even works on 256.0!
uniform float gcount = 64.0; // using 64: has less banding and most monitors are internally 6-bit
uniform float bcount = 64.0;
// inverted zoom; this value must set to (1f/zoom)
uniform float zoomInv = 1.0;
/*int bayer[7 * 7] = int[](
32,42,10,27,37,5,15,
1,18,28,45,13,23,40,
26,36,4,14,31,48,9,
44,12,22,39,0,17,34,
20,30,47,8,25,35,3,
38,6,16,33,43,11,21,
7,24,41,2,19,29,46
); // I kind of accidentally create it...
float bayerSize = 7.0;*/
/*int bayer[9 * 9] = int[](
50,71,2,23,44,56,77,17,29,
72,12,33,45,66,6,18,39,60,
22,43,55,76,16,28,49,70,1,
53,65,5,26,38,59,80,11,32,
75,15,27,48,69,0,21,42,54,
25,37,58,79,10,31,52,64,4,
47,68,8,20,41,62,74,14,35,
78,9,30,51,63,3,24,36,57,
19,40,61,73,13,34,46,67,7
); // I kind of accidentally create it...
float bayerSize = 9.0;*/
//int bayer[25 * 25] = int[](165,530,106,302,540,219,477,100,231,417,314,223,424,37,207,434,326,22,448,338,111,454,523,278,579,334,19,410,495,57,352,158,318,598,109,509,157,524,282,606,83,225,539,163,234,607,313,206,71,470,251,608,216,135,275,609,415,29,451,204,397,21,373,107,462,348,482,120,362,508,33,147,572,388,142,447,77,345,565,439,104,215,546,279,69,567,311,585,258,177,17,266,601,55,428,270,461,331,26,560,164,271,486,186,16,336,457,150,342,471,245,161,56,396,496,555,385,146,321,190,526,97,182,511,297,429,553,49,374,536,263,575,43,501,124,368,538,450,121,309,84,210,449,561,79,356,610,256,378,58,105,315,156,244,423,118,183,408,220,611,15,198,293,596,221,375,581,39,238,500,287,14,437,139,595,227,403,590,478,68,612,295,517,87,312,413,515,78,433,13,476,134,340,414,160,466,213,547,324,456,542,141,12,335,214,357,11,381,242,469,159,265,383,176,545,285,197,503,108,576,51,387,98,200,34,358,489,277,570,96,441,554,123,534,52,556,112,605,330,70,392,613,28,288,361,232,602,300,502,267,102,195,399,152,484,264,166,289,427,192,298,407,25,249,520,114,233,444,543,170,498,131,452,66,562,310,586,54,531,346,42,614,354,23,588,491,151,468,353,187,483,369,153,85,425,10,276,371,174,420,32,459,222,304,136,421,103,458,230,339,67,260,578,93,544,9,280,594,327,248,582,472,50,615,254,537,359,91,600,475,212,525,168,558,128,455,370,179,301,405,209,467,48,442,127,355,184,332,481,126,286,175,436,273,31,377,306,36,412,294,616,8,473,60,603,116,347,532,191,568,61,522,90,218,391,592,62,514,122,552,149,617,241,513,81,202,272,557,333,226,507,255,72,305,402,229,418,296,551,7,411,317,236,416,337,480,64,389,132,350,487,404,89,162,435,44,419,618,113,505,20,604,138,465,188,493,133,580,6,169,259,320,548,193,593,40,178,512,364,591,144,319,196,386,261,351,205,384,76,269,38,349,208,504,440,99,490,5,426,243,322,574,281,4,237,460,527,3,549,155,577,47,533,316,619,394,519,82,268,325,566,199,299,119,529,75,400,125,492,344,86,217,308,463,80,395,284,474,117,201,95,235,422,620,143,45,372,597,453,343,185,479,247,569,171,409,584,129,365,239,488,94,224,438,559,283,541,18,194,401,516,262,148,41,250,621,24,329,92,446,27,291,485,35,622,180,535,379,30,341,443,145,363,494,246,101,445,550,390,499,115,432,521,211,623,253,528,189,430,307,53,323,130,624,172,46,589,292,63,599,328,203,74,290,181,376,274,140,393,59,367,88,380,137,506,252,571,431,240,497,382,228,464,167,398,2,573,366,518,1,583,73,563,303,510,154,564,257,587,65,406,173,0,360,110);
int bayer[14 * 14] = int[](131,187,8,78,50,18,134,89,155,102,29,95,184,73,22,86,113,171,142,105,34,166,9,60,151,128,40,110,168,137,45,28,64,188,82,54,124,189,80,13,156,56,7,61,186,121,154,6,108,177,24,100,38,176,93,123,83,148,96,17,88,133,44,145,69,161,139,72,30,181,115,27,163,47,178,65,164,14,120,48,5,127,153,52,190,58,126,81,116,21,106,77,173,92,191,63,99,12,76,144,4,185,37,149,192,39,135,23,117,31,170,132,35,172,103,66,129,79,3,97,57,159,70,141,53,94,114,20,49,158,19,146,169,122,183,11,104,180,2,165,152,87,182,118,91,42,67,25,84,147,43,85,125,68,16,136,71,10,193,112,160,138,51,111,162,26,194,46,174,107,41,143,33,74,1,101,195,15,75,140,109,90,32,62,157,98,167,119,179,59,36,130,175,55,0,150);
float bayerSize = 14.0;
int bayerR[256] = int[](
120, 34, 248, 6, 116, 70, 252, 98, 124, 52, 104, 162, 37, 128, 99, 69,
225, 85, 138, 102, 47, 209, 191, 140, 19, 181, 11, 143, 253, 24, 204, 151,
167, 16, 195, 236, 159, 26, 173, 60, 84, 202, 223, 115, 88, 183, 235, 45,
108, 62, 177, 75, 126, 89, 232, 35, 244, 154, 43, 169, 59, 76, 2, 132,
251, 210, 22, 219, 149, 1, 113, 215, 125, 71, 27, 240, 212, 148, 197, 95,
157, 53, 119, 39, 246, 200, 51, 161, 100, 194, 136, 107, 15, 122, 227, 30,
83, 189, 144, 97, 64, 184, 81, 10, 176, 18, 228, 91, 186, 40, 65, 175,
8, 241, 229, 14, 165, 134, 221, 254, 145, 66, 207, 54, 164, 247, 139, 112,
46, 129, 73, 201, 109, 29, 94, 44, 121, 33, 242, 150, 5, 78, 205, 222,
103, 170, 23, 214, 153, 58, 234, 193, 168, 86, 114, 180, 130, 96, 25, 185,
57, 147, 87, 42, 249, 178, 3, 127, 211, 72, 12, 220, 199, 38, 158, 255,
0, 218, 192, 117, 137, 77, 101, 21, 156, 230, 49, 105, 61, 237, 74, 123,
179, 231, 67, 32, 163, 198, 243, 63, 142, 187, 250, 172, 17, 141, 208, 93,
133, 20, 106, 238, 13, 50, 216, 111, 28, 41, 90, 118, 155, 190, 31, 48,
160, 80, 146, 203, 92, 131, 182, 82, 166, 206, 135, 4, 79, 233, 110, 245,
213, 188, 56, 171, 224, 36, 152, 7, 226, 239, 68, 196, 217, 55, 174, 9
);
int bayerG[256] = int[](
162, 246, 7, 109, 125, 241, 180, 198, 32, 159, 187, 18, 219, 175, 90, 200,
129, 223, 94, 54, 217, 20, 149, 98, 247, 71, 143, 104, 232, 40, 2, 114,
60, 23, 156, 196, 38, 80, 231, 58, 118, 215, 11, 204, 55, 150, 254, 186,
206, 74, 234, 139, 173, 106, 130, 3, 177, 43, 89, 164, 126, 78, 99, 29,
170, 88, 117, 12, 252, 65, 203, 161, 225, 138, 250, 191, 22, 179, 216, 142,
242, 49, 188, 31, 213, 47, 184, 26, 76, 34, 110, 64, 239, 46, 120, 8,
220, 132, 163, 102, 151, 86, 116, 244, 100, 153, 209, 15, 85, 227, 157, 68,
96, 19, 201, 72, 229, 5, 140, 218, 59, 194, 123, 172, 135, 199, 107, 36,
146, 176, 53, 249, 124, 193, 171, 21, 45, 236, 1, 93, 52, 27, 185, 245,
81, 224, 111, 16, 39, 63, 95, 158, 82, 182, 141, 253, 214, 73, 167, 6,
61, 208, 155, 137, 181, 212, 243, 128, 230, 112, 66, 37, 152, 115, 235, 127,
192, 30, 91, 238, 77, 105, 9, 33, 202, 17, 165, 222, 10, 205, 97, 44,
251, 169, 0, 50, 197, 160, 144, 57, 75, 189, 101, 131, 84, 178, 24, 145,
121, 103, 133, 221, 25, 119, 255, 174, 226, 148, 42, 248, 56, 195, 228, 70,
211, 183, 62, 233, 87, 41, 207, 92, 113, 4, 210, 168, 28, 108, 154, 14,
79, 35, 147, 190, 166, 69, 13, 134, 51, 237, 83, 122, 67, 136, 240, 48
);
int bayerB[256] = int[](
166, 21, 186, 232, 50, 196, 126, 89, 191, 71, 134, 251, 87, 205, 129, 52,
113, 70, 88, 155, 110, 78, 34, 147, 177, 107, 49, 7, 161, 103, 181, 2,
252, 198, 143, 216, 25, 170, 224, 60, 242, 29, 213, 121, 234, 35, 146, 221,
45, 122, 12, 58, 97, 247, 117, 15, 200, 95, 140, 183, 73, 194, 64, 94,
28, 160, 235, 180, 203, 136, 46, 157, 80, 167, 229, 56, 23, 245, 133, 169,
228, 82, 105, 39, 72, 0, 188, 220, 127, 9, 40, 154, 111, 86, 13, 206,
53, 142, 249, 128, 214, 151, 90, 238, 66, 104, 250, 208, 174, 223, 119, 187,
69, 6, 193, 24, 168, 55, 112, 20, 175, 192, 76, 135, 1, 47, 156, 100,
149, 210, 116, 85, 227, 33, 254, 207, 43, 144, 30, 96, 63, 199, 233, 27,
240, 41, 163, 65, 182, 138, 99, 159, 120, 231, 215, 164, 244, 125, 79, 179,
108, 217, 92, 246, 11, 197, 74, 4, 59, 84, 16, 109, 185, 38, 14, 137,
57, 18, 130, 153, 48, 123, 171, 241, 202, 132, 178, 51, 145, 222, 91, 201,
172, 75, 190, 31, 236, 218, 106, 37, 152, 26, 248, 209, 5, 68, 158, 255,
8, 225, 114, 204, 83, 22, 67, 184, 226, 93, 77, 124, 102, 239, 118, 44,
98, 148, 61, 176, 101, 162, 141, 54, 115, 165, 42, 195, 173, 32, 189, 139,
211, 243, 36, 131, 3, 253, 212, 10, 237, 17, 219, 150, 62, 19, 230, 81
);
float bayerSize = 16.0;
float bayerDivider = bayerSize * bayerSize;
float quant = 63.0; // 64 steps -> 63.0; 256 steps -> 255.0
vec4 quantizer = vec4(quant);
vec4 quantizerDivider = vec4(1.0 / quant);
vec4 nearestColour(vec4 incolor) {
vec4 rgbaCounts = vec4(rcount, gcount, bcount, 1.0);
vec2 boolean = vec2(0.0, 1.0);
vec4 halfvec = vec4(0.5);
vec4 color = incolor;
color.r = floor((rgbaCounts.r - 1.0) * color.r + 0.5) / (rgbaCounts.r - 1.0);
color.g = floor((rgbaCounts.g - 1.0) * color.g + 0.5) / (rgbaCounts.g - 1.0);
color.b = floor((rgbaCounts.b - 1.0) * color.b + 0.5) / (rgbaCounts.b - 1.0);
color.a = 1.0;
return color;
vec4 nearestColour(vec4 inColor) {
return floor(quantizer * inColor + halfvec) * quantizerDivider;
}
void main(void) {
float spread = 1.0 / (0.299 * (rcount - 1.0) + 0.587 * (gcount - 1.0) + 0.114 * (bcount - 1.0)); // this spread value is optimised one -- try your own values for various effects!
float scale = v_texCoords.y * (1.0 - parallax_size) + (parallax_size / 2.0) + (parallax * parallax_size / 2.0);
float zoomSamplePoint = (1.0 - zoomInv) / 2.0; // will never quite exceed 0.5
float zoomSamplePoint = (1.0 - zoomInv) / 2.0;// will never quite exceed 0.5
// I don't even know if it works, and also not sure if I actually want it
vec3 newBottom = mix(bottomColor, topColor, zoomSamplePoint);
vec3 newTop = mix(topColor, bottomColor, zoomSamplePoint);
vec4 inColor = vec4(mix(newBottom, newTop, scale), 1.0);
vec4 inColor = v_color * vec4(mix(newBottom, newTop, scale), 1.0);
vec2 entry = mod(gl_FragCoord.xy, vec2(bayerSize, bayerSize));
gl_FragColor = nearestColour(inColor + spread * (bayer[int(entry.y) * int(bayerSize) + int(entry.x)] / bayerDivider - 0.5));
vec4 bayerThreshold = vec4(
bayerR[int(entry.y) * int(bayerSize) + int(entry.x)] / bayerDivider - 0.5,
bayerG[int(entry.y) * int(bayerSize) + int(entry.x)] / bayerDivider - 0.5,
bayerB[int(entry.y) * int(bayerSize) + int(entry.x)] / bayerDivider - 0.5,
0.5
);
vec4 selvec = nearestColour(inColor + bayerThreshold * quantizerDivider);
gl_FragColor = selvec * boolean.yyyx + inColor * boolean.xxxy;
}
/*

BIN
assets/LDR_RGB1_15.png LFS Normal file

Binary file not shown.

30
assets/alphadither.frag Normal file
View File

@@ -0,0 +1,30 @@
#version 120
#ifdef GL_ES
precision mediump float;
#endif
varying vec4 v_color;
varying vec2 v_texCoords;
uniform sampler2D u_texture;
//int bayer[14 * 14] = int[](131,187,8,78,50,18,134,89,155,102,29,95,184,73,22,86,113,171,142,105,34,166,9,60,151,128,40,110,168,137,45,28,64,188,82,54,124,189,80,13,156,56,7,61,186,121,154,6,108,177,24,100,38,176,93,123,83,148,96,17,88,133,44,145,69,161,139,72,30,181,115,27,163,47,178,65,164,14,120,48,5,127,153,52,190,58,126,81,116,21,106,77,173,92,191,63,99,12,76,144,4,185,37,149,192,39,135,23,117,31,170,132,35,172,103,66,129,79,3,97,57,159,70,141,53,94,114,20,49,158,19,146,169,122,183,11,104,180,2,165,152,87,182,118,91,42,67,25,84,147,43,85,125,68,16,136,71,10,193,112,160,138,51,111,162,26,194,46,174,107,41,143,33,74,1,101,195,15,75,140,109,90,32,62,157,98,167,119,179,59,36,130,175,55,0,150);
//float bayerSize = 14.0;
int bayer[4*4] = int[](0,8,2,10,12,4,14,6,3,11,1,9,15,7,13,5);
float bayerSize = 4.0;
float bayerDivider = bayerSize * bayerSize;
vec2 boolean = vec2(0.0, 1.0);
void main() {
vec4 inColor = v_color * (texture2D(u_texture, v_texCoords));
vec2 entry = mod(gl_FragCoord.xy, vec2(bayerSize, bayerSize));
float bayerThreshold = bayer[int(entry.y) * int(bayerSize) + int(entry.x)] / bayerDivider;
float alpha = inColor.a;
vec4 selvec0 = vec4(0.0, 0.0, 0.0, (alpha > 1.0 / bayerDivider) ? 1.0 : 0.0);
vec4 selvec = vec4(1.0, 1.0, 1.0, (alpha >= bayerThreshold) ? 1.0 : 0.0);
vec4 out0 = inColor * boolean.yyyx + selvec0;
gl_FragColor = out0 * selvec;
}

BIN
assets/graphics/gui/toggler.tga LFS Normal file

Binary file not shown.

View File

@@ -32,6 +32,7 @@ import net.torvald.terrarum.modulebasegame.TerrarumIngame;
import net.torvald.terrarum.modulebasegame.ui.ItemSlotImageFactory;
import net.torvald.terrarum.serialise.WriteConfig;
import net.torvald.terrarum.tvda.DiskSkimmer;
import net.torvald.terrarum.ui.Toolkit;
import net.torvald.terrarum.utils.JsonFetcher;
import net.torvald.terrarum.worlddrawer.CreateTileAtlas;
import net.torvald.terrarumsansbitmap.gdx.GameFontBase;
@@ -591,8 +592,9 @@ public class App implements ApplicationListener {
setCameraPosition(0f, 0f);
int drawWidth = Toolkit.INSTANCE.getDrawWidth();
int safetyTextLen = fontGame.getWidth(Lang.INSTANCE.get("APP_WARNING_HEALTH_AND_SAFETY", true));
int logoPosX = (scr.getWidth() - logo.getRegionWidth() - safetyTextLen) >>> 1;
int logoPosX = (drawWidth - logo.getRegionWidth() - safetyTextLen) >>> 1;
int logoPosY = Math.round(scr.getHeight() / 15f);
int textY = logoPosY + logo.getRegionHeight() - 16;
@@ -605,7 +607,7 @@ public class App implements ApplicationListener {
logoBatch.draw(logo, logoPosX, logoPosY + logo.getRegionHeight());
}
else {
logoBatch.draw(logo, (scr.getWidth() - logo.getRegionWidth()) / 2f,
logoBatch.draw(logo, (drawWidth - logo.getRegionWidth()) / 2f,
(scr.getHeight() - logo.getRegionHeight() * 2) / 2f + logo.getRegionHeight()
);
}
@@ -631,7 +633,7 @@ public class App implements ApplicationListener {
String s = Lang.INSTANCE.get("APP_CHINESE_HEALTHY_GAME_MSG_" + i, true);
fontGame.draw(logoBatch, s,
(scr.getWidth() - fontGame.getWidth(s)) >>> 1,
(drawWidth - fontGame.getWidth(s)) >>> 1,
Math.round(scr.getHeight() * 12f / 15f + fontGame.getLineHeight() * (i - 1))
);
}
@@ -642,12 +644,12 @@ public class App implements ApplicationListener {
Texture tex2 = CommonResourcePool.INSTANCE.getAsTexture("title_health2");
int virtualHeight = scr.getHeight() - logoPosY - logo.getRegionHeight() / 4;
int virtualHeightOffset = scr.getHeight() - virtualHeight;
logoBatch.draw(tex1, (scr.getWidth() - tex1.getWidth()) >>> 1, virtualHeightOffset + (virtualHeight >>> 1) - 16, tex1.getWidth(), -tex1.getHeight());
logoBatch.draw(tex2, (scr.getWidth() - tex2.getWidth()) >>> 1, virtualHeightOffset + (virtualHeight >>> 1) + 16 + tex2.getHeight(), tex2.getWidth(), -tex2.getHeight());
logoBatch.draw(tex1, (drawWidth - tex1.getWidth()) >>> 1, virtualHeightOffset + (virtualHeight >>> 1) - 16, tex1.getWidth(), -tex1.getHeight());
logoBatch.draw(tex2, (drawWidth - tex2.getWidth()) >>> 1, virtualHeightOffset + (virtualHeight >>> 1) + 16 + tex2.getHeight(), tex2.getWidth(), -tex2.getHeight());
}
else {
logoBatch.draw(logo, (scr.getWidth() - logo.getRegionWidth()) / 2f,
logoBatch.draw(logo, (drawWidth - logo.getRegionWidth()) / 2f,
(scr.getHeight() - logo.getRegionHeight() * 2) / 2f
);
}

View File

@@ -17,8 +17,8 @@ class ChunkLoadingLoadScreen(screenToBeLoaded: IngameInstance, private val world
private val world: GameWorld // must use Getter, as the field WILL BE redefined by the TerrarumIngame.enterCreateNewWorld() !
get() = screenToLoad!!.world
private var previewWidth = (App.scr.width * WorldgenLoadScreen.WIDTH_RATIO).roundToInt()
private var previewHeight = (App.scr.width * WorldgenLoadScreen.WIDTH_RATIO * worldheight / worldwidth).roundToInt()
private var previewWidth = (Toolkit.drawWidth * WorldgenLoadScreen.WIDTH_RATIO).roundToInt()
private var previewHeight = (Toolkit.drawWidth * WorldgenLoadScreen.WIDTH_RATIO * worldheight / worldwidth).roundToInt()
private lateinit var previewPixmap: Pixmap
private lateinit var previewTexture: Texture
@@ -40,6 +40,7 @@ class ChunkLoadingLoadScreen(screenToBeLoaded: IngameInstance, private val world
override fun render(delta: Float) {
gdxClearAndSetBlend(.094f, .094f, .094f, 0f)
val drawWidth = Toolkit.drawWidth
if (worldwidth != -1 && worldheight != -1) {
@@ -54,7 +55,7 @@ class ChunkLoadingLoadScreen(screenToBeLoaded: IngameInstance, private val world
App.batch.inUse {
it.color = Color.WHITE
val previewX = (App.scr.width - previewWidth).div(2f).round()
val previewX = (drawWidth - previewWidth).div(2f).round()
val previewY = (App.scr.height - previewHeight.times(1.5f)).div(2f).round()
Toolkit.drawBoxBorder(it, previewX.toInt() - 1, previewY.toInt() - 1, previewWidth + 2, previewHeight + 2)
it.draw(previewTexture,
@@ -64,7 +65,7 @@ class ChunkLoadingLoadScreen(screenToBeLoaded: IngameInstance, private val world
val text = messages.getHeadElem() ?: ""
App.fontGame.draw(it,
text,
(App.scr.width - App.fontGame.getWidth(text)).div(2f).round(),
(drawWidth - App.fontGame.getWidth(text)).div(2f).round(),
previewY + previewHeight + 98 - App.fontGame.lineHeight
)
}

View File

@@ -57,6 +57,7 @@ object IngameRenderer : Disposable {
val shaderRGBOnly: ShaderProgram
val shaderAtoGrey: ShaderProgram
val shaderPassthru = SpriteBatch.createDefaultShader()
val shaderAlphaDither: ShaderProgram
private val WIDTH = App.scr.width
private val HEIGHT = App.scr.height
@@ -98,11 +99,13 @@ object IngameRenderer : Disposable {
shaderBayer.setUniformf("rcount", 64f)
shaderBayer.setUniformf("gcount", 64f)
shaderBayer.setUniformf("bcount", 64f)
}
else {
shaderBayer = App.loadShaderFromFile("assets/4096.vert", "assets/passthrurgb.frag")
}
shaderAlphaDither = App.loadShaderFromFile("assets/4096.vert", "assets/alphadither.frag")
shaderBlendGlow = App.loadShaderFromFile("assets/blendGlow.vert", "assets/blendGlow.frag")
@@ -406,12 +409,16 @@ object IngameRenderer : Disposable {
batch.inUse {
moveCameraToWorldCoord()
actorsRenderBehind?.forEach { it.drawBody(batch) }
}
batch.shader = shaderAlphaDither
batch.inUse {
particlesContainer?.forEach { it.drawBody(batch) }
}
setCameraPosition(0f, 0f)
BlocksDrawer.drawTerrain(batch.projectionMatrix, false)
batch.shader = null
batch.inUse {
/////////////////
// draw actors //
@@ -739,6 +746,7 @@ object IngameRenderer : Disposable {
shaderRGBOnly.dispose()
shaderAtoGrey.dispose()
shaderPassthru.dispose()
shaderAlphaDither.dispose()
try {
fboRGBexport.dispose()

View File

@@ -34,8 +34,8 @@ class WorldgenLoadScreen(screenToBeLoaded: IngameInstance, private val worldwidt
val COL_AIR = Color.BLACK
}
private val previewWidth = (App.scr.width * WIDTH_RATIO).roundToInt()
private val previewHeight = (App.scr.width * WIDTH_RATIO * worldheight / worldwidth).roundToInt()
private val previewWidth = (Toolkit.drawWidth * WIDTH_RATIO).roundToInt()
private val previewHeight = (Toolkit.drawWidth * WIDTH_RATIO * worldheight / worldwidth).roundToInt()
private lateinit var previewPixmap: Pixmap
private lateinit var previewTexture: Texture
@@ -57,6 +57,8 @@ class WorldgenLoadScreen(screenToBeLoaded: IngameInstance, private val worldwidt
override fun render(delta: Float) {
gdxClearAndSetBlend(.094f, .094f, .094f, 0f)
val drawWidth = Toolkit.drawWidth
previewRenderCounter += delta
if (previewRenderCounter >= PREVIEW_UPDATE_RATE) {
previewRenderCounter -= PREVIEW_UPDATE_RATE
@@ -68,7 +70,7 @@ class WorldgenLoadScreen(screenToBeLoaded: IngameInstance, private val worldwidt
App.batch.inUse {
it.color = Color.WHITE
val previewX = (App.scr.width - previewWidth).div(2f).round()
val previewX = (drawWidth - previewWidth).div(2f).round()
val previewY = (App.scr.height - previewHeight.times(1.5f)).div(2f).round()
Toolkit.drawBoxBorder(it, previewX.toInt()-1, previewY.toInt()-1, previewWidth+2, previewHeight+2)
it.draw(previewTexture,
@@ -78,7 +80,7 @@ class WorldgenLoadScreen(screenToBeLoaded: IngameInstance, private val worldwidt
val text = messages.getHeadElem() ?: ""
App.fontGame.draw(it,
text,
(App.scr.width - App.fontGame.getWidth(text)).div(2f).round(),
(drawWidth - App.fontGame.getWidth(text)).div(2f).round(),
previewY + previewHeight + 98 - App.fontGame.lineHeight
)
}

View File

@@ -0,0 +1,18 @@
package net.torvald.terrarum.modulebasegame.console
import net.torvald.terrarum.App
import net.torvald.terrarum.console.ConsoleCommand
import net.torvald.terrarum.console.Echo
/**
* Created by minjaesong on 2021-10-06.
*/
object StreamerMode : ConsoleCommand {
override fun execute(args: Array<String>) {
App.setConfig("fx_streamerslayout", !App.getConfigBoolean("fx_streamerslayout"))
}
override fun printUsage() {
Echo("Toggles Streamer Mode")
}
}

View File

@@ -23,7 +23,7 @@ object Toolkit : Disposable {
val DEFAULT_BOX_BORDER_COL = Color(1f, 1f, 1f, 0.2f)
private val shaderBlur = App.loadShaderFromFile("assets/blur.vert", "assets/blur2.frag")
val baloonTile = TextureRegionPack("assets/graphics/gui/message_black_tileable.tga", 36, 36)
val baloonTile = TextureRegionPack("assets/graphics/gui/message_black_tileable.tga", 36, 36, flipY = true)
init {