Loops 为什么循环中的声明会打断动画?
我正在尝试制作一个降雪动画,为什么当Loops 为什么循环中的声明会打断动画?,loops,glsl,Loops,Glsl,我正在尝试制作一个降雪动画,为什么当y在循环外声明时,我的动画不工作 vec3 circle(in vec2 r, in vec2 center, in float radius) { return vec3(smoothstep(1.0, 0.0, smoothstep(0.0, 0.01, length(r-center)-radius))); } void snow(inout vec3 ret, in vec2 r, in float time) { vec3 m
y
在循环外声明时,我的动画不工作
vec3 circle(in vec2 r, in vec2 center, in float radius)
{
return vec3(smoothstep(1.0, 0.0, smoothstep(0.0, 0.01, length(r-center)-radius)));
}
void snow(inout vec3 ret, in vec2 r, in float time)
{
vec3 membership;
membership = vec3(0.0);
// Why this declaration of "y" DOESNT work?
//float y;
float x;
for(float j=0.0; j < 1.0; j+=0.9)
{
for(float i=0.0; i < 1.0; i+=0.3)
{
// But this one DOES ?
float y;
y = iGlobalTime * 0.3;
x = -0.98 + i*0.3;
membership+= circle(r, vec2(x, 0.5 - mod(y, 1.0)), 0.001);
ret = mix(ret, vec3(0.9, 0.9, 1.0), membership);
}
}
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 r = (fragCoord.xy - 0.5 * iResolution.xy) / iResolution.y ;
vec3 ret = vec3(0.0, 1.0 - (r.y+1.4)*0.5, 1.0 - (r.y+0.9)*0.5);
snow(ret, r, iGlobalTime);
fragColor = vec4(ret.x, ret.y, ret.z, 1.);
}
vec3圆(在vec2 r中,在vec2中心,在浮动半径中)
{
返回vec3(平滑步长(1.0,0.0,平滑步长(0.0,0.01,长度(r-中心)-半径));
}
无效雪(inout vec3 ret、vec2 r、浮动时间)
{
vec3成员资格;
成员资格=vec3(0.0);
//为什么这个“y”的声明不起作用?
//浮动y;
浮动x;
对于(浮动j=0.0;j<1.0;j+=0.9)
{
对于(浮动i=0.0;i<1.0;i+=0.3)
{
//但是这个有吗?
浮动y;
y=iGlobalTime*0.3;
x=-0.98+i*0.3;
隶属度+=圆(r,vec2(x,0.5-mod(y,1.0)),0.001);
ret=混合(ret,vec3(0.9,0.9,1.0),成员资格);
}
}
}
无效主图像(输出vec4 fragColor,输入vec2 fragCoord)
{
vec2r=(fragCoord.xy-0.5*iResolution.xy)/iResolution.y;
vec3-ret=vec3(0.0,1.0-(r.y+1.4)*0.5,1.0-(r.y+0.9)*0.5);
雪(ret、r、iGlobalTime);
fragColor=vec4(ret.x,ret.y,ret.z,1.);
}
我无法在shadertoy中复制它,这两种方式似乎都很好这很奇怪,对我来说,这确实发生在chrome和ff中,但在ieconfired中没有。在循环外声明y会打断Chrome中的动画,但不会打断Edge中的动画。我觉得这是沙德托的问题。我看不出这对你的代码有什么影响。我是在firefox上做的,仅供参考