Last active
May 22, 2021 12:29
-
-
Save behreajj/2c6a2f9f7c1cc445eba7d144bd7c48cc to your computer and use it in GitHub Desktop.
Circle Mixed With Noise
This file contains hidden or 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
float quantize(float x, int levels) { | |
return select( | |
floor(0.5 + x * levels) / levels, | |
x, levels < 2); | |
} | |
shader circle1( | |
point Point = P, | |
point Center = 0.0, | |
float Radius = 1.5, | |
float Blur = 0.05, | |
float NoiseWeight = 0.25, | |
float Roughness = 2.5, | |
color Outside = 0.0, | |
color Inside = 1.0, | |
int Quantize = 0, | |
output color Color = 0.8, | |
output float Fac = 0.5) { | |
vector diff = Center - Point; | |
float lenSq = dot(diff, diff); | |
float eval = 0.25 * Radius * Radius - lenSq; | |
point ptNorm = Roughness * normalize(Point); | |
float nVal = noise("usimplex", ptNorm); | |
float mxVal = mix(eval, nVal, NoiseWeight); | |
float halfBlur = 0.5 * clamp(Blur, 0.0, 1.0); | |
Fac = smoothstep(-halfBlur, halfBlur, mxVal); | |
Fac = quantize(Fac, Quantize - 1); | |
Color = lRgbTosRgb(mix( | |
sRgbTolRgb(Outside), | |
sRgbTolRgb(Inside), | |
Fac)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment