POV-Ray : Newsgroups : povray.advanced-users : height field generation Server Time
23 Dec 2024 14:47:00 EST (-0500)
  height field generation (Message 1 to 5 of 5)  
From: Dan Connelly
Subject: height field generation
Date: 30 Sep 2008 00:24:01
Message: <48e1a9e1$1@news.povray.org>
I found the Perl::GD module convenient for generating a height field.  For example:

#! /usr/bin/perl
use strict;
use GD::Simple;

# create a new image
my npoints = 256;
my $image = GD::Simple->new($npoints, $npoints);

# .. (clipped) a 2-d array f is populated with values, with maximal value fmax

for my $nx ( 0 .. $npoints - 1) {
   for my $ny ( 0 .. $npoints - 1) {
     my $f = int(255 * $f[$nx]->[$ny] / $fmax);
     my $color = $image->colorExact($f, $f, $f);
     $color = $image->colorAllocate($f, $f, $f)
       if ($color < 0);
     die
       if ($color < 0);
     $image->setPixel($nx,$ny,$color);
   }
}

open FOUT, ">heightfield.png"
   or die;
print FOUT $image->png;


Post a reply to this message

From: Christian Froeschlin
Subject: Re: height field generation
Date: 30 Sep 2008 09:02:14
Message: <48e22356$1@news.povray.org>
> I found the Perl::GD module convenient for generating a height field.  

If you have a function to generate the height
field, you can also use it in SDL directly:

#declare npoints = 512;
#declare f       = function {0.1+0.1*sin(x*20)};
#declare fmax    = 0.2;

height_field
{
   function npoints, npoints {f(x,0,y)/fmax}
}


Post a reply to this message

From: Dan Connelly
Subject: Re: height field generation
Date: 30 Sep 2008 11:24:09
Message: <48e24499$1@news.povray.org>
Christian Froeschlin wrote:
>> I found the Perl::GD module convenient for generating a height field.  
> 
> If you have a function to generate the height
> field, you can also use it in SDL directly:
> 
> #declare npoints = 512;
> #declare f       = function {0.1+0.1*sin(x*20)};
> #declare fmax    = 0.2;
> 
> height_field
> {
>   function npoints, npoints {f(x,0,y)/fmax}
> }

Thanks!

A disadvantage of the Perl GD module is I can't figure out how to generate 16-bit PNG
with it, which is a real issue, even with "smooth".  The advantage, of course, is you
needn't reevaluate the function each time the code is executed, depending on the
function complexity.

Dan


Post a reply to this message

From: Christian Froeschlin
Subject: Re: height field generation
Date: 30 Sep 2008 19:08:30
Message: <48e2b16e$1@news.povray.org>
Dan Connelly wrote:

> The advantage, of course, is you needn't reevaluate the function each 
> time the code is executed, depending on the function complexity.

You can also use a POV script to generate a 16-bit PNG
based on a function, either by defining a function pigment
or by rendering the heigth_field itself using hf_gray_16.


Post a reply to this message

From: Mark Weyer
Subject: Re: height field generation
Date: 1 Oct 2008 05:20:01
Message: <web.48e3404ddfbf1b63fddaa4670@news.povray.org>
> A disadvantage of the Perl GD module is I can't figure out how to generate
> 16-bit PNG with it, which is a real issue, even with "smooth".  The advantage,
> of course, is you needn't reevaluate the function each time the code is
> executed, depending on the function complexity.

I recommend the ppm or, in the case of heightfields, pgm format instead of png.
It is very easy to create, with as many bits as you want.

Povray does support ppm, but I am unsure whether bit-depths higher than 16
are supported. Also, I am unsure if pgm is supported, but you can always use
ppm im case it is not.

See http://netpbm.sourceforge.net/doc/#formats

Best regards,

  Mark Weyer


Post a reply to this message

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