POV-Ray : Newsgroups : povray.advanced-users : Pattern showing *change* in slope Server Time
10 Oct 2026 04:02:15 EDT (-0400)
  Pattern showing *change* in slope (Message 1 to 26 of 26)  
From: SharkD
Subject: Pattern showing *change* in slope
Date: 28 Aug 2009 06:52:54
Message: <4a97b706$1@news.povray.org>
How can I create a pattern that shows the *change* in slope of a 
heightfield. I.e., brighter where the "curvature" is greater.

Thanks!

-Mike


Post a reply to this message

From: clipka
Subject: Re: Pattern showing *change* in slope
Date: 28 Aug 2009 07:25:22
Message: <4a97bea2$1@news.povray.org>
SharkD schrieb:
> How can I create a pattern that shows the *change* in slope of a 
> heightfield. I.e., brighter where the "curvature" is greater.

You can create this from the image you use for the height field

To begin with, make a pigment from the image; make from that a function F.

Now, create a function G computing the curvature from five function 
values from F, spaced apart by (at least) 1/BITMAP_SIZE, to compute the 
"difference in difference" both vertically and horizontally:

#declare D = 1/BITMAP_SIZE; // insert actual size of your bitmap here
#declare Sqr = function(x) { x*x }
#declare G = function(x,y,z) {
   sqrt(
     Sqr( F(x-D,y,z) + F(x+D,y,z) - 2*F(x,y,z) ) // squared curvature X
     Sqr( F(x,y-D,z) + F(x,y-D,z) - 2*F(x,y,z) ) // squared curvature Y
   )
}

finally, apply this function as a pattern to your height field.


Post a reply to this message

From: Jaime Vives Piqueres
Subject: Re: Pattern showing *change* in slope
Date: 28 Aug 2009 07:40:32
Message: <4a97c230@news.povray.org>
SharkD escribió:
> How can I create a pattern that shows the *change* in slope of a 
> heightfield. I.e., brighter where the "curvature" is greater.
> 

I used that for my hf2iso experiment:

//---------------------------------------------------
global_settings{hf_gray_16}

#include "functions.inc"

// file to extract slope from
#declare hf_file="your_hf_here"

// sloped texture with autoilluminated finish
#declare t_terrain_slope=
texture{
  pigment{
   slope y
   color_map{
    [0.00 rgb 0]
    [0.50 rgb 1]
    [0.67 rgb 1]
    [0.75 rgb 0]
    [1.00 rgb 0]
   }
  }
  finish{brilliance 0 ambient 1}
}

// create a heightfield from the bitmat
#declare terrain=
height_field{
  tga hf_file
  translate -.5
  scale <2,1,2>
  texture{t_terrain_slope}
}
object{terrain}

// take a square shot
camera{
  orthographic
  location <0,0,-1>
  up 1*y right 1*x
  angle 90
  look_at 0
  rotate 90*x
}
//---------------------------------------------------


--
Jaime


Post a reply to this message

