POV-Ray : Newsgroups : povray.general : Help with macro(s) for simulating weather patterns : Re: Help with macro(s) for simulating weather patterns Server Time
29 Jul 2024 08:21:40 EDT (-0400)
  Re: Help with macro(s) for simulating weather patterns  
From: Alain
Date: 16 Apr 2012 17:48:04
Message: <4f8c9394@news.povray.org>

> clipka<ano### [at] anonymousorg>  wrote:
>>
>> Remember that you need to pass a #declare'd (or #local) object to
>> trace(). Note that trace() only probes this single object, and that this
>> object isn't visible in the scene unless you also instantiate it with
>> "object{MyObjectVariable}". You could use this to trace() a height_field
>> of the image.
>
> Of course, why didn't I realise that... *shakes head at himself*
>
> Thanks :D
>
>>
>> trace() is comparatively slow for your purposes though. Instead, a
>> better alternative is probably to define a "pigment function", which you
>> can then directly evaluate to retrieve the pigment's color at any given
>> point. The "functions.inc" macro "eval_pigment" encapsulates this in a
>> simple macro:
>>
>> #macro eval_pigment(pigm, vec)
>>       #local fn = function { pigment { pigm } }
>>       #local result = (fn(vec.x, vec.y, vec.z));
>>       result
>> #end
>
> That looks exactly what I want. Many thanks clipka :)
>
>>
>> You pass it the pigment and the point to be evaluated, and will get a
>> color value. (This is one of the few exceptions where functions may
>> return colors rather than scalars.)
>
> Probably why I haven't heard of it. ;)
>
> So, a good way to read an image would be something like this?
>
> Identify the image to pov with a #declare or #local, whichever is appropriate.
> Pull the x and y resolutions from it using a function (I know there's one around
> somewhere, can't find it at the moment).
> Use a nested loop to write the values from the image to a two dimensional array.
>
>  From there, it's a simple thing to determine if the point in question is water,
> or if not, how close to water it is. If the planet in use has no surface water,
> then it would be a simple thing to add an "eval_pigment" to the macro, with a
> conditional value which returns true or false depending, thus saving
> computational time. :)
>
> Any flaws?
>
> Thanks for your time.
>
> Regards
> D103
>
>

 From the documentations:

As of version 3.7 experimental support for reading the pixel resolution 
of an image map was added. This is done by giving an image map pigment 
identifier to max_extent(), which will then return the resolution of the 
image map as the x and y values of the returned vector.

Sample code:
#declare Image =
pigment {
   image_map {
     jpeg "YourImage.jpg"
     once
     }
   };

#declare Resolution = max_extent ( Image );

It return Resolution = <horizontal_size, vertical_size, 0>;



Alain


Post a reply to this message

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