The POV-Ray Cyclopedia

Ake Johansson sent me the following:

I have a problem concerning bitmapping images on objects in POV-Ray. I have modelled a beer bottle, and would like to map (using planar mapping) a label on the front of the bottle.

The mapping works fine, but i get a extra copy of the image on the back of the bottle (and in fact on the inside of the bottle as well!). When looking for information on this subject in newsgroups I have only found that "this is the way POV-Ray works".

Have you any ideas why POV-Ray maps the image on every surface that is "aligned" with the image? This makes is difficult to make e.g. a box with different bitmaps on every side...

One solution is CSG (to clip the object in half and then apply the image...), but that is rather difficult on an advanced object.

Another tips was to use the "radial" pattern, but I havent figured it out how to do this? Is this pattern applicable when I would like to make a simple image map on ONE side of a obejct...?

Well, it is true that image maps are "rods of color" extending indefinitely in certain directions. A planar map are rods of color parallel to the z axis from <0,0> to <1,1> in the x-y plane. Spherical maps plot these "rays" from the origin and they go out forever. Cylindrical maps wrap the image around a cylinder, so the rays radiate from the y axis parallel to the x-z plane.

The Coin example can be used to solve this.
Setup
Examining the bottle object
Basic Bottle Spline

Here is a bottle made with a spline and the basic texture of the glass

#declare bottle = lathe {
	quadratic_spline
	15, 
	<0.00, 0.00>, <0.00, 0.00>, <0.50, 0.00>,
	<0.60, 0.09>, <0.60, 2.01>, <0.26, 2.58>,
	<0.21, 3.39>, <0.29, 3.49>, <0.28, 3.60>,
	<0.15, 3.61>, <0.15, 2.68>, <0.38, 2.48>,
	<0.53, 1.99>, <0.55, 0.34>, <0.00, 0.10>
	sturm
}

#declare glassTexture = 
texture { 
  pigment { rgbf <0.8,0.6,0.3,0.9> }
  finish { ambient 0.1
           diffuse 0.1
           reflection 0.05
           specular 1
           roughness 0.0001 } }
The blue cylinder is the Z axis, the red cylinder is the X axis. Positive X is to the right, and positive Z is behind the bottle. In other words, almost the default view.
Method 1
Using a planar map
Here is the texture for the label (generic beer) and how the code is pieced together. The left image is a view from the front, and the right image is a view from behind the bottle.
#declare label0 = 
texture { 
  pigment { image_map { tga "label.tga"
                        map_type 0 
                        interpolate 2 
                        once } 
            translate <-0.5,1,0>
            scale <217/283,1,1>
           }
  }

object { bottle
         texture { glassTexture }
         texture { label0 }
         interior { ior 1.04 }
       }
The label is 217 pixels wide and 283 pixels tall. You can see it four times here, and it only need to be there once
Method 2
Using the coin method
Using a variation on Ron Parkers Coin solution, we manage to get rid of the labels showing up on the back of the bottle. Here's the code:
#declare Empty = pigment { rgbft 1 }

#declare label1 = texture {
  pigment { 
  radial
  pigment_map {
    [ 0.5 label ]
    [ 0.5 Empty ] } }
}    

object { bottle
         texture { glassTexture }
         texture { label1 }
         interior { ior 1.04 }
       }
Method 2
Fine Tuning the coin method
Here is a fine tuned version. Note the pigment map changes at 0.4 because the outer edge of the bottle is 0.6 units from the y axis, and the cylindrical pattern starts at density 1 on the y axis.
#declare label1 = 
  pigment { 
  radial
  pigment_map {
    [ 0.5 label ]
    [ 0.5 Empty ] } }

#declare label2 = 
 pigment {
   cylindrical
   pigment_map { [0.4 label1 ]
                 [0.4 Empty ] } 
    }

object { bottle
         texture { glassTexture }
         texture { pigment { label2 } }
         interior { ior 1.04 }
       }
  
Method 3
Adding a label to the back, as well
Using a simple can we can demonstrate how we can place two labels on the bottle. I'm using two different labels. The front label has a 2/3 aspect ratio, while the back label has a 3/2 aspect ratio. Using the same bottle we have the following:
#declare frontlabel = 
 pigment { image_map { tga "frontlabel.tga" // the file to read (iff/gif/tga/png/sys)
                        map_type 0 // 0=planar, 1=spherical, 2=cylindrical, 5=torus
                        interpolate 2 // 0=none, 1=linear, 2=bilinear, 4=normalized distance
                        once 
                        } // image_map
            translate <-0.5,1,0>
            scale <1,2/3,1>
            translate <0,0.5,0>
           }

#declare backlabel = 
 pigment { image_map { tga "backlabel.tga" // the file to read (iff/gif/tga/png/sys)
                        map_type 0 // 0=planar, 1=spherical, 2=cylindrical, 5=torus
                        interpolate 2 // 0=none, 1=linear, 2=bilinear, 4=normalized distance
                        once 
                        } // image_map
            translate <-0.5,00,0>
            scale <1,3/2,1>
            translate 0.5 *y
           }
           
 
#declare Empty = pigment { rgbt 1 }

#declare label1 = 
  pigment { 
  radial
  pigment_map {
    [ 0.5 frontlabel ]
    [ 0.5 backlabel rotate 180*y ] } }

#declare label2 = 
 pigment {
   cylindrical
   pigment_map { [0.41 label1 ]
                 [0.41 Empty ] } 
    }
 


object { beerbottle
         texture { glassTexture }
         texture { pigment { label2 } }
//         interior { ior 1.04 }
       }

Send feedback, or head back to the Cyclopedia.

Thanks for watching.