POV-Ray : Newsgroups : povray.general : 2D Crackle function Server Time
15 Nov 2024 13:22:16 EST (-0500)
  2D Crackle function (Message 1 to 2 of 2)  
From: Slime
Subject: 2D Crackle function
Date: 22 Aug 2004 21:07:32
Message: <41294354@news.povray.org>
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

From: John VanSickle
Subject: Re: 2D Crackle function
Date: 23 Aug 2004 08:20:40
Message: <4129e118$1@news.povray.org>
Slime wrote:

> 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.

I wrote the C code for this as a built-in POV pattern, and submitted it,
along with my code for the cells pattern, to (IIRC) the MegaPOV folks.
While the cells pattern made it into v3.5, the 2d crackle (for which
I recommended the name "web" did not.  Go figure.

All I did was rewrite the existing 3d crackle code; it wasn't very
difficult.

Regards,
John


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.