第 11 课:Cellular Noise
实现
uniform vec2 iResolution;
uniform float iTime;
vec2 points[9];
void init() {
points[0] = vec2(0.05,0.15);
points[1] = vec2(0.35,0.27);
points[2] = vec2(0.78,0.04);
points[3] = vec2(0.25,0.46);
points[4] = vec2(0.50,0.55);
points[5] = vec2(0.91,0.37);
points[6] = vec2(0.28,0.67);
points[7] = vec2(0.53,0.76);
points[8] = vec2(0.73,0.75);
}
vec2 getPoint(int index) {
return sin(points[index] * 6.28 + iTime / 3.0) * 0.5 + 0.5;
}
void main() {
init();
vec2 uv = gl_FragCoord.xy / iResolution.xy;
float m_dist = 1.0;
for(int i = 0; i < 9; i++){
float newDist = distance(uv, getPoint(i));
m_dist = newDist < m_dist ? newDist : m_dist;
}
gl_FragColor = vec4(0.0, m_dist * 2.25, 0.0, 1.0);
}