POV-Ray : Newsgroups : povray.advanced-users : Using lightmaps generated with POV back into POV textures : Using lightmaps generated with POV back into POV textures Server Time
27 Jun 2024 14:26:07 EDT (-0400)
  Using lightmaps generated with POV back into POV textures  
From: Jaime Vives Piqueres
Date: 27 Jan 2011 05:22:48
Message: <4d414778$1@news.povray.org>
Hi Gurus:

   I'm back at trying to develop my "texture baking" experiments into a 
more serious and usable technique for general usage. I'm working on a 
demo scene (and the corresponding how-to) with bundled tools to automate 
the process as much as possible.

   So far, the "direct texture baking" approach is working pretty well: 
when I use the baked textures back into the textures, without lighting, 
the result is the expected one (see living_room-tb.jpg on p.b.i.).

   But the "lightmapping" approach is giving me some headaches... the 
problem is not the map generation itself, but the "loading back" step 
where I "mix" the desired final pigment and the lightmap. This is what 
CG people calls "modulating" the texture with the lightmap. Everyone 
seems to be doing it just with multiplication, but I can't get good 
results with this method... not even multpliying it twice (see 
living_room-lm1.jpg and living_room-lm2.jpg on p.b.i.).

   Can anyone think of a better (more suited) operation than simple 
multiplication?

// macro baked_texture()
//
// params:
//
// * p_lightmap: lightmap pigment
// * t_pigment: pigment to combine with the lightmap
// * t_finish: finish for the resulting texture
// * t_normal: normal for the resulting texture
//
// description:
//
// creates an uv mapped texture by multiplying the specified pigments
// and adding the specified finish and normal statements
//
// uv_mapping is added to pigment and normal individually to allow
// for texture layering over the resulting texture
//
// min() is used on the lightmap function to avoid strange artifacts
// when using interpolation (not present when using 3.6)
//
#macro baked_texture(p_lightmap,t_pigment,t_finish,t_normal)

   #local ft_pigment = function { pigment { t_pigment } };
   #local fp_lightmap = function { pigment { p_lightmap } };
   #local RED = pigment {
     function { ft_pigment(x,y,z).red * min(fp_lightmap(x,y,z).red,1) }
     color_map { [0 rgb 0][1 rgb <1,0,0>] }
   }
   #local GREEN = pigment {
     function { ft_pigment(x,y,z).green * min(fp_lightmap(x,y,z).green,1) }
     color_map { [0 rgb 0][1 rgb <0,1,0>] }
   }
   #local BLUE = pigment {
     function { ft_pigment(x,y,z).blue * min(fp_lightmap(x,y,z).blue,1) }
     color_map { [0 rgb 0][1 rgb <0,0,1>] }
   }
   #local TC = pigment {
     function { ft_pigment(x,y,z).transmit }
     color_map { [0 rgb 0][1 rgb 0 transmit 1] }
   }
   #local FC = pigment {
     function { ft_pigment(x,y,z).filter }
     color_map { [0 rgb 0][1 rgb 0 filter 1] }
   }

   texture{
     pigment{
       uv_mapping
       average
       pigment_map{
         [1 RED]
         [1 GREEN]
         [1 BLUE]
         [1 TC]
         [1 FC]
       }
     }
     finish{
       t_finish
       emission 5
     }
     normal{
       uv_mapping
       t_normal
     }
   }

#end


-- 
Jaime Vives Piqueres
		
La Persistencia de la Ignorancia
http://www.ignorancia.org


Post a reply to this message

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