Friday, June 18, 2010

Creating terrain in PoVRay using isosurface and pigment

The original jpeg
Every now and again I play around with isosurfaces in PoVRay. The one thing I persistently have trouble remembering how to do is generate solid terrain using a heightfield image mapped onto an isosurface.
There are plenty of examples out there of how to do it with a sphere, but for terrain you would rather use a box. 
Here's an example using the jpeg to the left.

#declare P1=function{

pigment{
image_map{jpeg "texturegen.jpg" map_type 0 }
rotate x*180 translate <0.5,0.5,0> scale 2 }
}
Note the translation, rotation and scaling are required to make the original image sit in the same orientation and position on the isosurface as they appear in the original image.
The second part is the isosurface itself.

The isosurface version
#declare Height = 1 //use this to vary the depth of the image
#declare Land =

   isosurface {
      function { z-Height*P1(x,y,z).gray}
      contained_by{box{<-1,-1,-1><1,1,1>}}
      max_gradient 20
      translate <-0.5,0.5,-0.5> scale <5,5,0.2>

      rotate x*-90
   }
object {Land translate <-0.5,0,-0.5> scale <100,1,100> }
Again, the isosurface has to be scaled and rotated for the image to appear correctly on the top side.

Was this post complete gobbledygook? You need to visit PoVRay.