英文:
Restrict GLSL u_time from falling below 0.5 when using it with Sin
问题
以下是您提供的GLSL代码的翻译部分:
void main() {
vec2 uv = gl_FragCoord.xy / u_resolution.xy * 10.0;
vec3 color = vec3(0.0);
float wave_width = sin(u_time); //这是我希望u_time受限制的地方
uv.y -= 4.0;
uv.y += (0.2 * sin(uv.x + u_time));
wave_width *= abs(1.0 / (10.0 * uv.y));
color += vec3(wave_width, 0.0 , 0.0);
gl_FragColor = vec4(color, 1.0);
}
请注意,这段代码中没有实际翻译的部分,只是代码本身。如果您有其他问题或需要进一步帮助,请告诉我。
英文:
I am in the process of learning glsl and I am having trouble restricting the u_time from falling below 0.5. I'd like the range of it to be from 0.5-1.0 with sin. Here is my code below where I have a line moving by sin. The restriction of where I want the u_time is labeled. It is for a glow effect to the line.
void main() {
vec2 uv = gl_FragCoord.xy / u_resolution.xy * 10.0;
vec3 color = vec3(0.0);
float wave_width = sin(u_time); //Here is where I want the u_time restricted
uv.y -= 4.0;
uv.y += (0.2 * sin(uv.x + u_time));
wave_width *= abs(1.0 / (10.0 * uv.y));
color += vec3(wave_width, 0.0 , 0.0);
gl_FragColor = vec4(color, 1.0);
}
答案1
得分: 1
函数 sin
返回一个在范围 [-1, 1] 内的数。将这个数乘以 0.25 会得到一个在范围 [-0.25, 0.25] 内的数。如果您然后加上 0.75,您会得到一个在范围 [0.5, 1.0] 内的数:
float wave_width = sin(u_time) * 0.25 + 0.75;
英文:
The function sin
returns a number in the range [-1, 1]. Scaling this number by 0.25 gives a number in the range [-0.25, 0.25]. If you then add 0.75, you get a number in the range [0.5, 1.0]:
float wave_width = sin(u_time) * 0.25 + 0.75;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论