p爲到圓柱體中心的位置向量,h.x爲圓柱體的半徑,h.y爲圓柱體的半高。設定圓柱體中心在座標原點,沿y軸放置。
float Cylinder( vec3 p, vec2 h )
{
vec2 d = abs(vec2(length(p.xz),p.y)) - h;
return min(max(d.x,d.y),0.0) + length(max(d,0.0));
}
p爲到圓柱體中心的位置向量,h.x爲圓柱體的半徑,h.y爲圓柱體的半高。設定圓柱體中心在座標原點,沿y軸放置。
float Cylinder( vec3 p, vec2 h )
{
vec2 d = abs(vec2(length(p.xz),p.y)) - h;
return min(max(d.x,d.y),0.0) + length(max(d,0.0));
}
https://www.shadertoy.com/view/MssyRN https://www.shadertoy.com/view/4tl3RM
1、二維情況 a(x,y)的垂直向量爲b(y,-x) 2、三維情況 已知a(x,y,z),b(x,y,z),求c(x,y,z)與a垂直並且與b共面 d=corss(a,b) c=cross(a,d)
4.0以後纔有的函數。只能用於片段着色全。計算lod vec2 textureQueryLod( gsampler1D sampler, float P); vec2 textureQueryLod(