我試圖讓燈泡發光一點,然後變得不那麼激烈。也在邊緣有點暗淡。我找到了一個代碼,我認爲它創建了我想創建的效果,但我似乎並沒有很好地理解它。下面的代碼:WebGL代碼的解釋 - 爲什麼它的工作方式
mat2 rotate2d(float angle){
return mat2(cos(angle),-sin(angle),
sin(angle),cos(angle));
}
float variation(vec2 v1, vec2 v2, float strength, float speed) {
return sin(
dot(normalize(v1), normalize(v2)) * strength + iGlobalTime * speed
)/100.0;
}
vec3 paintCircle (vec2 uv, vec2 center, float rad, float width) {
vec2 diff = center-uv;
float len = length(diff);
len += variation(diff, vec2(0.0, 1.0), 5.0, 2.0);
len -= variation(diff, vec2(1.0, 0.0), 5.0, 2.0);
float circle = smoothstep(rad-width, rad, len) - smoothstep(rad, rad+width, len);
return vec3(circle);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord)
{
vec2 uv = fragCoord.xy/iResolution.xy;
uv.x *= 1.5;
uv.x -= 0.25;
vec3 color;
float radius = 0.35;
vec2 center = vec2(0.5);
//paint color circle
color = paintCircle(uv, center, radius, 0.1);
//color with gradient
vec2 v = rotate2d(iGlobalTime) * uv;
color *= vec3(v.x, v.y, 0.7-v.y*v.x);
//paint white circle
color += paintCircle(uv, center, radius, 0.01);
fragColor = vec4(color, 1.0);
}
我不明白爲什麼我們需要標準化的向量的點積和它是如何選擇exacly:
len += variation(diff, vec2(0.0, 1.0), 5.0, 2.0);
len -= variation(diff, vec2(1.0, 0.0), 5.0, 2.0);
我的意思是 - 爲什麼會出現先增加,然後減? 那麼這是爲什麼:
vec2 uv = fragCoord.xy/iResolution.xy;
uv.x *= 1.5;
uv.x -= 0.25;
這又如何 vec2 v = rotate2d(iGlobalTime) * uv; color *= vec3(v.x, v.y, 0.7-v.y*v.x);
使顏色漸變? 如果有人喜歡在那裏看它,它的作用是:https://www.shadertoy.com/view/ltBXRc。 我顯然不是很擅長几何。如果有人可以幫助我,我會很感激它:)
是的,它的確如此。謝謝 :) – vixenn