Skip to content

Instantly share code, notes, and snippets.

@qoh
Last active May 11, 2020 04:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qoh/07b8440d58205897c3cb5ad5f5d475b2 to your computer and use it in GitHub Desktop.
Save qoh/07b8440d58205897c3cb5ad5f5d475b2 to your computer and use it in GitHub Desktop.
#version 120
#extension GL_EXT_texture_array : require
#extension GL_EXT_texture_array : enable
vec2 poissonDisk[36] = vec2[](
vec2(-0.412506, -0.505401),
vec2(-0.198678, -0.362386),
vec2(0.0612825, -0.360698),
vec2(-0.680803, -0.662816),
vec2(-0.275453, -0.057909),
vec2(-0.57524, -0.225002),
vec2(-0.135255, -0.644076),
vec2(-0.357393, -0.873324),
vec2(0.087715, -0.83279),
vec2(0.274221, -0.575671),
vec2(0.012977, 0.0652626),
vec2(-0.908303, -0.306803),
vec2(-0.632239, 0.236252),
vec2(-0.972579, 0.0551293),
vec2(-0.907004, 0.400391),
vec2(0.26208, -0.129809),
vec2(0.515364, -0.235511),
vec2(0.470022, -0.743824),
vec2(0.62804, -0.459096),
vec2(0.332402, 0.200743),
vec2(0.83457, -0.0398735),
vec2(0.645883, 0.24368),
vec2(0.367844, 0.453785),
vec2(0.700306, 0.512157),
vec2(-0.414574, 0.413026),
vec2(-0.51206, 0.680345),
vec2(0.40368, 0.800573),
vec2(-0.0603344, 0.708574),
vec2(0.0684587, 0.385982),
vec2(-0.209951, 0.191194),
vec2(-0.273511, 0.918154),
vec2(0.19039, 0.661354),
vec2(0.511419, 0.0151699),
vec2(0.962834, -0.256675),
vec2(0.897324, 0.331031),
vec2(0.00145936, 0.959284)
);
varying vec4 vPos;
uniform sampler2DArray stex;
uniform vec4 far_d;
void main() {
int index;
float fudge;
float fact;
if (vPos.y < far_d.x) {
index = 0;
fudge = 0.1f / 2048;
fact = 4;
} else if (vPos.y < far_d.y) {
index = 1;
fudge = 0.2f / 2048;
fact = 2.9f;
} else if (vPos.y < far_d.z) {
index = 2;
fudge = 0.3f / 2048;
fact = 1.45f;
} else {
index = 3;
fudge = 0.4f / 2048;
fact = 0.5f;
}
vec4 coord = gl_TextureMatrix[index]*vPos;
float threshold = coord.z - fudge;
coord.z = float(index);
// float coef = (texture2DArray(stex, vec3(coord.xy, index)).x > threshold) ? 1 : 0;
float coef = 0.0f;
for (int i = 0; i < 36; i++) {
vec2 offset = poissonDisk[i] * (fact * 0.001f);
float sample = texture2DArray(stex, vec3(coord.xy + offset, index)).x;
if (sample > threshold) coef += 1.0f / 36;
}
gl_FragColor = vec4(coef, coef, coef, 1.0f);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment