1.距离与符号
length(uv) 表示到圆心的距离
sign 函数:
如果输入值大于或等于0,则返回1。
如果输入值小于0,则返回-1
sign(Circle(uv,0.7)) 半径大于0.7返回1,小于0.7返回-1
-1的话就是黑色,1- 那就是白色了.
c = 1.0 - sign(Circle(uv,0.7)) * c;
#define PI 3.1415926
vec2 fixUV(in vec2 uv){
return (2.0 * uv - iResolution.xy) /
min(iResolution.x,iResolution.y);
}
float Circle(vec2 uv,float r){
return length(uv) - r;
}
void mainImage(out vec4 fragColor,in vec2 fragCoord){
vec2 uv = fixUV(fragCoord);
vec3 c = vec3(0.4,0.5,0.6);
c = 1.0 - sign(Circle(uv,0.7)) * c;
fragColor = vec4(c,1.0);
}
效果:
2.远近明暗
#define PI 3.1415926
vec2 fixUV(in vec2 uv){
return (2.0 * uv - iResolution.xy) /
min(iResolution.x,iResolution.y);
}
float Circle(vec2 uv,float r){
return length(uv) - r;
}
void mainImage(out vec4 fragColor,in vec2 fragCoord){
vec2 uv = fixUV(fragCoord);
vec3 c = vec3(0.4,0.5,0.6);
float d = Circle(uv,0.7);
c = 1.0 - sign(d) * c;
//离圆心越近越亮
c *= 1.0 - exp(-3.0 * abs(d));
fragColor = vec4(c,1.0);
}
效果: