POV-Ray : Newsgroups : povray.general : Using a function in a height_field declaration Server Time
25 Apr 2024 06:38:32 EDT (-0400)
  Using a function in a height_field declaration (Message 1 to 10 of 58)  
Goto Latest 10 Messages Next 10 Messages >>>
From: Bald Eagle
Subject: Using a function in a height_field declaration
Date: 13 Feb 2023 14:45:00
Message: <web.63ea928499ce13121f9dae3025979125@news.povray.org>
According to:
https://wiki.povray.org/content/Reference:Height_Field

(At the very bottom)

"The height field object also allows for substituting a user defined function
instead of specifying an image. That function can either be in it's literal
form, or it can be a call to a function that you have predeclared. The user
supplied parameters FieldResolution_X and FieldResolution_Y are integer values
that affect the resolution of the color/index values, not size of the unscaled
height field."

There is, of course, no code snippet supplied, so I'm just casting about trying
to get this to work.

Has anyone used this method before?

-BW


Post a reply to this message

From: Bald Eagle
Subject: Re: Using a function in a height_field declaration
Date: 13 Feb 2023 17:10:00
Message: <web.63eab4b743a1dd881f9dae3025979125@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:

> There is, of course, no code snippet supplied, so I'm just casting about trying
> to get this to work.

Got it to work.
Part of the issue was just the scale and the orthographic camera + camera
position.
Very nice and fast.  Isosurface looks better and smoother, but I'm still
playing...


Post a reply to this message

From: yesbird
Subject: Re: Using a function in a height_field declaration
Date: 13 Feb 2023 17:20:00
Message: <web.63eab64b43a1dd883691b85710800fb2@news.povray.org>
Very interesting !
Could you share the scene, please ? May be I will use this trick in my POV-Lab
....


Post a reply to this message

From: Bald Eagle
Subject: Re: Using a function in a height_field declaration
Date: 13 Feb 2023 19:10:00
Message: <web.63ead0ea43a1dd881f9dae3025979125@news.povray.org>
"yesbird" <nomail@nomail> wrote:
> Very interesting !
> Could you share the scene, please ? May be I will use this trick in my POV-Lab
> ....

#version 3.8;
global_settings {assumed_gamma 1}
#declare E = 0.00001;



camera {
 orthographic
 location <image_width/2, image_height/2,  -image_width*2>
 right x*image_width
 up y*image_height
 //sky y
 look_at <image_width/2, image_height/2, 0>
 rotate y*0
}

light_source {<image_width/2, image_height/2, -image_width*4> rgb 1 shadowless}


#declare BWCM = color_map {
 [0 rgb 0]
 [1 rgb 1]
}

#declare RGCM = color_map {
 [0.0 rgb x]
 [0.54 rgb x+y]
 [0.54 rgb 0] // black elevation line
 [0.55 rgb 0]
 [0.55 rgb x+y]
 [1.0 rgb y]
}

height_field {
 function 500 500 {pigment {bozo scale 0.1 color_map {BWCM} }}
 smooth
 pigment {gradient y color_map {RGCM} scale 0.9}
 scale image_height/2
 translate <image_width/3, image_height/4, 0> rotate -x*80
}


Post a reply to this message

From: Cousin Ricky
Subject: Re: Using a function in a height_field declaration
Date: 13 Feb 2023 19:45:48
Message: <63ead9bc$1@news.povray.org>
On 2023-02-13 18:15 (-4), yesbird wrote:
> Very interesting !
> Could you share the scene, please ? May be I will use this trick in my POV-Lab

Here is an example with a user-defined function:

---------[BEGIN CODE]----------
#version 3.7;
global_settings { assumed_gamma 1 }

#declare MyFunction = function (x, y)
{ (2 - cos (x * 2*pi) - cos (y * 2*pi)) / 4
}

height_field
{ function 20, 20 { MyFunction (x, y) }
  smooth
  translate -<0.5, 0, 0.5>
  scale <4, 2, 4>
  pigment { green 0.5 }
}

camera
{ location <-2.913, 2.985, -10.873>
  look_at y
  angle 26.2648
}
#default { finish { diffuse 0.6 ambient rgb 0.15005 emission 0 } }
light_source
{ <-5.804, 12.609, -10.054>, rgb 1391125
  fade_power 2 fade_distance 0.0098425
  spotlight point_at y
  radius 38.861 falloff 90 tightness 0.25
}
box { -1, 1 scale <13, 14, 13> pigment { rgb 1 } }
plane
{ y, 0
  pigment { checker rgb 0.05 rgb 1 }
}
----------[END CODE]-----------

You can also define the function directly inside the height_field statement:

height_field
{ function 20, 20 { (2 - cos (x * 2*pi) - cos (y * 2*pi)) / 4 }
  ...
}


Post a reply to this message

From: Cousin Ricky
Subject: Re: Using a function in a height_field declaration
Date: 13 Feb 2023 19:50:01
Message: <63eadab9$1@news.povray.org>
On 2023-02-13 15:41 (-4), Bald Eagle wrote:
> 
> Has anyone used this method before?

Yes, for the hills in my prefab render rig:

https://github.com/CousinRicky/POV-ShapeOfTheDay

It's in file shapeoftheday.inc


Post a reply to this message

From: yesbird
Subject: Re: Using a function in a height_field declaration
Date: 13 Feb 2023 20:30:00
Message: <web.63eae2ca43a1dd8848296d0110800fb2@news.povray.org>
>
> Here is an example with a user-defined function:
> ...

Thanks a lot, very compact and fast method, I'll use it in my project.


Post a reply to this message

From: Thomas de Groot
Subject: Re: Using a function in a height_field declaration
Date: 14 Feb 2023 02:12:03
Message: <63eb3443$1@news.povray.org>
Op 13/02/2023 om 20:41 schreef Bald Eagle:
> 
> Has anyone used this method before?
> 

Sure thing. It is the method used in "Journey to an Unknown Region" 
landscape. :-)

-- 
Thomas


Post a reply to this message

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

Goto Latest 10 Messages Next 10 Messages >>>

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