POV-Ray : Newsgroups : povray.binaries.images : Crackle again Server Time26 Nov 2022 04:03:37 EST (-0500)
 Crackle again (Message 1 to 10 of 16)
 From: Bill Pragnell Subject: Crackle again Date: 23 Nov 2022 07:40:00 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.637e143ebe1b321fb96893c06f35e431%40news.povray.org",
"dateCreated": "2022-11-23T12:40:00+00:00",
"datePublished": "2022-11-23T12:40:00+00:00",
"author": {
"@type": "Person",
"name": "Bill Pragnell"
}
}
Hi everyone

I was reading through the recent thread on the crackle pattern, and I too was
unaware of the 'solid' modifier. And I too have often craved a 'custom'
crackle-like effect that could permit cell color to be controlled by a function
or pigment.

After some thought, I basically came to the same conclusions as Bald Eagle -
i.e. that it can't be done with user-defined functions, because the position
information is lost in the closest-distance calculation.

However, I think I've found another way. It's not particularly elegant, and it
only works in 2D, but it parses relatively leniently and renders fast. The idea
is to make a set of object pigment functions, one per cell, tracing against
cones to produce non-overlapping meshes. The object pigments can be given an
interior value based on their seed point position, zero outside, and then
combined using max() into one big function that can then itself go into a
pigment.

The attached example uses 250 seed points in a 20x20 square, the cells colored
using a wood pattern. It should be straightforward to layer the simple distance
function version of the same point array to provide mortar (although I haven't
tried this yet).

Bill
```

Attachments:

Preview of image 'cracklebobs.png'

 From: Bill Pragnell Subject: Re: Crackle again Date: 23 Nov 2022 08:35:00 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.637e2164c37f1de0b96893c06f35e431%40news.povray.org",
"dateCreated": "2022-11-23T13:35:00+00:00",
"datePublished": "2022-11-23T13:35:00+00:00",
"author": {
"@type": "Person",
"name": "Bill Pragnell"
}
}
"Bill Pragnell" <bil### [at] hotmailcom> wrote:
> Hi everyone

Code for the curious:

#declare BrightFn = function { pigment {
wood color_map { [0 rgb 0] [1 rgb 1] } rotate x*90 scale 6
} }

#declare N = 250;
#declare Sd = seed(0);
#declare D = 10;
#declare Points = array[N];
#declare Cones = array[N];
#for (I, 0, N-1)
#declare Points[I] = <rand(Sd)*20-10, 0, rand(Sd)*20-10>;
#declare Cones[I] = cone { Points[I]-y*D, 10, Points[I], 0 }
#end

#declare OtherCones = array[N];
#for (I, 0, N-1)
#declare OtherCones[I] = union {
#for (J, 0, N-1)
#if (J != I) object { Cones[J] } #end
#end
plane { y, -D } // to catch misses
}
#end

#declare NS = 250;
#declare DA = 360/NS;
#declare MeshCells = array[N];
#for (I, 0, N-1)
#declare MeshCells[I] = mesh {
#for (IA, 0, NS-1)
#declare V1 = vrotate(<1,-1,0>, y*DA*IA);
#declare V2 = vrotate(<1,-1,0>, y*DA*(IA+1));
#declare P1 = trace(OtherCones[I], Points[I], V1);
#declare P2 = trace(OtherCones[I], Points[I], V2);
triangle { Points[I], P1, P2 }
triangle { P1, <P1.x, -D, P1.z>, <P2.x, -D, P2.z> }
triangle { P1, <P2.x, -D, P2.z>, P2 }
triangle { Points[I]-y*D, <P2.x, -D, P2.z>, <P1.x, -D, P1.z> }
#end
inside_vector y
}
#end

#declare Fns = array[N];
#for (I, 0, N-1)
#declare Fns[I] = function {
pigment {
object {
MeshCells[I]
rgb 0, rgb BrightFn(Points[I].x, -D+1e-4, Points[I].z).x
}
}
}
#end
#declare WholeFn = function {
max(
#for (I, 0, N-1)
Fns[I](x, -D+1e-4, z).x
#if (I < N-1) , #end
#end
)
}

box {
<-10, -0.01, -10>, <10, 0, 10>
pigment { function { WholeFn(x, y, z) } color_map { [0 rgb 0] [1 rgb 1] } }
finish { diffuse 0.8 ambient 0 }
}
```
 From: Bald Eagle Subject: Re: Crackle again Date: 23 Nov 2022 13:20:00 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.637e641ec37f1de01f9dae3025979125%40news.povray.org",
"dateCreated": "2022-11-23T18:20:00+00:00",
"datePublished": "2022-11-23T18:20:00+00:00",
"author": {
"@type": "Person",
"name": "Bald Eagle"
}
}
Oh - an object pigment pattern.  Brilliant.

I am, however, having problems rendering this.   Could you provide a camera and
look-at position, or a complete version of the scene?

- BW
```
 From: Tor Olav Kristensen Subject: Re: Crackle again Date: 23 Nov 2022 14:35:00 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.637e759ec37f1de096ac14b489db30a9%40news.povray.org",
"dateCreated": "2022-11-23T19:35:00+00:00",
"datePublished": "2022-11-23T19:35:00+00:00",
"author": {
"@type": "Person",
"name": "Tor Olav Kristensen"
}
}
"Bald Eagle" <cre### [at] netscapenet> wrote:
> Oh - an object pigment pattern.  Brilliant.
>
> I am, however, having problems rendering this.   Could you provide a camera and
> look-at position, or a complete version of the scene?

Try this:

#version 3.7;

global_settings { assumed_gamma 1.0 }

camera {
location 20*y
look_at 0*y
}

default {
finish {
diffuse 0
emission color rgb <1, 1, 1>
}
}

--
Tor Olav
http://subcube.com
https://github.com/t-o-k
```
 From: Bill Pragnell Subject: Re: Crackle again Date: 23 Nov 2022 14:50:00 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.637e791ac37f1de0b96893c06f35e431%40news.povray.org",
"dateCreated": "2022-11-23T19:50:00+00:00",
"datePublished": "2022-11-23T19:50:00+00:00",
"author": {
"@type": "Person",
"name": "Bill Pragnell"
}
}
"Bald Eagle" <cre### [at] netscapenet> wrote:
> Oh - an object pigment pattern.  Brilliant.
>
> I am, however, having problems rendering this.   Could you provide a camera
> and look-at position, or a complete version of the scene?

Sure, sorry! I don't know why I didn't just post the whole thing :)
This is what I used:

camera {
location <0, 30, 0>
up y
right x*4/3
angle 50
look_at <0, 0, 0>
}

light_source { <500, 400, -300> rgb 1 }
background { rgb <0.8, 0.9, 1> }
```
 From: Bald Eagle Subject: Re: Crackle again Date: 23 Nov 2022 19:10:00 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.637eb561c37f1de01f9dae3025979125%40news.povray.org",
"dateCreated": "2022-11-24T00:10:00+00:00",
"datePublished": "2022-11-24T00:10:00+00:00",
"author": {
"@type": "Person",
"name": "Bald Eagle"
}
}
Very cool!

I upped the count to 500 and used the bozo pattern, scale 1 and a 10-value color
map.

This is definitely what we've been after - very nicely done.  :)

I've only just gotten back in, and haven't worked it out in enough detail to
understand exactly how all the parts work.   I tried it with the "POVRAY" point
set, got it to work, dabbled a bit more, and broke it again...

I'm wondering if there are other ways to control the colors of the cells - by
height?  by area?

Very interested in your mortar idea.

Also wondering if the Delaunay triangulation can be done as well.  Rendering the
dual would be a cool effect.

Great work, Bill - this was a very clever solution.
```

Attachments:

Preview of image 'billpragnellvoronoiconemesh.png'

 From: Bill Pragnell Subject: Re: Crackle again Date: 24 Nov 2022 05:50:00 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.637f4aa5c37f1de022cd71f26f35e431%40news.povray.org",
"dateCreated": "2022-11-24T10:50:00+00:00",
"datePublished": "2022-11-24T10:50:00+00:00",
"author": {
"@type": "Person",
"name": "Bill Pragnell"
}
}
"Bald Eagle" <cre### [at] netscapenet> wrote:
> I've only just gotten back in, and haven't worked it out in enough detail to
> understand exactly how all the parts work.   I tried it with the "POVRAY"
> point set, got it to work, dabbled a bit more, and broke it again...

Everything used to generate the cells gets stored in arrays - try rendering
individual meshes to get a feel for the objects that go into the pigments.

that a field of cones could be used to generate a 2D voronoi field. My code uses
a 'depth' of 10, with 45-degree cones - the slice used by the function is just
above this y=-10 floor so tweaking might cause it to miss the objects.

The other thing I'm unsure about is how many arguments the max() function can
accept - this is probably the practical upper limit on the cell count.

> I'm wondering if there are other ways to control the colors of the cells - by
> height?  by area?

In that snippet, the BrightFn is what I use to generate the cell value 0-1; a
pigment was the obvious choice, but you might be able to do something with the
stored meshes to generate a suitable function for area... basically anything
that could feasibly be encoded in a function.

> Very interested in your mortar idea.

I was referring to the custom 'standard' crackle that you demonstrated in your
post, using the min distance from a seed point to generate the color value. The
documentation even mentions using a solid crackle with a regular crackle layered
over it to generate mortar for the solid cells.

> Also wondering if the Delaunay triangulation can be done as well.  Rendering
> the dual would be a cool effect.

No idea - this is a bit of a hack! I imagine triangulation could be done with an
SDL macro, and then the triangles could be colored however you want... but I
have no experience implementing Delaunay triangulation so I'm not sure.

> Great work, Bill - this was a very clever solution.

It was fun to think through! Now if only we could have iteration in user-defined
functions... :)

Bill
```
 From: Bald Eagle Subject: Re: Crackle again Date: 24 Nov 2022 09:15:00 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.637f7befc37f1de01f9dae3025979125%40news.povray.org",
"dateCreated": "2022-11-24T14:15:00+00:00",
"datePublished": "2022-11-24T14:15:00+00:00",
"author": {
"@type": "Person",
"name": "Bald Eagle"
}
}
"Bill Pragnell" <bil### [at] hotmailcom> wrote:

> The other thing I'm unsure about is how many arguments the max() function can
> accept - this is probably the practical upper limit on the cell count.

Nope.  I the one I posted was 500, and I successfully ran one with 1500, which
was SLOW.

But also, even if there is an upper limit, just make an aggregating function
that takes the max () of other, max() functions with fewer arguments than the
limit.

> I was referring to the custom 'standard' crackle that you demonstrated in your
> post, using the min distance from a seed point to generate the color value.

"My post" ... I make a lot of them, and I don't think I've posted any with
POV-Ray's native crackle pattern.

> The
> documentation even mentions using a solid crackle with a regular crackle layered
> over it to generate mortar for the solid cells.

Interesting.   I'll have to look at that - way back in 2013, I used this method
for making mortar for my Secret Passage scene.

#declare Pigment_1 =
pigment{ crackle solid turbulence 0.35 scale 0.45
color_map{
[0.00 color rgb<1, 1, 1>*0]
[0.08 color rgb<1, 1, 1>*0]
[0.40 color rgb<1, 0.55, 0>]
[1.00 color rgb<1, 1, 0.8>]
} // end of color_map
} // end of pigment -----------------

#declare Roughness = 2;

//  Flagstone Texture
#declare Texture_1 =
texture {crackle form <-1, 1, 0> metric 2 offset 0.1 cubic_wave turbulence 0
scale 12
texture_map {
[0.00 pigment {Clear}]
[0.01 pigment {Clear}]
[0.01 crackle solid form <-1, 1, 0> metric 2 offset 0
texture_map {
[0.00 T_Stone5  normal {granite scale Roughness}]
[0.20 T_Stone5  normal {granite scale Roughness}]

[0.20 T_Stone14 normal {agate scale Roughness}]
[0.40 T_Stone14 normal {agate scale Roughness}]

[0.40 T_Stone20 normal {bumps scale Roughness}]
[0.60 T_Stone20 normal {bumps scale Roughness}]

[0.60 T_Stone33 normal {ripples scale Roughness}]
[0.80 T_Stone33 normal {ripples scale Roughness}]

[0.80 T_Stone43 normal {waves scale Roughness}]
[1.00 T_Stone43 normal {waves scale Roughness}]
}]  //  end of inner texture map
} // end of outer texture_map

} // end of texture

> > Also wondering if the Delaunay triangulation can be done as well.  Rendering
> > the dual would be a cool effect.
>
> No idea - this is a bit of a hack! I imagine triangulation could be done with an
> SDL macro, and then the triangles could be colored however you want... but I
> have no experience implementing Delaunay triangulation so I'm not sure.

Yeah - me neither, but I thought maybe you'd have another stroke of genius   :)

Also wondering if, with your existing knowledge of how your code works, if there
was a way to "draw lines" with cylinders around the borders of the cells.
Something to do with the mesh vertices perhaps....
```
 From: Bill Pragnell Subject: Re: Crackle again Date: 24 Nov 2022 09:50:00 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.637f839fc37f1de022cd71f26f35e431%40news.povray.org",
"dateCreated": "2022-11-24T14:50:00+00:00",
"datePublished": "2022-11-24T14:50:00+00:00",
"author": {
"@type": "Person",
"name": "Bill Pragnell"
}
}
"Bald Eagle" <cre### [at] netscapenet> wrote:
> > I was referring to the custom 'standard' crackle that you demonstrated in
> > your post, using the min distance from a seed point to generate the color
> > value.
>
> "My post" ... I make a lot of them, and I don't think I've posted any with
> POV-Ray's native crackle pattern.

Sorry; the previous crackle thread from a couple of days ago, with the custom
version you showed that just colors a point based on distance to the closest
seed point.

This one:
http://news.povray.org/povray.binaries.images/message/%3Cweb.6376dd8c302862a41f9dae3025979125%40news.povray.org%3E

> > The documentation even mentions using a solid crackle with a regular crackle
> > layered over it to generate mortar for the solid cells.
>
> Interesting.   I'll have to look at that - way back in 2013, I used this
> method for making mortar for my Secret Passage scene.

See 3.4.7.2.3 in the online reference help ('Crackle Pattern'). It's only a
brief mention. From your example though, it looks like you're comfortable with

> Also wondering if, with your existing knowledge of how your code works, if
> there was a way to "draw lines" with cylinders around the borders of the
> cells. Something to do with the mesh vertices perhaps....

Hmm that's a thought. It would consist of a large quantity of spheres and/or
cylinders placed around each mesh base, all as a single object pattern. It would
be much slower than using another function texture layer, but it would give an
constant thickness of mortar, which the texture method might not... I'll have to
try this out when I get the chance!

Bill
```
 From: Bald Eagle Subject: Re: Crackle again Date: 24 Nov 2022 11:00:00 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.637f94a9c37f1de01f9dae3025979125%40news.povray.org",
"dateCreated": "2022-11-24T16:00:00+00:00",
"datePublished": "2022-11-24T16:00:00+00:00",
"author": {
"@type": "Person",
"name": "Bald Eagle"
}
}
"Bill Pragnell" <bil### [at] hotmailcom> wrote:

> Sorry; the previous crackle thread from a couple of days ago, with the custom
> version you showed that just colors a point based on distance to the closest
> seed point.

http://news.povray.org/povray.binaries.images/message/%3Cweb.6376dd8c302862a41f9dae3025979125%40news.povray.org%3E

Ah.  "Colors" meaning simple scalar grayscale shading.

>
> > > The documentation even mentions using a solid crackle with a regular crackle
> > > layered over it to generate mortar for the solid cells.

I think what they mean is the reverse?
"There is no provision for mortar, but mortar may be created by layering or
texture-mapping a standard crackle texture with a solid one."

It's been a while since I've messed with that, and their language there is a
little - vague.

> > Also wondering if, with your existing knowledge of how your code works, if
> > there was a way to "draw lines" with cylinders around the borders of the
> > cells. Something to do with the mesh vertices perhaps....
>
> Hmm that's a thought. It would consist of a large quantity of spheres and/or
> cylinders placed around each mesh base, all as a single object pattern.

I was actually thinking not as an object pattern, but as the native lattice of
cylinders.  Make a scene with small spheres as the center points, and make the
Voronoi with cylinder{} objects.

AND, if that's possible - then why not do the Voronoi with prism {} objects.
Then they can all be collected into an array and textured however one wants -
even manually, one at a time.

But there is obviously much to played with here.   How does it look if instead
of using cones, we use spheres, ellipsoids, superellipsoids, pyramids, etc?

http://www.f-lohmueller.de/pov_tut/all_shapes/shapes3_0000e.htm
http://www.f-lohmueller.de/pov_tut/all_shapes/shapes350e.htm

While researching this, I have also seen people use other distance metrics, such
as the "Manhattan distance" or "taxicab distance", etc.
```