POV-Ray : Newsgroups : povray.general : Using a function in a height_field declaration Server Time
28 Dec 2024 18:22:01 EST (-0500)
  Using a function in a height_field declaration (Message 9 to 18 of 58)  
<<< Previous 8 Messages Goto Latest 10 Messages Next 10 Messages >>>
From: William F Pokorny
Subject: Re: Using a function in a height_field declaration
Date: 14 Feb 2023 05:25:57
Message: <63eb61b5$1@news.povray.org>
On 2/13/23 19:45, Cousin Ricky wrote:
> #declare MyFunction = function (x, y)
> { (2 - cos (x * 2*pi) - cos (y * 2*pi)) / 4
> }
> 
> height_field
> { function 20, 20 { MyFunction (x, y) }
>    smooth

Good example. I always get tripped up when I come back to height_fields 
because the function variables used are x and y (to match image based 
height_fields I guess) while the generated height field sits atop the 
x,z plane with y being the height. I too often first code my function 
using x and z!

Bill P.

---
Another quick example.

#declare Fn02 = function { pattern { granite scale 0.5 } }
#declare Orange = srgb <1,0.50196,0>;
#declare HF00 = height_field {
     function 800, 800 { Fn02(x,y,z) }
     smooth
     pigment { color Orange }
     translate <-0.5,0,-0.5>
     scale <2,0.05,2>
}


Post a reply to this message

From: yesbird
Subject: Re: Using a function in a height_field declaration
Date: 14 Feb 2023 05:45:00
Message: <web.63eb65fe43a1dd8868fd655b10800fb2@news.povray.org>
> Another quick example.
>

Do not see anything, except "Black Square" by kazimir Malevich:

------------------------------------------
#version 3.8;
global_settings { assumed_gamma 1 }

#declare Fn02 = function { pattern { granite scale 0.5 } }
#declare Orange = srgb <1,0.50196,0>;
#declare HF00 = height_field {
     function 800, 800 { Fn02(x,y,z) }
     smooth
     pigment { color Orange }
     translate <-0.5,0,-0.5>
     scale <2,0.05,2>
}

camera
{ location <10,10,10>
  look_at <0,0,0>
  angle 90
}

light_source
{ <10,10,10>, rgb <1,1,1>
}
------------------------------------------
YB


Post a reply to this message

From: Kenneth
Subject: Re: Using a function in a height_field declaration
Date: 14 Feb 2023 07:25:00
Message: <web.63eb79dd43a1dd889b4924336e066e29@news.povray.org>
"yesbird" <nomail@nomail> wrote:
> > Another quick example.
> >
>
> Do not see anything, except "Black Square" by kazimir Malevich:
>

Although you #declared your height_field as HF00, you forgot to actually use it
in the scene. A simple mistake. ;-)

......
#declare HF00 = height_field {
     function 800, 800 { Fn02(x,y,z) }
     smooth
     pigment { color Orange }
     translate <-0.5,0,-0.5>
     scale <2,0.05,2>
}

object{HF00} // or simply  HF00, which also works...sometimes...depending on
// other code that comes before its use. Stick to object{HF00} for now.

----------
By the way: Somewhere in the documentation, it states that when using a function
for a height_field, and creating that function from a pigment/pattern like
granite, the function 'sees' (or uses) only a 2-dimensional 'slice' of the 3-D
pattern-- and in the x/y plane, not the x/z plane as you might imagine.
Otherwise,
           function { pattern { granite scale 0.5 } }

IS fully 3-dimensional.

(I HOPE I have this information correct.)


Post a reply to this message

From: yesbird
Subject: Re: Using a function in a height_field declaration
Date: 14 Feb 2023 07:40:00
Message: <web.63eb805843a1dd8868fd655b10800fb2@news.povray.org>
> Although you #declared your height_field as HF00, you forgot to actually use it
> in the scene. A simple mistake. ;-)

Ooo, thanks for correction, the reason was a 'blind' copy/paste ...
Now I see, that relief is really beautiful, will use this function for
landscaping :)
--
YB


Post a reply to this message

From: yesbird
Subject: Re: Using a function in a height_field declaration
Date: 14 Feb 2023 08:35:00
Message: <web.63eb8cd543a1dd8868fd655b10800fb2@news.povray.org>
Yet another mystery. In following example 50 is resolution, but how to set range
for x,z ? Only small part of surface is visible.

---------------------------------------------------
#version 3.8;
global_settings { assumed_gamma 1 }

camera
{ location <1,1,1> * 2
  look_at <0,0,0>
  angle 50
}

light_source { <10,10,10>, rgb <1,1,1> }

height_field
{
  function 50, 50 { sin (sqrt (x*x + y*y)) / (sqrt (x*x + y*y)) }
  smooth
  scale <1, 0.3, 1>
  pigment { green 0.8 }
}
---------------------------------------------------
YB


