第 10 课:Noise Texture
实现
uniform vec2 iResolution;
uniform float iTime;
uniform sampler2D iChannel0;
float sdfBox(vec2 center, vec2 size, vec2 pos) {
vec2 d = abs(pos - center) - size;
return length(max(d, 0.0)) + min(max(d.x, d.y), 0.0);
}
void main() {
vec2 aspect = vec2(iResolution.x / iResolution.y, 1.0);
vec2 uv = gl_FragCoord.xy / iResolution.xy;
float time = iTime * 0.25;
vec4 noise = texture(iChannel0, fract(uv - vec2(0.0,time)));
float distortion = noise.x; // sample noise value
distortion *= uv.y;
distortion *= 0.4;
vec2 center = vec2(0.5, 0.4);
float shape = sdfBox(center * aspect, vec2(0.5, 0.15), uv * aspect);
shape = max(shape - distortion, 0.0);
float t = 1.0 - smoothstep(0.0, 0.1, shape);
vec3 color = vec3(1.5, 1.0, 0.25) * t * (distortion + 0.6);
gl_FragColor = vec4(color * color, 1.0);
}