From: Warp
Subject: Re: Pattern showing *change* in slope
Date: 28 Aug 2009 07:45:22
Message: <4a97c352@news.povray.org>
Jaime Vives Piqueres <jai### [at] ignoranciaorg> wrote:
> // sloped texture with autoilluminated finish
> #declare t_terrain_slope=
> texture{
>   pigment{
>    slope y

  That shows the slope of the heightfield, not the *change* in slope,
which is a bit more involved (it would require the derivative of the
function which indicates the slope of the heightfield; since the slope
function is the derivative of the heightfield function, the change in
slope would thus be the double derivative of the heightfield function).

  Maybe the original poster really wanted to actually see the slope,
rather than the change in slope, in which case your answer would be
the correct one.

-- 
                                                          - Warp


Post a reply to this message

From: SharkD
Subject: Re: Pattern showing *change* in slope
Date: 28 Aug 2009 09:38:51
Message: <4a97ddeb@news.povray.org>
Warp wrote:
>   That shows the slope of the heightfield, not the *change* in slope,
> which is a bit more involved (it would require the derivative of the
> function which indicates the slope of the heightfield; since the slope
> function is the derivative of the heightfield function, the change in
> slope would thus be the double derivative of the heightfield function).
> 
>   Maybe the original poster really wanted to actually see the slope,
> rather than the change in slope, in which case your answer would be
> the correct one.
> 

Nope. I want the double derivative.

-Mike


Post a reply to this message

From: SharkD
Subject: Re: Pattern showing *change* in slope
Date: 28 Aug 2009 09:39:53
Message: <4a97de29$1@news.povray.org>
clipka wrote:
> You can create this from the image you use for the height field
> 
> To begin with, make a pigment from the image; make from that a function F.
> 
> Now, create a function G computing the curvature from five function 
> values from F, spaced apart by (at least) 1/BITMAP_SIZE, to compute the 
> "difference in difference" both vertically and horizontally:
> 
> #declare D = 1/BITMAP_SIZE; // insert actual size of your bitmap here
> #declare Sqr = function(x) { x*x }
> #declare G = function(x,y,z) {
>   sqrt(
>     Sqr( F(x-D,y,z) + F(x+D,y,z) - 2*F(x,y,z) ) // squared curvature X
>     Sqr( F(x,y-D,z) + F(x,y-D,z) - 2*F(x,y,z) ) // squared curvature Y
>   )
> }
> 
> finally, apply this function as a pattern to your height field.

I'll give it a shot, thanks.

-Mike


Post a reply to this message

From: SharkD
Subject: Re: Pattern showing *change* in slope
Date: 28 Aug 2009 10:33:34
Message: <4a97eabe$1@news.povray.org>
Warp wrote:
> Jaime Vives Piqueres <jai### [at] ignoranciaorg> wrote:
>> // sloped texture with autoilluminated finish
>> #declare t_terrain_slope=
>> texture{
>>   pigment{
>>    slope y
> 
>   That shows the slope of the heightfield, not the *change* in slope,
> which is a bit more involved (it would require the derivative of the
> function which indicates the slope of the heightfield; since the slope
> function is the derivative of the heightfield function, the change in
> slope would thus be the double derivative of the heightfield function).
> 
>   Maybe the original poster really wanted to actually see the slope,
> rather than the change in slope, in which case your answer would be
> the correct one.
> 

Is there a function in POV that will allow me to automatically take the 
derivative of another function?

-Mike


Post a reply to this message

From: Warp
Subject: Re: Pattern showing *change* in slope
Date: 28 Aug 2009 11:12:05
Message: <4a97f3c5@news.povray.org>
SharkD <mik### [at] gmailcom> wrote:
> Nope. I want the double derivative.

  Then your only option is to generate the heightfield using a function
and then use the double derivative of that function with respect to x and
another with respect to y and combine them appropriately to create the
desired pattern, which you then can use to create the pigment.

-- 
                                                          - Warp


Post a reply to this message

From: Warp
Subject: Re: Pattern showing *change* in slope
Date: 28 Aug 2009 11:13:36
Message: <4a97f41f@news.povray.org>
SharkD <mik### [at] gmailcom> wrote:
> Is there a function in POV that will allow me to automatically take the 
> derivative of another function?

  Calculating the derivative of a function analytically is not trivial
and has such low demand that povray obviously doesn't offer such a thing.

  A numerical approximation could be easier, but still the demand is so
low that no such luck.

  But I think the user-defined functions are expressive enough for you to
do it in SDL.

-- 
                                                          - Warp


Post a reply to this message

From: SharkD
Subject: Re: Pattern showing *change* in slope
Date: 28 Aug 2009 11:52:04
Message: <4a97fd24$1@news.povray.org>
Warp wrote:
> SharkD <mik### [at] gmailcom> wrote:
>> Is there a function in POV that will allow me to automatically take the 
>> derivative of another function?
> 
>   Calculating the derivative of a function analytically is not trivial
> and has such low demand that povray obviously doesn't offer such a thing.
> 
>   A numerical approximation could be easier, but still the demand is so
> low that no such luck.
> 
>   But I think the user-defined functions are expressive enough for you to
> do it in SDL.
>


Post a reply to this message

From: SharkD
Subject: Re: Pattern showing *change* in slope
Date: 28 Aug 2009 11:52:30
Message: <4a97fd3e@news.povray.org>
Warp wrote:
>   But I think the user-defined functions are expressive enough for you to
> do it in SDL.
> 

OK, so how would I go about doing it?

-Mike


Post a reply to this message

From: SharkD
Subject: Re: Pattern showing *change* in slope
Date: 28 Aug 2009 12:05:34
Message: <4a98004e$1@news.povray.org>
clipka wrote:
> SharkD schrieb:
>> How can I create a pattern that shows the *change* in slope of a 
>> heightfield. I.e., brighter where the "curvature" is greater.
> 
> You can create this from the image you use for the height field
> 
> To begin with, make a pigment from the image; make from that a function F.
> 
> Now, create a function G computing the curvature from five function 
> values from F, spaced apart by (at least) 1/BITMAP_SIZE, to compute the 
> "difference in difference" both vertically and horizontally:

OK, here's what I have:

//START
#local hf_function1 = function {pigment {hf_pigment3}}
#local dv_D = 1/1024;
#local dv_Sqr = function(x) {x * x}
#local dv_G = function(x,y,z)
{
	sqrt
	(
		dv_Sqr(hf_function1(x - dv_D,y,z) + hf_function1(x + dv_D,y,z) - 2 * 
hf_function1(x,y,z))
		dv_Sqr(hf_function1(x,y - dv_D,z) + hf_function1(x,y - dv_D,z) - 2 * 
hf_function1(x,y,z))
	)
}
//END

However, I get the error: "Parse Error: Expected '.', + found instead"

-Mike


Post a reply to this message

From: Warp
Subject: Re: Pattern showing *change* in slope
Date: 28 Aug 2009 12:09:26
Message: <4a980135@news.povray.org>
SharkD <mik### [at] gmailcom> wrote:
> Warp wrote:
> >   But I think the user-defined functions are expressive enough for you to
> > do it in SDL.
> > 

> OK, so how would I go about doing it?

http://en.wikipedia.org/wiki/Derivative

-- 
                                                          - Warp


Post a reply to this message

From: SharkD
Subject: Re: Pattern showing *change* in slope
Date: 28 Aug 2009 12:10:02
Message: <4a98015a$1@news.povray.org>
clipka wrote:
>   sqrt(
>     Sqr( F(x-D,y,z) + F(x+D,y,z) - 2*F(x,y,z) ) // squared curvature X
>     Sqr( F(x,y-D,z) + F(x,y-D,z) - 2*F(x,y,z) ) // squared curvature Y
>   )

Also, there's supposed to be an operator between the first and second 
instances of the function "Sqr". Which operator is it?

-Mike


Post a reply to this message

From: SharkD
Subject: Re: Pattern showing *change* in slope
Date: 28 Aug 2009 12:16:08
Message: <4a9802c8@news.povray.org>
Warp wrote:
>> OK, so how would I go about doing it?
> 
> http://en.wikipedia.org/wiki/Derivative
> 

Please point me to the part where it describes POV SDL.

Thanks.

-Mike


Post a reply to this message

From: clipka
Subject: Re: Pattern showing *change* in slope
Date: 28 Aug 2009 12:31:00
Message: <4a980644$1@news.povray.org>
SharkD schrieb:
> clipka wrote:
>>   sqrt(
>>     Sqr( F(x-D,y,z) + F(x+D,y,z) - 2*F(x,y,z) ) // squared curvature X
>>     Sqr( F(x,y-D,z) + F(x,y-D,z) - 2*F(x,y,z) ) // squared curvature Y
>>   )
> 
> Also, there's supposed to be an operator between the first and second 
> instances of the function "Sqr". Which operator is it?

Oops, sorry - should be "+".

The idea behind it is that each terms inside the Sqr() computes the 
curvature in a particular dimension; if you interpret that as a vector, 
the sqrt(Sqr()+Sqr()) computes the "absolute" of the curvature.


Post a reply to this message

From: clipka
Subject: Re: Pattern showing *change* in slope
Date: 28 Aug 2009 12:35:40
Message: <4a98075c$1@news.povray.org>
SharkD schrieb:
> OK, here's what I have:
> ...
>         dv_Sqr(hf_function1(x - dv_D,y,z) + hf_function1(x + dv_D,y,z) - 
> 2 * hf_function1(x,y,z))
> ...
> However, I get the error: "Parse Error: Expected '.', + found instead"

Sorry, I forgot that with that hf_function1 being a pigment function, 
you'll need to evaluate a particular color component, so instead of

     hf_function1(...)

you need to write:

     hf_function1(...).grey

(or .red, .green or .blue, but if I'm not mistaken the height_field 
object uses the combined grey value as well, so the same should be used 
as the basis for the curvature computations.)


Post a reply to this message

From: SharkD
Subject: Re: Pattern showing *change* in slope
Date: 28 Aug 2009 12:43:37
Message: <4a980939$1@news.povray.org>
clipka wrote:
> Sorry, I forgot that with that hf_function1 being a pigment function, 
> you'll need to evaluate a particular color component, so instead of
> 
>     hf_function1(...)
> 
> you need to write:
> 
>     hf_function1(...).grey
> 
> (or .red, .green or .blue, but if I'm not mistaken the height_field 
> object uses the combined grey value as well, so the same should be used 
> as the basis for the curvature computations.)

Thanks! However, all I see is black. Here are the relevant portions of 
my scene.

-Mike

//START
#local hf_pigment1 = pigment
{
	image_map {png "hf_big.png"}
	rotate x * 180		// flipped
}
#local hf_function1 = function {pigment {hf_pigment1}}

#local dv_D =		1/1024;
#local dv_Sqr =		function(x) {x * x}
#local dv_G =		function(x,y,z)
{
	sqrt
	(
		dv_Sqr(hf_function1(x - dv_D,y,z).gray + hf_function1(x + 
dv_D,y,z).gray - 2 * hf_function1(x,y,z).gray)
		+
		dv_Sqr(hf_function1(x,y - dv_D,z).gray + hf_function1(x,y - 
dv_D,z).gray - 2 * hf_function1(x,y,z).gray)
	)
}

height_field
{
	function 1024, 1024 {hf_function1(x,y,z).gray}
	smooth
	texture
	{
		pigment
		{
			function {dv_G(x,y,z)}
			color_map
			{
				[0 rgb 0]
				[1 rgb 1]
			}
		}
		finish {ambient 1}
	}
	translate <-1/2,0,-1/2,>
}
//END


Post a reply to this message

From: clipka
Subject: Re: Pattern showing *change* in slope
Date: 28 Aug 2009 13:01:54
Message: <4a980d82$1@news.povray.org>
SharkD schrieb:
> Thanks! However, all I see is black. Here are the relevant portions of 
> my scene.

Ah, yes... looks like I forgot that you need to multiply the sqrt() term 
with the image's size again (and then scale to taste).


Post a reply to this message

From: Reactor
Subject: Re: Pattern showing *change* in slope
Date: 28 Aug 2009 18:25:00
Message: <web.4a9858dd38d8f2bb457ff4630@news.povray.org>
SharkD <mik### [at] gmailcom> wrote:

> Thanks! However, all I see is black. Here are the relevant portions of
> my scene.
>
> -Mike
>
> //START
> #local hf_pigment1 = pigment
> {
>  image_map {png "hf_big.png"}
>  rotate x * 180  // flipped
> }
> #local hf_function1 = function {pigment {hf_pigment1}}
>
> #local dv_D =  1/1024;
> #local dv_Sqr =  function(x) {x * x}
> #local dv_G =  function(x,y,z)
> {
>  sqrt
>  (
>   dv_Sqr(hf_function1(x - dv_D,y,z).gray + hf_function1(x +
> dv_D,y,z).gray - 2 * hf_function1(x,y,z).gray)
>   +
>   dv_Sqr(hf_function1(x,y - dv_D,z).gray + hf_function1(x,y -
> dv_D,z).gray - 2 * hf_function1(x,y,z).gray)
>  )
> }


The dy component is being subtracted twice, when it should be subtracted for one
value, then added.


#local dv_G = function(x,y,z)
{
    1/dv_D *
    sqrt
    (
        dv_Sqr(   hf_function1(x - dv_D,y,z).gray
                + hf_function1(x + dv_D,y,z).gray
                - 2 * hf_function1(x,y,z).gray )

       +dv_Sqr(   hf_function1(x,y - dv_D,z).gray
                + hf_function1(x,y + dv_D,z).gray
                - 2 * hf_function1(x,y,z).gray )
    )
}

Also, isn't that the first derivative (i.e. slope), not the second?  The
function is roughly analogous to what you would want to do with, say, the
surface normal of the object (i.e. measure the normal's rate of change), or the
values that are returned from the slope pattern.

If you use this directly as a pigment, you should clip it between 0 and 1.
Personally, I would also probably rotate the image and evaluate in the xz plane
because it is easier for me to think of, but either way will work.


-Reactor


Post a reply to this message

From: SharkD
Subject: Re: Pattern showing *change* in slope
Date: 28 Aug 2009 23:54:11
Message: <4a98a663@news.povray.org>
Reactor wrote:
> Also, isn't that the first derivative (i.e. slope), not the second?  The
> function is roughly analogous to what you would want to do with, say, the
> surface normal of the object (i.e. measure the normal's rate of change), or the
> values that are returned from the slope pattern.
> 
> If you use this directly as a pigment, you should clip it between 0 and 1.
> Personally, I would also probably rotate the image and evaluate in the xz plane
> because it is easier for me to think of, but either way will work.
> 
> 
> -Reactor


There are unfortunately some weird striations in the resulting image:

http://i421.photobucket.com/albums/pp292/SharkD2161/Support/hf_striations.png

At least I can *see* something. :)

-Mike


Post a reply to this message

From: clipka
Subject: Re: Pattern showing *change* in slope
Date: 29 Aug 2009 00:09:47
Message: <4a98aa0b@news.povray.org>
SharkD schrieb:
> There are unfortunately some weird striations in the resulting image:
> 
> http://i421.photobucket.com/albums/pp292/SharkD2161/Support/hf_striations.png 

The factor to multiply the sqrt() term with is obviously too high, 
leading to the banded pattern.

In addition, it appears to me that your input file is suffering from 
JPEG artifacts, causing those regular-spaced vertical stripes.


Post a reply to this message

From: Reactor
Subject: Re: Pattern showing *change* in slope
Date: 29 Aug 2009 00:15:29
Message: <web.4a98aa4038d8f2bb16a06750@news.povray.org>
SharkD <mik### [at] gmailcom> wrote:
> Reactor wrote:
> > Also, isn't that the first derivative (i.e. slope), not the second?  The
> > function is roughly analogous to what you would want to do with, say, the
> > surface normal of the object (i.e. measure the normal's rate of change), or the
> > values that are returned from the slope pattern.
> >
> > If you use this directly as a pigment, you should clip it between 0 and 1.
> > Personally, I would also probably rotate the image and evaluate in the xz plane
> > because it is easier for me to think of, but either way will work.
> >
> >
> > -Reactor
>
>
> There are unfortunately some weird striations in the resulting image:
>
> http://i421.photobucket.com/albums/pp292/SharkD2161/Support/hf_striations.png
>
> At least I can *see* something. :)
>
> -Mike

The striations are do to the values going outside of the 0...1 range.  It can be
clipped using min() and max().

Are you using the change in slope to decide where to place objects?  I've been
working on a macro for that, trying to get it to decide where to place rocks
for stream beds.  It works ok, but I think it needs to average the normals in a
small radius for each point to get a more accurate test of concavity.

-Reactor


Post a reply to this message

From: SharkD
Subject: Re: Pattern showing *change* in slope
Date: 29 Aug 2009 18:04:34
Message: <4a99a5f2@news.povray.org>
clipka wrote:
> In addition, it appears to me that your input file is suffering from 
> JPEG artifacts, causing those regular-spaced vertical stripes.

Not JPEG artifacts, but artifacts from increasing the dimensions of a 
low resolution heightfield. I thought L3DT had eliminated them, but it 
didn't. Thanks.

-Mike


Post a reply to this message

From: SharkD
Subject: Re: Pattern showing *change* in slope
Date: 29 Aug 2009 19:40:53
Message: <4a99bc85$1@news.povray.org>
Reactor wrote:
> Are you using the change in slope to decide where to place objects?  I've been
> working on a macro for that, trying to get it to decide where to place rocks
> for stream beds.  It works ok, but I think it needs to average the normals in a
> small radius for each point to get a more accurate test of concavity.
> 
> -Reactor

Sort of. I am rendering the image to act as a guide. Based on the guide 
I place the objects manually in a separate application.

-Mike


Post a reply to this message

From: Tim Attwood
Subject: Re: Pattern showing *change* in slope
Date: 8 Sep 2009 16:59:01
Message: <4aa6c595$1@news.povray.org>
> Please point me to the part where it describes POV SDL.

The derivative of a surface is really 2D, but here's the
x component. It's just the change in the slope (dx) with
the interval xstep. With an image it really isn't smooth up
close, so you need to make sure that the interval is large 
enough to avoid the artefacts, and small enough to still
get an accurate slope.

camera {
  orthographic
  location <0,0,1>   
  look_at  <0,0,0>
  right 1*x 
  up 1*y
}

// input heightfield image
#declare fn1 = function {pigment {image_map {png "plasma3.png"}}};

// derivative 
#declare xstep = 0.01; 
#declare dx = function { (fn1(x,y,z).grey-fn1(x-xstep,y,z).grey) -
                         (fn1(x+xstep,y,z).grey-fn1(x,y,z).grey) };

// remap to drawable colors
#declare fcolor = function { select( dx(x,y,z)+0.5, 0, 
                             select( dx(x,y,z)-0.5, dx(x,y,z)+0.5,1))};

box { // this box fits exactly in view
  <-0.5, -0.5, 0>, <0.5, 0.5, 0>
  texture {
    pigment { 
       image_map {
          function 200,200 {fcolor(x-0.5,y-0.5,z)}
       }    
    }
  }
}


Post a reply to this message

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