POV-Ray : Newsgroups : povray.advanced-users : Frustration!! : Re: Frustration!! Server Time
1 Jul 2024 05:42:57 EDT (-0400)
  Re: Frustration!!  
From: Mike Williams
Date: 15 Aug 2009 11:18:32
Message: <amLsAECAHthKFwr4@econym.demon.co.uk>
Wasn't it Lioness who wrote:
>Hi all,
>
>I have a smal problem and I hope you can help me .... I have been working with
>Pov-Ray since version 1, never had any problems doing what I wanted to do, but
>this one is doing my head in!
>
>Why is the following not working? Pov-Ray throws a massive wobbler when
>I try to
>run this code. It's probably something really stupid, but I can't see what the
>problem is ....
>
>#declare Image1 = function{pigment{image_map{jpeg "scene100.jpg"
>             interpolate 2 once } translate<-0.5,-0.5,0> scale 6}}
>#declare Image2 = function{pigment{image_map{jpeg "sand1b.jpg"
>             interpolate 2 once }translate<-0.5,-0.5,0> scale 6}}
>
>#declare Val1 = function{Image1(x,y,z).gray}
>#declare Val2 = function{Image2(x,y,z).gray}
>
>#declare OverlayRed =
>pigment
>{
>    #if(Val1 > Val2)
>       function{(1-Image1(x,y,z).red)*(1-Image2(x,y,z).red)/1}
>                 colour_map{[0 rgb 0][1 rgb <2,0,0> ]}
>    #else
>      function{(Image1(x,y,z).red)*Image2(x,y,z).red)/1}
>                 colour_map{[0 rgb 0][1 rgb <2,0,0>] }
>    #end
>}
>
>Everything works fine until I put the if-then-else thing in ...
>
>I hope you can help. Thanks in advance!

#if statements are resolved during the Parse phase of the processing, so
you can say things like
  #if(Val1(0,0,0) > Val2(0,0,0))
Which causes one of the two functions to be chosen at parse time
depending on the colour of a particular point specified at parse time,
then used for every point of the resulting pigment.


"select" statements are resolved at run time, so you can use them to
examine each point and choose the corresponding function depending on
the values of the images at that point. The syntax gets a bit
convoluted:

#declare OverlayRed =
pigment
{
    function { select ((Image1(x,y,z).gray - Image2(x,y,z).gray)
                 ,
               ((1-Image1(x,y,z).red)*(1-Image2(x,y,z).red)/1)
                 ,
               ((Image1(x,y,z).red)*Image2(x,y,z).red/1)
               )
             }
    colour_map{[0 rgb 0][1 rgb <2,0,0>] }
}

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

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