POV-Ray : Newsgroups : povray.advanced-users : Color function Server Time
27 Dec 2024 16:09:56 EST (-0500)
  Color function (Message 1 to 4 of 4)  
From: val
Subject: Color function
Date: 30 Mar 2005 14:15:00
Message: <web.424af75ff455f9a3238336500@news.povray.org>
Hi folks

I'd like to make a simple scene with the Cook & Torrance model for light
reflection instead or the common Phong model. I thought it could be easy,
but after many hours I realized it was at least not as simple as I thought.

I started using a pigment function to implement the diffuse lighting in
a sphere:

    #declare fun = function { (max(0, (sx*(x-px) + sy*(y-py) + sz*(z-pz)
)/rd + amb)*0.5 }

where <px, py, pz> is the sphere center (so <x-px, y-py, z-pz> is the sphere
normal), and <sx, sy, sz> is the normalized light vector. rd is the sphere
radius and amb is the amount of ambient lighting.

Then the sphere object is declared as

    sphere { <px, py, pz>  rd
      texture {
          pigment { function { fun(x, y, z) }
               color_map { [0.0 rgb <0,0.0,0.0>*2]
                           [1.0 rgb colr*2] }
          }
          finish { ambient 1 diffuse 0 }
      }
    }

where colr is the rgb color of the sphere. The diffuse lighting works fine,
but it is almost impossible to stablish a color map to represent all the
colors needed by the specular reflection.
So, I realized I need a way to color the pixel in position (x, y, z), or, in
other words, I need a function like this one:

      texture {
          pigment { color { function { fun_color(x, y, z) }
          }
          finish { ambient 1 diffuse 0 }
      }

but, of course, POV doesn't recognize this sintaxe.
Suggestions?

Val


Post a reply to this message

From: PM 2Ring
Subject: Re: Color function
Date: 7 Apr 2005 12:50:00
Message: <web.425563e2d92a72013d6ca37a0@news.povray.org>
"val" <val### [at] carraraus> wrote:

> So, I realized I need a way to color the pixel in position (x, y, z), or, in
> other words, I need a function like this one:
>
>       texture {
>           pigment { color { function { fun_color(x, y, z) }
>           }
>           finish { ambient 1 diffuse 0 }
>       }
>
> but, of course, POV doesn't recognize this sintaxe.
> Suggestions?

Here's one possibility below. You may also like to know that POV can cope
with negative colour values. I'll post a relevant example soon.

// Persistence of Vision Ray Tracer Scene Description File
// File: PigFunc.pov
// Vers: 3.6
// Desc: Pigment function demo
// Date: 2005.02.19
// Auth: PM 2Ring
//
//  -D +A0.1 +AM2 +R3
//  -F -A0.4 +AM2 +R1
//

#version 3.6;

global_settings {
  assumed_gamma 1
}

camera {
  location <0, 5, -1> * 2.4
  look_at  0
  right x*image_width/image_height up y

  angle 40
}

light_source {
   <0, 2, -1> * 30
   rgb 1
}

//Make a color_map from a0 to a1
#macro CMRange(a0, a1)color_map{[0 a0][1 a1]}#end

//Make a color_map from Black to a
#macro CMFull(a)CMRange(rgb 0, a)#end

#declare TestPig = pigment{hexagon rgb<1 .9 .5>, rgb <.85 .5 .6>, rgb <0 0
..8>}

#declare f_Pig = function{pigment{TestPig}}

//Turn a pigment function into a real-live pigment!
#declare PigRGB =
pigment{
  average
  pigment_map {
    [1 function{f_Pig(x,y,z).red} CMFull(red 3)]
    [1 function{f_Pig(x,y,z).green} CMFull(green 3)]
    [1 function{f_Pig(x,y,z).blue} CMFull(blue 3)]
  }
}

cylinder{
  -.1*y, .1*y, 3

  pigment{
    PigRGB
    //TestPig
  }
}

//---------------------------------------------------------


Post a reply to this message

From: val
Subject: Re: Color function
Date: 20 Apr 2005 10:55:00
Message: <web.42666bf1d92a7201238336500@news.povray.org>
"PM 2Ring" <nomail@nomail> wrote:
> Here's one possibility below. You may also like to know that POV can cope
> with negative colour values. I'll post a relevant example soon.
>
>
> //Make a color_map from a0 to a1
> #macro CMRange(a0, a1)color_map{[0 a0][1 a1]}#end
>
> //Make a color_map from Black to a
> #macro CMFull(a)CMRange(rgb 0, a)#end
>
> #declare TestPig = pigment{hexagon rgb<1 .9 .5>, rgb <.85 .5 .6>, rgb <0 0
> ..8>}
>
> #declare f_Pig = function{pigment{TestPig}}
>
> //Turn a pigment function into a real-live pigment!
> #declare PigRGB =
> pigment{
>   average
>   pigment_map {
>     [1 function{f_Pig(x,y,z).red} CMFull(red 3)]
>     [1 function{f_Pig(x,y,z).green} CMFull(green 3)]
>     [1 function{f_Pig(x,y,z).blue} CMFull(blue 3)]
>   }
> }
>
> cylinder{
>   -.1*y, .1*y, 3
>
>   pigment{
>     PigRGB
>     //TestPig
>   }
> }
>
> //---------------------------------------------------------

Thanks. It works! It took me a couple of days to realize that
the function should span in RGB components:

#declare fun_x = function { color_x*max(0, (sx*(x-px) + sy*(y-py) +
sz*(z-pz))/raio) + color_x*amb  }
#declare fun_y = function { color_y*max(0, (sx*(x-px) + sy*(y-py) +
sz*(z-pz))/raio) + color_y*amb  }
#declare fun_z = function { color_z*max(0, (sx*(x-px) + sy*(y-py) +
sz*(z-pz))/raio) + color_z*amb  }

#declare PigRGB =
pigment{
  average
  pigment_map {
    [1 function{fun_x(x,y,z)} color_map{[0 rgb 0][1 red 3]}]
    [1 function{fun_y(x,y,z)} color_map{[0 rgb 0][1 green 3]}]
    [1 function{fun_z(x,y,z)} color_map{[0 rgb 0][1 blue 3]}]
  }
}

// create a sphere shape
sphere {
  pos        // center of sphere <X Y Z>
  raio       // radius of sphere
  pigment{ PigRGB }
  finish { ambient 1 diffuse 0 }
}


Val


Post a reply to this message

From: PM 2Ring
Subject: Re: Color function
Date: 30 Apr 2005 04:45:01
Message: <web.427344b2d92a7201e1f4d92c0@news.povray.org>
Hi val,

> "PM 2Ring" <nomail@nomail> wrote:
> > Here's one possibility below. You may also like to know that POV can cope
> > with negative colour values. I'll post a relevant example soon.
>
> Thanks. It works! It took me a couple of days to realize that
> the function should span in RGB components:
>
> #declare fun_x = function { color_x*max(0, (sx*(x-px) + sy*(y-py) +
> sz*(z-pz))/raio) + color_x*amb  }
> #declare fun_y = function { color_y*max(0, (sx*(x-px) + sy*(y-py) +
> sz*(z-pz))/raio) + color_y*amb  }
> #declare fun_z = function { color_z*max(0, (sx*(x-px) + sy*(y-py) +
> sz*(z-pz))/raio) + color_z*amb  }
>
> #declare PigRGB =
> pigment{
>   average
>   pigment_map {
>     [1 function{fun_x(x,y,z)} color_map{[0 rgb 0][1 red 3]}]
>     [1 function{fun_y(x,y,z)} color_map{[0 rgb 0][1 green 3]}]
>     [1 function{fun_z(x,y,z)} color_map{[0 rgb 0][1 blue 3]}]
>   }
> }
> Val

Great! I forgot about cleaning up my negative colours example, but in the
mean time I'll post a related pigment function example in p.b.i., thread
"Pigment Functions". This one lets you do a fake MC Escher "Circle Limit"
effect, using stereographic projection.


Post a reply to this message

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