美文网首页unity练习
01_造型函数__shader_GLSL

01_造型函数__shader_GLSL

作者: alphonseLin | 来源:发表于2020-02-25 05:30 被阅读0次

相关函数网站

GraphToy

GraphToy界面

Shadershop

Shadershop界面

相关图片:

image.png
image.png
image.png
image.png
image.png
image.png

显示结果

视频网址

代码

#ifdef GL_ES
precision mediump float;
#endif
#define PI 3.14159265359

uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;

// Plot a line on Y using a value between 0.0-1.0
float plot(vec2 st, float pct){
  return  smoothstep( pct-0.02, pct, st.y) -
          smoothstep( pct, pct+0.02, st.y);
}

float sinc( float x, float k )
{
    float a = PI*((k*x-.0))*20.;
    return sin(a)/a+0.3;
}

float parabola( float x, float k )
{
    return pow( 4.0*x*(1.0-x), k );
}

float gain(float x, float k) 
{
    float a = 0.5*pow(2.0*((x<0.5)?x:1.0-x), k);
    return (x<0.5)?a:1.0-a;
}

float pcurve( float x, float a, float b )
{
    float k = pow(a+b,a+b) / (pow(a,a)*pow(b,b));
    return k * pow( x, a ) * pow( 1.0-x, b );
}

float expImpulse( float x, float k )
{
    float h = k*x;
    return h*exp(1.0-h);
}

float almostIdentity( float x, float n )
{
    return sqrt(x*x+n);
}

void main() {
    vec2 st = gl_FragCoord.xy/u_resolution;

    //float y=st.x*sin(u_time)*0.5+0.5;
    //float y = sinc(st.x,abs(sin(u_time)));
    //float y = parabola(st.x,abs(sin(u_time)));
    //float y = gain(st.x,abs(sin(u_time)));
    //float y = expImpulse(st.x,abs(sin(u_time)));
    //float y = pcurve(st.x,abs(sin(u_time)),abs(tan(u_time)+3.));
    float y=almostIdentity((st.x-0.5),abs(sin(u_time)));

    vec3 color = vec3(0.0, 0.0, 0.0);

    // Plot a line
    float pct = plot(st,y);
    color = (1.0-pct)*color+pct*vec3(0.9176, 0.0, 1.0);

    gl_FragColor = vec4(color,1.0);
}

书本链接

the book of shader

相关文章

网友评论

    本文标题:01_造型函数__shader_GLSL

    本文链接:https://www.haomeiwen.com/subject/hvuaqhtx.html