mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-03-09 21:31:51 +09:00
43 lines
1.1 KiB
GLSL
43 lines
1.1 KiB
GLSL
/**
|
|
* Blue Noise texture created by Christoph Peters, released under CC0
|
|
* http://momentsingraphics.de/BlueNoise.html
|
|
*/
|
|
|
|
#version 120
|
|
#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
|
|
} |