本文最后更新于41 天前,其中的信息可能已经过时,如有错误请发送邮件到marcelozoeng@qq.com
一个圆
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
// Normalized pixel coordinates (from 0 to 1)
vec2 uv = fragCoord/iResolution.xy;
uv -= 0.5;// -.5 <> .5
uv.x *= iResolution.x / iResolution.y;
float d = length(uv);
float r = 0.3;
float c = smoothstep(r , r -0.05, d);
//if ( d < 0.3) d = 1.; else d = 0.;
// Output to screen
fragColor = vec4(vec3(c),1.0);
}
微笑小黄脸
float Circle (vec2 uv, vec2 p, float r, float blur)
{
float d = length(uv - p);
float c = smoothstep(r , r - blur, d);
return c;
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
// Normalized pixel coordinates (from 0 to 1)
vec2 uv = fragCoord/iResolution.xy;
uv -= 0.5;// uv -= vec2(.5, .5);
uv.x *= iResolution.x / iResolution.y;
//颜色
vec3 col = vec3(0);
//眼睛
float c = Circle(uv, vec2(0), .4, .05);
c -= Circle(uv, vec2(.1, .1), .07, .01);
c -= Circle(uv, vec2(-.1, .1), .07, .01);
//嘴巴
float mouth = Circle(uv, vec2(0.,0.), .25, .01);
mouth -= Circle(uv, vec2(0., 0.05), .25, .01);
c -= mouth;
// Output to screen
col = vec3(1., 1., 0.)*c;
fragColor = vec4(col,1.0);
}
float Circle (vec2 uv, vec2 p, float r, float blur)
{
float d = length(uv - p);
float c = smoothstep(r , r - blur, d);
return c;
}
float smiley(vec2 uv, vec2 p, float size){
uv -= p;//转换坐标系
uv /= size;//缩放坐标系
float c = Circle(uv, vec2(0), .4, .01);//c就是mask遮罩
c -= Circle(uv, vec2(.1, .1), .07, .01);
c -= Circle(uv, vec2(-.1, .1), .07, .01);
float mouth = Circle(uv, vec2(0.,0.), .25, .01);
mouth -= Circle(uv, vec2(0., 0.05), .25, .01);
c -= mouth;
return c;
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
// Normalized pixel coordinates (from 0 to 1)
vec2 uv = fragCoord/iResolution.xy;
uv -= 0.5;// uv -= vec2(.5, .5);
uv.x *= iResolution.x / iResolution.y;
vec3 col = vec3(0);
float mask = smiley(uv, vec2(0,0.), 1.);
//col = vec3(mouth);
//if ( d < 0.3) d = 1.; else d = 0.;
//vec3 col = 0.5 + vec3(0,2,4);
// Time varying pixel color
//vec3 col = 0.5 + 0.5*cos(iTime+uv.xyx+vec3(0,2,4));
// Output to screen
//fragColor = vec4(col,1.0);
col = vec3(1., 1., 0.)*mask;
fragColor = vec4(col,1.0);
}
矩形
float Band(float t, float start, float end, float blur)
{
float step1 = smoothstep(start - blur, start + blur, t);
float step2 = smoothstep(end + blur, end - blur, t);
return step1 * step2;
}
float Rect(vec2 uv, float left,float right, float bottom, float top, float blur){
float band1= Band(uv.x, left, right, blur);
float band2= Band(uv.y, bottom, top, blur);
return band1 * band2;
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
// Normalized pixel coordinates (from 0 to 1)
vec2 uv = fragCoord/iResolution.xy;
uv -= 0.5;// uv -= vec2(.5, .5);
uv.x *= iResolution.x / iResolution.y;
vec3 col = vec3(0);
float mask = 0.;
// Output to screen
mask = Rect(uv, -0.2, .2, -0.2, .2, .01);
col = vec3(1., 1., 1.)*mask;
fragColor = vec4(col,1.0);
}