第 3 课:Vector Scalar Multiplication
我的解:向量的放大和位移
我的解
uniform float iTime;
uniform vec2 iResolution;
float circle(vec2 c, vec2 uv) {
return 1.0 - smoothstep(0.19, 0.2, distance(c, uv));
}
void main() {
vec2 uv = gl_FragCoord.xy / iResolution.xy;
uv *= 2.0;
uv -= 1.0;
uv.x *= iResolution.x / iResolution.y;
vec2 start = vec2(-0.9, 0.0);
vec2 end = vec2(0.9, sin(iTime) * 0.7);
float t = fract(iTime);
vec2 p = (end - start)*t - vec2(0.9, 0.0); // FIX IT
vec3 result = mix(vec3(0.12), vec3(1.0, 0.3, 0.3), circle(p, uv));
gl_FragColor = vec4(result, 1.0);
}
复盘笔记
- 向量的放大和位移
- 回过头来发现自己是硬掰,我是通过时间修改了向量的大小,但是向量始终是针对世界空间的,要挪回start point的本地空间