Created
May 10, 2020 18:03
-
-
Save drewgillievfx/dd20867d2a93b578a4529b7cdf11c84a to your computer and use it in GitHub Desktop.
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
float dist2cell(point p, string spacename, float freq, float jitter) { | |
point pp = transform(spacename, p) * freq; | |
point thiscell = point(floor(pp[0]) + 0.5, | |
floor(pp[1]) + 0.5, | |
floor(pp[2]) + 0.5); | |
float dist2nearest = 1000; | |
int i,j,k; | |
for(i = -1; i <= 1; i += 1) | |
for(j = -1; j <= 1; j += 1) | |
for(k = -1; k <= 1; k += 1) { | |
point testcell = thiscell + vector(i,j,k); | |
point pos = testcell + (noise("snoise", testcell) * jitter) - 0.5; | |
float dist = distance(pos, pp); | |
if(dist < dist2nearest) | |
dist2nearest = dist; | |
} | |
return dist2nearest; | |
} | |
//------------------------------------------------------- | |
shader | |
eyes(float cellfreq = 5, | |
float radius = 0.15, | |
float blur = 0.1, | |
float jitter = 1, | |
color patcolor = color(1,0,1), | |
color bakcolor = color(1,1,1), | |
string spacename = "shader", | |
output color resultRGB = 0, | |
output float resultMask = 0, | |
output float resultF = 0) | |
{ | |
float d = dist2cell(P, spacename, cellfreq, jitter); | |
resultF = 1 - smoothstep(radius, radius + blur, d); | |
resultRGB = mix(bakcolor, patcolor, resultF); | |
resultMask = (d <= radius) ? 1 : 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment