-
Notifications
You must be signed in to change notification settings - Fork 633
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(point-layer): use 2d sdf functions
- Loading branch information
Showing
10 changed files
with
167 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* 2D signed distance field functions | ||
* @see http://www.iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm | ||
*/ | ||
|
||
float ndot(vec2 a, vec2 b ) { return a.x*b.x - a.y*b.y; } | ||
|
||
float sdCircle(vec2 p, float r) { | ||
return length(p) - r; | ||
} | ||
|
||
float sdEquilateralTriangle(vec2 p) { | ||
const float k = sqrt(3.0); | ||
p.x = abs(p.x) - 1.0; | ||
p.y = p.y + 1.0/k; | ||
if( p.x + k*p.y > 0.0 ) p = vec2(p.x-k*p.y,-k*p.x-p.y)/2.0; | ||
p.x -= clamp( p.x, -2.0, 0.0 ); | ||
return -length(p)*sign(p.y); | ||
} | ||
|
||
float sdBox(vec2 p, vec2 b) { | ||
vec2 d = abs(p)-b; | ||
return length(max(d,vec2(0))) + min(max(d.x,d.y),0.0); | ||
} | ||
|
||
float sdPentagon(vec2 p, float r) { | ||
const vec3 k = vec3(0.809016994,0.587785252,0.726542528); | ||
p.x = abs(p.x); | ||
p -= 2.0*min(dot(vec2(-k.x,k.y),p),0.0)*vec2(-k.x,k.y); | ||
p -= 2.0*min(dot(vec2( k.x,k.y),p),0.0)*vec2( k.x,k.y); | ||
p -= vec2(clamp(p.x,-r*k.z,r*k.z),r); | ||
return length(p)*sign(p.y); | ||
} | ||
|
||
float sdHexagon(vec2 p, float r) { | ||
const vec3 k = vec3(-0.866025404,0.5,0.577350269); | ||
p = abs(p); | ||
p -= 2.0*min(dot(k.xy,p),0.0)*k.xy; | ||
p -= vec2(clamp(p.x, -k.z*r, k.z*r), r); | ||
return length(p)*sign(p.y); | ||
} | ||
|
||
float sdOctogon(vec2 p, float r) { | ||
const vec3 k = vec3(-0.9238795325, 0.3826834323, 0.4142135623 ); | ||
p = abs(p); | ||
p -= 2.0*min(dot(vec2( k.x,k.y),p),0.0)*vec2( k.x,k.y); | ||
p -= 2.0*min(dot(vec2(-k.x,k.y),p),0.0)*vec2(-k.x,k.y); | ||
p -= vec2(clamp(p.x, -k.z*r, k.z*r), r); | ||
return length(p)*sign(p.y); | ||
} | ||
|
||
float sdHexagram(vec2 p, float r) { | ||
const vec4 k=vec4(-0.5,0.8660254038,0.5773502692,1.7320508076); | ||
p = abs(p); | ||
p -= 2.0*min(dot(k.xy,p),0.0)*k.xy; | ||
p -= 2.0*min(dot(k.yx,p),0.0)*k.yx; | ||
p -= vec2(clamp(p.x,r*k.z,r*k.w),r); | ||
return length(p)*sign(p.y); | ||
} | ||
|
||
float sdRhombus(vec2 p, vec2 b) { | ||
vec2 q = abs(p); | ||
float h = clamp((-2.0*ndot(q,b)+ndot(b,b))/dot(b,b),-1.0,1.0); | ||
float d = length( q - 0.5*b*vec2(1.0-h,1.0+h) ); | ||
return d * sign( q.x*b.y + q.y*b.x - b.x*b.y ); | ||
} | ||
|
||
float sdVesica(vec2 p, float r, float d) { | ||
p = abs(p); | ||
float b = sqrt(r*r-d*d); // can delay this sqrt | ||
return ((p.y-b)*d>p.x*b) | ||
? length(p-vec2(0.0,b)) | ||
: length(p-vec2(-d,0.0))-r; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/** | ||
* 针对绘制圆形的优化 | ||
* 绘制 SDF,不仅是圆形 | ||
* 手动构建点阵坐标系,便于实现描边、反走样效果 | ||
*/ | ||
import * as THREE from '../../../core/three'; | ||
|