shader cleanup; a config key for higher bits per pixel on graphics

This commit is contained in:
minjaesong
2022-03-25 15:49:43 +09:00
parent af542e43a9
commit 327e000a54
17 changed files with 39 additions and 193 deletions

View File

@@ -1,14 +0,0 @@
varying vec4 v_color;
varying vec2 v_texCoords;
uniform sampler2D u_texture;
void main(void) {
vec4 color = texture2D(u_texture, v_texCoords).rgba;
color.r = floor(15.0 * color.r + 0.5) / 15.0;
color.g = floor(15.0 * color.g + 0.5) / 15.0;
color.b = floor(15.0 * color.b + 0.5) / 15.0;
// a: passthrough
gl_FragColor = color;
}

View File

@@ -1,43 +0,0 @@
/**
* Blue Noise texture created by Christoph Peters, released under CC0
* http://momentsingraphics.de/BlueNoise.html
*/
#version 130
#ifdef GL_ES
precision mediump float;
#endif
varying vec4 v_color;
varying vec2 v_texCoords;
uniform sampler2D u_texture;
uniform sampler2D u_pattern;
uniform ivec2 rnd = ivec2(0,0);
float quant = 127.0; // 64 steps -> 63.0; 256 steps -> 255.0
vec4 quantiser = vec4(quant);
vec4 quantiserDivider = vec4(1.0 / quant);
vec2 boolean = vec2(0.0, 1.0);
vec4 halfvec = vec4(0.5);
vec2 patternsize = vec2(1.0/512.0, 1.0/512.0);
vec4 nearestColour(vec4 inColor) {
return floor(quantiser * inColor + halfvec) * quantiserDivider;
}
vec4 getDitherredDot(vec4 inColor) {
vec4 bayerThreshold = vec4(texture2D(u_pattern, (gl_FragCoord.xy + rnd) * patternsize) - 0.5);
return nearestColour(bayerThreshold * quantiserDivider + inColor);
}
void main(void) {
// create texture coordinates based on pixelSize //
vec4 inColor = v_color * (texture2D(u_texture, v_texCoords)).aaaa;
vec4 selvec = getDitherredDot(inColor);
gl_FragColor = selvec * boolean.yyyx + boolean.xxxy; // use quantised RGB but not the A
}

View File

@@ -1,43 +0,0 @@
/**
* Blue Noise texture created by Christoph Peters, released under CC0
* http://momentsingraphics.de/BlueNoise.html
*/
#version 130
#ifdef GL_ES
precision mediump float;
#endif
varying vec4 v_color;
varying vec2 v_texCoords;
uniform sampler2D u_texture;
uniform sampler2D u_pattern;
uniform ivec2 rnd = ivec2(0,0);
float quant = 127.0; // 64 steps -> 63.0; 256 steps -> 255.0
vec4 quantiser = vec4(quant);
vec4 quantiserDivider = vec4(1.0 / quant);
vec2 boolean = vec2(0.0, 1.0);
vec4 halfvec = vec4(0.5);
vec2 patternsize = vec2(1.0/512.0, 1.0/512.0);
vec4 nearestColour(vec4 inColor) {
return floor(quantiser * inColor + halfvec) * quantiserDivider;
}
vec4 getDitherredDot(vec4 inColor) {
vec4 bayerThreshold = vec4(texture2D(u_pattern, (gl_FragCoord.xy + rnd) * patternsize) - 0.5);
return nearestColour(bayerThreshold * quantiserDivider + inColor);
}
void main(void) {
// create texture coordinates based on pixelSize //
vec4 inColor = v_color * (texture2D(u_texture, v_texCoords));
vec4 selvec = getDitherredDot(inColor);
gl_FragColor = selvec * boolean.yyyx + boolean.xxxy; // use quantised RGB but not the A
}

View File

