Last active
November 7, 2015 11:24
-
-
Save kioba/3d2f27ac238af37f5164 to your computer and use it in GitHub Desktop.
Quadratic Curve Pixel Shader
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
float4 QuadraticPS(float2 p : TEXCOORD0, | |
float4 color : COLOR0) : COLOR | |
{ | |
// Gradients | |
float2 px = ddx(p); | |
float2 py = ddy(p); | |
// Chain rule | |
float fx = (2*p.x)*px.x - px.y; | |
float fy = (2*p.x)*py.x - py.y; | |
// Signed distance | |
float sd = (p.x*p.x - p.y)/sqrt(fx*fx + fy*fy); | |
// Linear alpha | |
float alpha = 0.5 - sd; | |
if (alpha > 1) // Inside | |
color.a = 1; | |
else if (alpha < 0) // Outside | |
clip(-1); | |
else | |
// Near boundary | |
color.a = alpha; | |
return color; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Charles Loop & Jim Blinn Quadratic Curve Pixel Shader:
http://http.developer.nvidia.com/GPUGems3/gpugems3_ch25.html