Shadertoy学习笔记(四)飘落的花瓣

ε祈祈猫儿з 提交于 2019-12-22 18:48:40

首先画一个圆 

#define S(a,b,t) smoothstep(a,b,t)

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    // Normalized pixel coordinates (from 0 to 1)
    vec2 uv = (fragCoord.xy - .5*iResolution.xy)/iResolution.y;
    vec3 col = vec3(0.);
    float d = length(uv);
    float c = S(.3,.28,d);
    col = vec3(c);
    
    fragColor = vec4(col,1.);
}

心形 

   uv.x*=.7;
    uv.y -= sqrt(abs(uv.x))*.5;

增加模糊

#define S(a,b,t) smoothstep(a,b,t)

float smax(float a,float b,float k)
{
    float h = clamp((b-a)/k+.5,0.,1.);
    return mix(a,b,h)+h*(1.-h)*k*.5;
}



void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    // Normalized pixel coordinates (from 0 to 1)
    vec2 uv = (fragCoord.xy - .5*iResolution.xy)/iResolution.y;
    vec2 m = iMouse.xy/iResolution.xy;
    
    float r = .3;
    float b = m.y*r;
    
    uv.x*=.7;
    uv.y -= smax(sqrt(abs(uv.x))*.5,b,.1);
    uv.y += .1+b*.5;
    vec3 col = vec3(0.);
    float d = length(uv);
    
    float c = S(r+b,r-b,d);
    col = vec3(c);
    
    fragColor = vec4(col,1.);
}

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!