POV-Ray : Newsgroups : povray.advanced-users : Pattern showing *change* in slope Server Time
1 Jul 2024 05:56:42 EDT (-0400)
  Pattern showing *change* in slope (Message 11 to 20 of 26)  
<<< Previous 10 Messages Goto Latest 10 Messages Next 6 Messages >>>
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

<<< Previous 10 Messages Goto Latest 10 Messages Next 6 Messages >>>

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