POV-Ray : Newsgroups : povray.general : using an image_map for media density/color? Server Time
26 Dec 2024 00:19:56 EST (-0500)
  using an image_map for media density/color? (Message 1 to 8 of 8)  
From: Kenneth
Subject: using an image_map for media density/color?
Date: 28 Mar 2006 00:15:00
Message: <web.4428c5d859cea9017bf568ef0@news.povray.org>
Hi, all!

I'm trying to use an image_map to color some media in a transparent
box--that is, "extruding" the image_map's colors in the +Z direction,
"filling" the box from front to back with emitting (or scattering) media,
the colors of which correspond to the image_map colors.  My image_map has
an alpha channel as well (the idea being that the transparent parts of the
image_map will create NO media density.)

A recent post got me to thinking about this...

http://news.povray.org/povray.general/thread/%3Cweb.44174d8d9ca30044945ca8690%40news.povray.org%3E/

I'm not even sure that what I'm attempting to do is possible; I've tried
various ideas with no luck. Reading the POV docs in sections 3.5.11.15 and
16, I'm thinking that the image_map should first be turned into a pattern
function(?)...  Like this:

#declare my_pattern =
function{
 pigment{
  image_map{png "my_image.png"
    map_type 0
    interpolate 2
    once
    }
     }
     }

and then *trying* to apply it to an interior{media} statement,
like this example (which doesn't work, and generates an error message):

interior{
 media{
  emission .5
  density{
   my_pattern
     }
                      }
           }


Am I on the wrong track entirely? When I try to use the image_map itself in
the media's density block, I get the error message, "image_map can only be
used in a pigment statement."  Perhaps my image_map should instead be
turned into a color_map somehow (?)

I feel like I'm overlooking something obvious. Any help or suggestions would
be most appreciated. This technique would be *very* useful.

BTW, my_pattern works perfectly well when used properly as an isosurface
function, so I'm at a loss as to why it isn't working in media.

Ken


Post a reply to this message

From: Mike Williams
Subject: Re: using an image_map for media density/color?
Date: 28 Mar 2006 02:06:21
Message: <8qxMFBAS9NKEFwOC@econym.demon.co.uk>
Wasn't it Kenneth who wrote:
>Hi, all!
>
>I'm trying to use an image_map to color some media in a transparent
>box--that is, "extruding" the image_map's colors in the +Z direction,
>"filling" the box from front to back with emitting (or scattering) media,
>the colors of which correspond to the image_map colors.  My image_map has
>an alpha channel as well (the idea being that the transparent parts of the
>image_map will create NO media density.)

If this can be done, then using a single pattern isn't the way to go.
The problem is that you want all four colour channels to affect the
colour and density of the media, but using a pattern reduces the data to
a single channel.

        density {image_pattern {png "my_image.png"}}

You can split your image into three: red*alpha, green*alpha, blue*alpha.
Then use an interior that contains three media components. Since you're
using emission media, black is the same as transparent. 

interior {
  media {
    emission .5
    density {
      image_pattern {png "red.png"}
      colour_map {[0 rgb 0][1 rgb x]}
    }
  }
  media {
    emission .5
    density {
      image_pattern {png "green.png"}
      colour_map {[0 rgb 0][1 rgb y]}
    }
  }
  media {
    emission .5
    density {
      image_pattern {png "blue.png"}
      colour_map {[0 rgb 0][1 rgb z]}
    }
  }
}

For the other types of media, things get a little more complicated.

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Bruno Cabasson
Subject: Re: using an image_map for media density/color?
Date: 28 Mar 2006 02:45:01
Message: <web.4428e8b336d0704182fc96790@news.povray.org>
"Kenneth" <kdw### [at] earthlinknet> wrote:
> Hi, all!
>
> I'm trying to use an image_map to color some media in a transparent
> box--that is, "extruding" the image_map's colors in the +Z direction,
> "filling" the box from front to back with emitting (or scattering) media,
> the colors of which correspond to the image_map colors.  My image_map has
> an alpha channel as well (the idea being that the transparent parts of the
> image_map will create NO media density.)
>
> A recent post got me to thinking about this...
>
>
http://news.povray.org/povray.general/thread/%3Cweb.44174d8d9ca30044945ca8690%40news.povray.org%3E/
>
> I'm not even sure that what I'm attempting to do is possible; I've tried
> various ideas with no luck. Reading the POV docs in sections 3.5.11.15 and
> 16, I'm thinking that the image_map should first be turned into a pattern
> function(?)...  Like this:
>
> #declare my_pattern =
> function{
>  pigment{
>   image_map{png "my_image.png"
>     map_type 0
>     interpolate 2
>     once
>     }
>      }
>      }
>
> and then *trying* to apply it to an interior{media} statement,
> like this example (which doesn't work, and generates an error message):
>
> interior{
>  media{
>   emission .5
>   density{
>    my_pattern
>      }
>                       }
>            }
>
>
> Am I on the wrong track entirely? When I try to use the image_map itself in
> the media's density block, I get the error message, "image_map can only be
> used in a pigment statement."  Perhaps my image_map should instead be
> turned into a color_map somehow (?)
>
> I feel like I'm overlooking something obvious. Any help or suggestions would
> be most appreciated. This technique would be *very* useful.
>
> BTW, my_pattern works perfectly well when used properly as an isosurface
> function, so I'm at a loss as to why it isn't working in media.
>
> Ken

Hello!

AFAIK, an image_map is only defined in the x-y plane. So, I guess that using
it as a 3 dimensional pattern will lead to non-zero values only in that
plane, and therefore your density will be non-zero in an infinitely thin
slice of your container, ... which I am afraid will also be valuated to
zero.

   Regards.


Post a reply to this message

From: Bruno Cabasson
Subject: Re: using an image_map for media density/color?
Date: 28 Mar 2006 03:20:01
Message: <web.4428f19636d0704182fc96790@news.povray.org>
"Bruno Cabasson" <bru### [at] alcatelaleniaspacefr> wrote:

> AFAIK, an image_map is only defined in the x-y plane. So, I guess that using
> it as a 3 dimensional pattern will lead to non-zero values only in that
> plane, and therefore your density will be non-zero in an infinitely thin
> slice of your container, ... which I am afraid will also be valuated to
> zero.
>
>    Regards.

Ooops! not 100% awake this morning ... My reply was not very smart ...
Forget it. Mike's is much more sensible ...


Post a reply to this message

From: Bruno Cabasson
Subject: Re: using an image_map for media density/color?
Date: 28 Mar 2006 03:40:01
Message: <web.4428f64e36d0704182fc96790@news.povray.org>
"Bruno Cabasson" <bru### [at] alcatelaleniaspacefr> wrote:
> "Bruno Cabasson" <bru### [at] alcatelaleniaspacefr> wrote:
>
> > AFAIK, an image_map is only defined in the x-y plane. So, I guess that using
> > it as a 3 dimensional pattern will lead to non-zero values only in that
> > plane, and therefore your density will be non-zero in an infinitely thin
> > slice of your container, ... which I am afraid will also be valuated to
> > zero.
> >
> >    Regards.
>
> Ooops! not 100% awake this morning ... My reply was not very smart ...
> Forget it. Mike's is much more sensible ...

I had a cofee and my brain functions a little now ;)

This piece of code works:

#declare my_pattern = function
{
    pigment
    {
        image_map
        {
            png "my_image.png"
            map_type 0
            interpolate 2
            once
        }
    }
}

box
{
    0, 1
    pigment {rgbt 1}
    hollow
    interior
    {
        media
        {
            emission Red
            density {function  {my_pattern(x,y,z).red}}
        }
        media
        {
            emission Green
            density {function  {my_pattern(x,y,z).green}}
        }
        media
        {
            emission Blue
            density {function  {my_pattern(x,y,z).blue}}
        }
    }
}

Regards


Post a reply to this message

From: Kenneth
Subject: Re: using an image_map for media density/color?
Date: 29 Mar 2006 13:15:00
Message: <web.442acca136d07041bcf27ce60@news.povray.org>
"Bruno Cabasson" <bru### [at] alcatelaleniaspacefr> wrote:

> This piece of code works:
>
> #declare my_pattern = function
> {
>     pigment
>     {
>         image_map
>         {
>             png "my_image.png"
>             map_type 0
>             interpolate 2
>             once
>         }
>     }
> }
>
> box
> {
>     0, 1
>     pigment {rgbt 1}
>     hollow
>     interior
>     {
>         media
>         {
>             emission Red
>             density {function  {my_pattern(x,y,z).red}}
>         }
>         media
>         {
>             emission Green
>             density {function  {my_pattern(x,y,z).green}}
>         }
>         media
>         {
>             emission Blue
>             density {function  {my_pattern(x,y,z).blue}}
>         }
>     }
> }
>
> Regards


Sorry for the delay in replying; I've been experimenting!

Thanks to both you and Mike Williams for posting these techniques; I
wouldn't have thought of either one.

Your code does indeed work.  Very neat! The trouble, though, is that the
function seems to be ignoring the alpha channel in the image_map image. Or
rather, it treats the alpha channel as pure white, and fills the box with
full media density there. (I tried *LOTS* of odd tricks to get rid of that,
to no avail.) Any idea why?

I did come up with a workaround--getting rid of the alpha channel altogether
and substituting black for it in the image. That wiped out the offending
surrounding media.

Ultimately, I got your technique to work very well (with a few
modifications) by using THREE versions of my image_map...two as functions,
(no alpha channel)
and one (WITH the alpha channel) simply projected onto the box as a regular
pigment--the give the final object more "definition." Plus, using both
absorbing and emitting media, each with separate functions derived from
different versions of my image_map.  The result is a nice solid-looking
object, in the shape of the image, and nicely textured on the outside
"shell"...just what I wanted! Describing this process in detail would be
*most* difficult, so instead, I'll put together a visual description of it,
in steps, and post it soon over at p.b.i., along with the code.

I haven't yet tried Mike Williams' technique; I'll tackle that next.

Just thought I'd add that POV doesn't allow something like emission red as a
color specification (it generates an error). emission <1,0,0> is the
simple workaround, of course.

THANKS AGAIN!

Ken W.


Post a reply to this message

From: Chambers
Subject: Re: using an image_map for media density/color?
Date: 29 Mar 2006 15:36:43
Message: <442aefdb$1@news.povray.org>
Kenneth wrote:
> Just thought I'd add that POV doesn't allow something like emission red as a
> color specification (it generates an error). emission <1,0,0> is the
> simple workaround, of course.
> 
> THANKS AGAIN!
> 
> Ken W.


Quick note: He really specified "emission Red", which is not the same 
thing as "emission red".  The second requires a float value after the 
"red", while the first is #declared in colors.inc as "red 1" (or "rgb 
<1,0,0>", I don't know which).

...Chambers


Post a reply to this message

From: Kenneth
Subject: Re: using an image_map for media density/color?
Date: 31 Mar 2006 11:40:01
Message: <web.442d5a9c36d0704176e868250@news.povray.org>
Chambers <bdc### [at] yahoocom> wrote:
> Kenneth wrote:
> > Just thought I'd add that POV doesn't allow something like emission red as a
> > color specification (it generates an error). emission <1,0,0> is the
> > simple workaround, of course.
> >
> > THANKS AGAIN!
> >
> > Ken W.
>
>
> Quick note: He really specified "emission Red", which is not the same
> thing as "emission red".  The second requires a float value after the
> "red", while the first is #declared in colors.inc as "red 1" (or "rgb
> <1,0,0>", I don't know which).
>
> ...Chambers

The identifier "red" followed by a float value is something I didn't know
about.  Many thanks. Time for me to re-read 3.2.1.5 Specifying Colors  ;-)


Post a reply to this message

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