造型函数的补充

157 阅读1分钟

之前其实提过,两个图形之间,做加减乘,这三种运算,分别对应 并集, 补集 , 交集。

我最近使用这个函数,恍然小悟,这就是个减法,用两个图形相减,剩余的部分就是我们要的那条线。

float curve(float x,float y){ 
return smoothstep(.01, 0.0, x-y) - smoothstep(-.01, -0.21, x-y)   ;
}

image.png

来分别看,smoothstep(.01, 0.0, x-y)

image.png

smoothstep(.21, 0.0, x-y)

image.png

再合起来

image.png 最后稍稍修改代码,把偏移量也作为一个参数。

float curve(float x,float y,float d){ 
return smoothstep(.01 +d, -.01+d,  x-y)  ;
}
。。。。。

     color11 = mix(color11,color2,curve(st2.y, noise(st2.x), 0.2) ) ;
     color11 = mix(color11,color3,curve(st2.y, noise(st2.x), 0.1) ) ;
     color11 = mix(color11,color4,curve(st2.y, noise(st2.x), -0.) ) ;
     color11 = mix(color11,color5,curve(st2.y, noise(st2.x), -0.1) ) ;
     color11 = mix(color11,color6,curve(st2.y, noise(st2.x), -0.2) ) ;

image.png