|
|
I was applying crackle to a ground plane and got tired of the way it has
occasional large flat areas due mostly to the fact that it's based on points
in 3D space. So I made my own 2D "crackle" function to use instead.
It's slow, so that's a significant tradeoff. But it mostly fixes the problem
of large flat dark areas.
In case anyone's interested, I'm posting it here:
// 2D Crackle function by Slime ( http://www.slimeland.com/ )
#declare Crackle2DClamp = function(x) {
x - floor(x)
}
#declare Crackle2DPointDist = function(x, y, cellx,celly) {
sqrt(pow(x-(cellx + Crackle2DClamp(f_noise3d(cellx,celly,0 )*10000)),2)
+pow(y-(celly + Crackle2DClamp(f_noise3d(cellx,celly,10)*10000)),2))
}
#macro testAllPoints(skipnum)
#local counter = 0;
#local _x = -2;
#while (_x <= 2)
#local _y = -2;
#while (_y <= 2)
#if (abs(_x) != 2 | (_x != _y & _x != -_y))
#if (counter != skipnum)
Crackle2DPointDist(x,y, fx+_x,fy+_y)
#if (counter < 20)
#if (counter < 19 | skipnum != 20)
,
#end
#end
#end
#local counter = counter + 1;
#end
#local _y = _y + 1;
#end
#local _x = _x + 1;
#end
#end
#declare Crackle2DSecondNearPoint = function(x,y, fx,fy, nearestdist) {
#local counter = 0;
#local _x = -2;
#while (_x <= 2)
#local _y = -2;
#while (_y <= 2)
#if (abs(_x) != 2 | (_x != _y & _x != -_y))
select (
abs(nearestdist - Crackle2DPointDist(x,y, fx+_x, fy+_y)) - 0.000001,
min(testAllPoints(counter)),
#local counter = counter + 1;
#end
#local _y = _y + 1;
#end
#local _x = _x + 1;
#end
0
#local testnum = 0;
#while (testnum < 21)
)
#local testnum = testnum + 1;
#end
}
#declare Crackle2DNearPoint = function(x,y, fx,fy) {
min(testAllPoints(-1))
}
#declare Crackle2DHelper = function(x,y, nearestdist) {
(Crackle2DSecondNearPoint(x,y, floor(x),floor(y), nearestdist) -
nearestdist) / sqrt(2)
}
#declare Crackle2D = function {
Crackle2DHelper(x,z, Crackle2DNearPoint(x,z, floor(x),floor(z)))
}
Use like:
pigment {
function {Crackle2D(x,y,z)}
...
}
Enjoy.
- Slime
[ http://www.slimeland.com/ ]
Post a reply to this message
|
|