Post a reply to this message

From: Kenneth
Subject: Re: Using a function in a height_field declaration
Date: 14 Feb 2023 11:00:00
Message: <web.63ebab6243a1dd889b4924336e066e29@news.povray.org>
"yesbird" <nomail@nomail> wrote:
> Yet another mystery. In following example 50 is resolution, but how to set range
> for x,z ? Only small part of surface is visible.
>

Ah, that's simple too:

By default, a height_field is only 1X1 units square (x and z). That's the way
POV-ray creates it, regardless of the resolution that you give to the function.

So, you would need to simply scale-up the entire height_field afterward-- say,
10X10. BUT, that also requires that you change two other things, to keep the
height_field looking nice and detailed:

1) increase the given resolution of the function. That is, instead of
        function 50,50{...}
it should now be  function 50*10,50*10 {...}. Or 500,500. Of course, this higher
resolution takes longer to process, because there are now more triangles that
have to be created. By the way, the resolution is not the square size of the
height_field, but its 'detail'... the number of triangles.

2) (optional)  If you want the granite pattern to look 'the same size'
as in your original 1X1 render-- but spread over the larger area-- you
will need to either scale-down the original pattern by 1/10, OR use a
function trick to do it afterward:
     #declare HF00 = height_field {
     function 500, 500 { Fn02(x*10,y*10,z*10) }

(Actually, the z does not need this when making a height_field; z is
ignored.)

The interesting thing to notice is that a function's 'scaling' is the opposite
of what would seem normal-- 10 instead of 1/10.


Post a reply to this message

From: Kenneth
Subject: Re: Using a function in a height_field declaration
Date: 14 Feb 2023 12:00:00
Message: <web.63ebbdaf43a1dd889b4924336e066e29@news.povray.org>
"yesbird" <nomail@nomail> wrote:
> Yet another mystery. In following example 50 is resolution, but how to set range
> for x,z ? Only small part of surface is visible.
>
> height_field
> {
>   function 50, 50 { sin (sqrt (x*x + y*y)) / (sqrt (x*x + y*y)) }
>   smooth
>   scale <1, 0.3, 1>
>   pigment { green 0.8 }
> }

That's because the sine waves are too 'large' to see in the 1X1 height_field.

Try this function 'scaling' trick for an interesting-- if odd-looking -- result.
(I changed your light_source position to <10,4,10> to make it easier to see, and
gave the function a higher resolution):

function 200, 200 { sin (sqrt (x*x + y*y)*20) / (sqrt (x*x + y*y)*20)}

As you can see, playing around with function values can be quite fun!


Post a reply to this message

From: yesbird
Subject: Re: Using a function in a height_field declaration
Date: 14 Feb 2023 12:35:00
Message: <web.63ebc50343a1dd8868fd655b10800fb2@news.povray.org>
Thanks, Kenneth.

Of сourse I've tried to play with arguments scaling , but problem in shifting
from origin (please look at attachment). Still can't figure out how it work.

----------------------------------------------------
#version 3.8;
global_settings { assumed_gamma 1 }

camera
{ location <1,1,1> * 2
  look_at <0,-0.5,0>
  angle 50
}

light_source { <10,10,10>, rgb <1,1,1> }

#declare somb = function (x,y) { sin (sqrt (x*x + y*y)) / sqrt (x*x + y*y) };

height_field
{
  function 500, 500 { somb(x*10, y*10) }

  smooth
  scale <1, 0.3, 1>
  pigment { green 0.8 }
}
----------------------------------------------------
YB


Post a reply to this message


Attachments:
Download 'height_field.png' (34 KB)

Preview of image 'height_field.png'
height_field.png


 

From: Bald Eagle
Subject: Re: Using a function in a height_field declaration
Date: 14 Feb 2023 13:25:00
Message: <web.63ebd17943a1dd881f9dae3025979125@news.povray.org>
"yesbird" <nomail@nomail> wrote:

> Of сourse I've tried to play with arguments scaling , but problem in shifting
> from origin (please look at attachment). Still can't figure out how it work.

You're using multiplication.division to scale.

You shift it over from the origin in the same way, just with
addition/subtraction.


So where you have (x*x), you would use ( (x+3)*(x+3) ) to shift everything to
the left.  Same works for y with up/down and z with backwards/forwards.

- BW


Post a reply to this message

From: yesbird
Subject: Re: Using a function in a height_field declaration
Date: 14 Feb 2023 14:05:00
Message: <web.63ebda3d43a1dd8868fd655b10800fb2@news.povray.org>
> You shift it over from the origin in the same way, just with
> addition/subtraction.

I know, but why I should shift it ? We are looking straight at the origin, peak
should be there, or I am missing something ?
--
YB


Post a reply to this message

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

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