@@ -1,59 +0,0 @@
/**
* Blue Noise texture created by Christoph Peters, released under CC0
* http://momentsingraphics.de/BlueNoise.html
*/
#version 130
#ifdef GL_ES
precision mediump float;
#endif
varying vec4 v_color;
varying vec2 v_texCoords;
uniform sampler2D u_texture;
uniform sampler2D u_pattern;
uniform ivec2 rnd = ivec2(0,0);
float quant = 127.0; // 64 steps -> 63.0; 256 steps -> 255.0
vec4 quantiser = vec4(quant);
vec4 quantiserDivider = vec4(1.0 / quant);
vec2 boolean = vec2(0.0, 1.0);
vec4 halfvec = vec4(0.5);
vec2 patternsize = vec2(1.0/512.0, 1.0/512.0);
vec4 nearestColour(vec4 inColor) {
return floor(quantiser * inColor + halfvec) * quantiserDivider;
}
vec4 getDitherredDot(vec4 inColor) {
vec4 bayerThreshold = vec4(texture2D(u_pattern, (gl_FragCoord.xy + rnd) * patternsize) - 0.5);
return nearestColour(bayerThreshold * quantiserDivider + inColor);
}
uniform vec2 iResolution;
uniform float flip;
uniform vec2 direction;
vec4 blur(sampler2D image, vec2 uv, vec2 resolution, vec2 direction) {
vec4 color = vec4(0.0);
vec2 off1 = vec2(1.3846153846) * direction;
vec2 off2 = vec2(3.2307692308) * direction;
color += texture2D(image, uv) * 0.2270270270;
color += texture2D(image, uv + (off1 / resolution)) * 0.3162162162;
color += texture2D(image, uv - (off1 / resolution)) * 0.3162162162;
color += texture2D(image, uv + (off2 / resolution)) * 0.0702702703;
color += texture2D(image, uv - (off2 / resolution)) * 0.0702702703;
return color;
}
void main() {
vec2 uv = vec2(gl_FragCoord.xy / iResolution.xy);
if (flip == 1.0) { uv.y = 1.0 - uv.y; }
vec4 inColor = blur(u_texture, uv, iResolution.xy, direction);
vec4 selvec = getDitherredDot(inColor);
gl_FragColor = selvec; // quantise all four RGBA
}

View File

@@ -23,9 +23,7 @@ uniform sampler2D u_texture;
uniform sampler2D u_pattern;
uniform ivec2 rnd = ivec2(0,0);
float quant = 255.0; // 64 steps -> 63.0; 256 steps -> 255.0
vec4 quantiser = vec4(quant);
vec4 quantiserDivider = vec4(1.0 / quant);
uniform float quant = 255.0; // 64 steps -> 63.0; 256 steps -> 255.0
vec2 boolean = vec2(0.0, 1.0);
vec4 halfvec = vec4(0.5);
@@ -33,12 +31,12 @@ vec4 halfvec = vec4(0.5);
vec2 patternsize = vec2(1.0/512.0, 1.0/512.0);
vec4 nearestColour(vec4 inColor) {
return floor(quantiser * inColor + halfvec) * quantiserDivider;
return floor(vec4(quant) * inColor + halfvec) * vec4(1.0 / quant);
}
vec4 getDitherredDot(vec4 inColor) {
vec4 bayerThreshold = vec4(texture2D(u_pattern, (gl_FragCoord.xy + rnd) * patternsize) - 0.5);
return nearestColour(bayerThreshold * quantiserDivider + inColor);
return nearestColour(bayerThreshold * vec4(1.0 / quant) + inColor);
}

View File

@@ -19,7 +19,7 @@ uniform float parallax_size = 1.0/3.0; // 0: no parallax
uniform float zoomInv = 1.0;
float quant = 63.0; // 64 steps -> 63.0; 256 steps -> 255.0
float quant = 255.0; // 64 steps -> 63.0; 256 steps -> 255.0
vec4 quantiser = vec4(quant);
vec4 quantiserDivider = vec4(1.0 / quant);