POV-Ray : Newsgroups : povray.advanced-users : Crafting a heightfield : Re: Crafting a heightfield Server Time
18 Apr 2024 23:27:57 EDT (-0400)
  Re: Crafting a heightfield  
From: Thomas de Groot
Date: 28 Nov 2018 07:24:11
Message: <5bfe88eb@news.povray.org>
On 27-11-2018 14:08, Bald Eagle wrote:
> Sure, that sounds great.  :)
> I think there are a lot of methods and work-flow "tricks" that are hard to come
> by - and there are SO many areas in POV-Ray that have that sort of learning
> curve / time investment.
> 
> And it's comparatively easy to throw some random stuff around and make it look
> good vs coding up the SDL to do something within very specific parameters.
> I think Archimedes was quoted as saying something about "art" vs math &
> geometry.  (I have not been able to rediscover the exact quote)
> 
> Most of what I like about POV-Ray is that it blends the art and geometry, and
> the deveopers and community give us one a good set of tools to bridge the two
> approaches.
> 
> Thanks, Thomas  :)
> All the best.
> 

This is a bit more tricky than I thought initially. I generally build my 
height_fields using an external program, usually the now ancient 
GeoControl (flavoured if necessary by pinches of e.g. TerraBrush, 
Wilbur, World Machine (1)) and rendered as an image_map function. That 
said, I sometimes draw the landscape beforehand in e.g. The Gimp, as a 
grey-scale contour map. I did this for instance for the Gancaloon 
project. However, I then pass this map through GeoControl in order to 
smooth out the steps between grey values (2). This is close to what 
Leroy is doing with his macros and the advantage is a fair control over 
where the topographic features need to be.

To place buildings and such where I want on the obtained height_field, I 
follow a process that is also closely related to Leroy's methodology: I 
create a /square/ map from the height_field with the orthographic 
camera. To the height_field I generally add the origin axis (at the 
centre of the height_field, ideally) and -optionally - a regular grid 
(adding no_shadow). Typically, the camera code looks like this:

//start code
camera {
   #local CamLoc    = <0.0, HF_scale.x/2, 0.0>;
   #local CamLookAt = <0.0,   0.0, 0.0>;
   orthographic
   location  CamLoc
   look_at   CamLookAt
   angle     90
   right     x*AspectRatio
}
//end code

where HF_scale is the size of the height_field, generally large, like 
8000 x 8000, and AspectRatio being image_width/image_height of course.

You now have a map on which you can determine the coordinates of your 
buildings, using e.g. The Gimp. However, you need to do a little 
calculation to convert the Gimp coordinates (origin at bottom left) to 
the POV-Ray coordinates (origin at the centre of the height_field). I 
use the following macro:

//start code
//Macro to transform a GIMP location on an orthographic map (origin 
lower left corner)
//to a POV height_field location (origin at centre of map).
//An offset (x- and z directions) needs to be determined experimentally
//as there seems to be a small discrepancy between the two map renders.

#macro LocTrans(Input)
   #local HFS      = HF_scale.x;  //assuming x = z
   #local Mdim     = MapDim; //number of pixels (assuming x = z) of the 
orthographic map view
   #local InTrans  = (100*Input)/Mdim;  //percentages from origin
   #local OutTrans = (HFS*InTrans)/100; //location on scaled height_field
   #declare Output = <-(HFS/2)+OutTrans.x, Input.y, (HFS/2)-OutTrans.z>; 
//location according to origin

   Output
   //#debug concat("\n  InTrans: <",vstr(3, InTrans, ", ", 0,3),">\n")
   //#debug concat("  OutTrans: <",vstr(3, OutTrans, ", ", 0,3),">\n")
   //#debug concat("  Output: <",vstr(3, Output, ", ", 0,3),">\n")
#end
//end code

You may need to determine offset values for x and z experimentally as 
the accuracy is not 100% in most cases. The y direction is of course 
found using trace().

Another use for the map is to draw areas where you want specific 
groupings of things, like trees. This can be done adding layers to the 
map in The Gimp and painting coloured fields over the map. In POV-Ray 
you can populate those areas on the height_field using the evalpigment 
macro.

If you use a program like GeoControl, maps with a road pattern obtained 
from the preceding action can be added to make them slightly eroded into 
the landscape or to add a particular road texture.

(1) Possibly already known locations, but:
https://www.world-creator.com/ (successor of GeoControl)
http://www.cyberfunks.de/page/terrabrush/index.htm
http://www.fracterra.com/wilbur.html
http://www.world-machine.com/index.php

(2) The drawback of the method is that it is difficult to add 
close-fitting extra height_fields to the boundaries, especially if the 
grey-scale map is passed through the sieve of another application. That 
happened to my Gancaloon landscape when I wanted to extend it. When 
under water, boundary differences are obviously unimportant, but on land...

I get the impression this is about all. If I remember additional tricks, 
I shall come back here. As an afterthought, I attach a document I wrote 
on the Gancaloon matter back in 2012.

All the above is open to further improvements. If this inspires others 
to more and better implementations I shall be very interested to hear 
from them.

-- 
Thomas


Post a reply to this message


Attachments:
Download 'guidelines for city builders.pdf' (921 KB)

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