1.代码
float almostIdentity( float x, float n )
{
return sqrt(x*x+n*n);
}
//px 为自变量,py = f(px)
float plot(float px,float py)
{
//0.02 为线的粗细
float a = smoothstep(py - 0.02,py,px);
float b = smoothstep(py,py + 0.02,px);
return a - b;
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
// Normalized pixel coordinates (from 0 to 1)
vec2 uv = fragCoord.xy / iResolution.xy;
float c = plot(almostIdentity(uv.x,abs(sin(iTime))) ,uv.y);
fragColor = vec4(vec3(c),1.0);
}
2.效果
3.Sinc Impulse函数
float sinc( float x, float k )
{
float a = 3.1415926*(k*x-1.0);
return sin(a)/a;
}
//px 为自变量,py = f(px)
float plot(float px,float py)
{
//0.02 为线的粗细
float a = smoothstep(py - 0.02,py,px);
float b = smoothstep(py,py + 0.02,px);
return a - b;
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
// Normalized pixel coordinates (from 0 to 1)
vec2 uv = fragCoord.xy / iResolution.xy;
float c = plot(sinc(uv.x * 10.0 ,abs(sin(iTime))) + 0.3 ,uv.y);
fragColor = vec4(vec3(c),1.0);
}
效果: