POV-Ray : Newsgroups : povray.newusers : Complex blending between multiple image_maps Server Time
29 Jul 2024 18:17:23 EDT (-0400)
  Complex blending between multiple image_maps (Message 1 to 5 of 5)  
From: Eric James
Subject: Complex blending between multiple image_maps
Date: 22 Jul 2005 12:20:00
Message: <web.42e11c275f2b4af23b6b98ba0@news.povray.org>
Hi,

I'm a relative newcomer to POV-Ray and I'm trying to render many external
objects that were created for realtime application and not with POV-Ray in
mind.  I've been able to translate all of the scene geometry into POV-Ray
correctly using some external applications that handle the conversion to
the Mesh2 format.  However, I'm completely stuck when it comes to the
textures.  Every object has at least 3 distinct image_maps applied to it
that are blended together in a complex fashion (since the real-time 3d APIs
strongly encourage you to do that to achieve detailed visuals).

As an example of the kinds of things that are being done between image_map
layers, any two textures can be blended together by either, adding them
together, subtracting one from the other, multiplying them together (and
optionally afterwards multiplying the result by 2.0 or 4.0), add them
together and then subtract 0.5, blending them based on the alpha channel of
the second texture, or blend between them either based on vertex alpha's of
the mesh or the vertex greyscale color of the mesh. This process is
inherently stackable, such that to the result of a blend between any two
image_maps, another can be blended in the same fashion.  In order to be
able to render these models in POV-Ray as they were designed, I need to
write a POV-Ray exporter for the objects' textures.

However I can't seem to find a straightforward equivalent way to do these
blendings between uv_mapped image_maps.  From reading over the
documentation I've only been able to figure out how to blend based on 1
texture's alpha channel or based on a constant using the "average" keyword.
 I unfortunately have not been successful at searching for a solution.

Are there any known links that might explain how I might go about doing
this?  Alternately, does anyone have any suggestions as to how I could
structure the texture{} blocks such that I can implement any of these
blending equations between multiple image_maps?

The closest I can see would be to use custom functions to do it, which is
above my knowledge level without a bit of further guidance or examples, for
which I would be extremely appreciative.

Thanks for the help!

Eric


Post a reply to this message

From: Mike Williams
Subject: Re: Complex blending between multiple image_maps
Date: 22 Jul 2005 17:17:21
Message: <IB+x$GAlIW4CFwST@econym.demon.co.uk>
Wasn't it Eric James who wrote:
>
>The closest I can see would be to use custom functions to do it, which is
>above my knowledge level without a bit of further guidance or examples, for
>which I would be extremely appreciative.

It's not easy. What you have to do is this:

Declare pigment functions from the two image maps

#declare IM1 = function {pigment {image_map {jpeg "tex1.jpg" interpolate 2}}}
#declare IM2 = function {pigment {image_map {jpeg "tex2.jpg" interpolate 2}}}

Perform separate mathematical operations on the red, green and blue channels, to
produce three blended pigments, one for each colour channel. These pigment
functions need to have a colour_map that triples the brightness (see later).

You can perform whatever arithmetic operations you want here. I'm just going to
add them.

#declare R = pigment {function {IM1(x,y,z).red + IM2(x,y,z).red}
   colour_map{[0 rgb 0][1 rgb <3,0,0>]}}

#declare G = pigment {function {IM1(x,y,z).green + IM2(x,y,z).green}
   colour_map{[0 rgb 0][1 rgb <0,3,0>]}}

#declare B = pigment {function {IM1(x,y,z).blue + IM2(x,y,z).blue}
   colour_map{[0 rgb 0][1 rgb <0,0,3>]}}

Finally assemble the three component pigments using an "average" pigment_map.
By averaging three pigments that are on different colour channels, the
brightness gets divided by 3. That's why we tripled the brightness earlier. 
E.g. if the output colour of a particular pixel is white, we'd get that by the
fact that (<3,0,0> + <0,3,0> + <0,0,3>)/3 = <1,1,1>.

sphere {0,1
  pigment {average
    pigment_map {
      [1 R]
      [1 G]
      [1 B]
    }
  }
}

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Eric James
Subject: Re: Complex blending between multiple image_maps
Date: 22 Jul 2005 18:35:00
Message: <web.42e1721d299815bb3b6b98ba0@news.povray.org>
>
> It's not easy. What you have to do is this:
>

Wow, you're not kidding. ;)  That does look complicated, but definitely
workable.    I can't wait to try that out first thing Monday.

I have only one remaining question, how can I bring mesh vertex alphas or
mesh vertex colors into the equations, such that I can use them as the
blending parameters, such that the equation would be something like:
final_color = (img1_color * vert_alpha) + (img2_color * (1.0 - vert_alpha));

Many thanks for the help!  I definitely think I'll be able to get this
working and I would not have been able to do so on my own.

Eric


Post a reply to this message

From: Mike Williams
Subject: Re: Complex blending between multiple image_maps
Date: 22 Jul 2005 22:02:34
Message: <o8MGRBAuUa4CFwUJ@econym.demon.co.uk>
Wasn't it Eric James who wrote:
>>
>> It's not easy. What you have to do is this:
>>
>
>Wow, you're not kidding. ;)  That does look complicated, but definitely
>workable.    I can't wait to try that out first thing Monday.
>
>I have only one remaining question, how can I bring mesh vertex alphas or
>mesh vertex colors into the equations, such that I can use them as the
>blending parameters, such that the equation would be something like:
>final_color = (img1_color * vert_alpha) + (img2_color * (1.0 - vert_alpha));

I don't think that question means anything in POV. What are you trying
to do with the mesh vertices that's different from other points on the
surface? Where would you be getting the vertex colours from when you've
not created the pigment yet? 

-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

From: Eric James
Subject: Re: Complex blending between multiple image_maps
Date: 25 Jul 2005 10:50:00
Message: <web.42e4fb79299815bbcc017cc80@news.povray.org>
> I don't think that question means anything in POV. What are you trying
> to do with the mesh vertices that's different from other points on the
> surface? Where would you be getting the vertex colours from when you've
> not created the pigment yet?

You're quite right.  Some of the objects I'm trying to import blend between
textures based on the colors specified for the mesh vertices themselves.  I
incorrectly assumed I'd be able to do the equivalent in POV.  The only
option I seem to have is to convert that vertex color based blending into
vertex-texture interpolation as defined in the 2.4.2.4.2 section of the
documentation, though going from one method to the other doesn't look to be
easy.

Thanks again for all the help.


Post a reply to this message

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