POV-Ray : Newsgroups : povray.newusers : Really weird image mapping results Server Time
31 Oct 2024 19:20:46 EDT (-0400)
  Really weird image mapping results (Message 1 to 3 of 3)  
From: Bald Eagle
Subject: Really weird image mapping results
Date: 12 Oct 2014 13:25:07
Message: <web.543ab8f6e381fe465e7df57c0@news.povray.org>
I've been playing around with mapping a texture onto half of an oblate spheroid,
and I've gotten really weird results.

Here's what I get:
The image seems to be half-scaled compared to the object it gets mapped onto.
The image has a weird "doubling" effect. (top right)
When I display the same hemi-spheroid as a guide, my image-mapped object
disappears, (lower right)
but when I rotate them at different angles, I can see the image map above, and
through the green below. (lower left)

Also interesting is the "chopping" going on between the 4 views.
It's like there's differencing going on between things that should be
independent.

.... I think the trouble may be due to the nut behind my keyboard ...

//#######################################################################
Image file:
http://news.povray.org/*/attachment/%3Cweb.54375641cbb3d8155e7df57c0%40news.povray.org%3E/medallion1.png
//#######################################################################

#version 3.7;
global_settings{ assumed_gamma 1.0 }

#include "debug.inc"
 Set_Debug (true)
#include "colors.inc"
#include "textures.inc"
#include "glass.inc"
#include "metals.inc"
#include "golds.inc"
#include "stones.inc"
#include "woods.inc"
#include "shapes.inc"
#include "shapes2.inc"
#include "functions.inc"
#include "math.inc"
#include "transforms.inc"

#declare Feet = 12;

#ifdef (SDL)
 // do nothing
#else
//--------------------------------------------------------------------------------------------------------<<<<
//--------------------------------------------------------------------------------------------------------<<<<
//------------------------------------------------------------- Camera_Position,
Camera_look_at, Camera_Angle
#declare Camera_Number = 0;
//--------------------------------------------------------------------------------------------------------<<<<
//--------------------------------------------------------------------------------------------------------<<<<
#switch ( Camera_Number )
#case (0)
  #declare Camera_Position = < 0, 0, -4*Feet> ;  // front view
  #declare Camera_Look_At  = < 0, 0,  0.00> ;
  #declare Camera_Angle    =  65 ;
#break
#case (1)
  #declare Camera_Position = < 5.00, 5.00, -4.00> ;  // diagonal view
  #declare Camera_Look_At  = < 0.70, 1,  0.00> ;
  #declare Camera_Angle    =  42 ;
#break
#case (2)
  #declare Camera_Position = < 0.00, 1.00,-20.00> ;  // front view
  #declare Camera_Look_At  = < 0.00, 1.00,  0.00> ;
  #declare Camera_Angle    =  65 ;
#break
#case (3)
  #declare Camera_Position = < 0*Feet, 2*Feet,  0*Feet> ;  // top view
  #declare Camera_Look_At  = < 0.00, 0*Feet,  0*Feet> ;
  #declare Camera_Angle    =  65 ;
#break
#case (4)
  #declare Camera_Position = < 0.00, 9*Feet,  27*Feet> ;  // mobile view
  #declare Camera_Look_At  = < 0.00, 0*Feet,  33*Feet> ;
  #declare Camera_Angle    =  65 ;
#break
#case (5)
  #declare Camera_Position = < 0.00, 6*Feet,  35*Feet> ;  // mobile view
  #declare Camera_Look_At  = < 0.00, 6*Feet,  25*Feet> ;
  #declare Camera_Angle    =  65 ;
#break
#else
  #declare Camera_Position = < 0.00, 1.00,-20.00> ;  // front view
  #declare Camera_Look_At  = < 0.00, 1.00,  0.00> ;
  #declare Camera_Angle    =  65 ;
#break
#end // of "#switch ( Camera_Number )" -----------------------------
//-------------------------------------------------------------------------------------------------------<<<<
//-------------------------------------------------------------------------------------------------------<<<<
camera { location Camera_Position
        right    x*image_width/image_height
        angle    Camera_Angle
        look_at  Camera_Look_At
 }

light_source {<0*Feet, 0*Feet, -10*Feet> color rgb <1, 1, 1>*0.4}

// sky --------------------------------------------------------------------

sky_sphere{ pigment{ gradient <0,1,0>
                     color_map{ [0   color rgb <1, 1, 1>         ]//White
                                [0.4 color rgb <0.14, 0.14, 0.56>]//~Navy
                                [0.6 color rgb <0.14, 0.14, 0.56>]//~Navy
                                [1.0 color rgb <1, 1, 1>         ]//White
                              }
                     scale 2 }
           } // end of sky_sphere

#end  // end SDL check



#declare Medallion =
texture {
 pigment {//uv_mapping
  image_map {
  png "Medallion1.png"
  once
  //map_type 1    // planar
  //interpolate 0
  //once
  //texture { pigment {Red} }
  //texture { Gold_Metal }
  }
 } //rotate x*90 //scale 0.25 translate <1, 0, 0>
}

#declare Gold = texture {T_Gold_2A finish {phong 1 metallic reflection {0.2}} }

#declare Sine   = function (x,y) {sin (y/sqrt (pow (x,2) + pow (y,2)) )}
#declare Circle = function (x,y) { 1- (pow (x,2) + pow (y,2)) }


//##############################################################################
#declare Hemisphere =
union {
difference {
 sphere {0, 1 }
 box {0, 1 translate <-.5, -.5, 0> scale 2}
 texture {Medallion translate -0.5}
 scale <18, 18, 1.5>
}
cylinder {<0,0,0>, <10, 0, 0> 0.125}
cylinder {<0,0,0>, <0, 10, 0> 0.125}
cylinder {<0,0,0>, <0, 0, 10> 0.125}
}



#declare Hemispheroid =
difference {
 sphere {0, 1}
 box {0, 1 translate <-.5, -.5, 0> scale 2}
 scale <18, 18, 1.5>
 pigment {Green filter 0.99}
}

object {Hemisphere   translate <-15, 10, 0> }
//object {Hemispheroid translate <-15, 10, 0>}

object {Hemisphere   rotate x*70 translate <15, 10, 0> }
//object {Hemispheroid translate <15, 10, 0>}

object {Hemisphere   translate <-15, -10, 0> }
object {Hemispheroid rotate x*70 translate <-15, -10, 0>}

object {Hemisphere   translate <15, -10, 0> }
object {Hemispheroid translate <15, -10, 0>}


//##############################################################################
#declare Quarter =
height_field {
 function 200,200 {
  pattern {
   function {Circle (x, y)}
   // waves scale 0.1
   // turbulence 0.8
  }
 }
 translate -z*1
 /*pigment{ gradient <0,1,0>
 color_map{  [0   color rgb <0, 0, 0>         ]  //Blue
   [1.0 color rgb <1, 1, 1>         ]  //White
  }
 }*/
 scale <10, 5, 10> * 0.5
 rotate x * 0
   }

#declare MedallionFunction =
difference {
 union {
  object {Quarter}
  object {Quarter rotate y*90}
  object {Quarter rotate y*180}
  object {Quarter rotate y*270}
  }
 sphere {0, 1 scale 2 inverse}
 rotate x*90
 texture {Medallion}
}


Post a reply to this message

From: Alain
Subject: Re: Really weird image mapping results
Date: 12 Oct 2014 14:14:26
Message: <543ac502@news.povray.org>

> I've been playing around with mapping a texture onto half of an oblate spheroid,
> and I've gotten really weird results.
>
> Here's what I get:
> The image seems to be half-scaled compared to the object it gets mapped onto.
> The image has a weird "doubling" effect. (top right)
> When I display the same hemi-spheroid as a guide, my image-mapped object
> disappears, (lower right)
> but when I rotate them at different angles, I can see the image map above, and
> through the green below. (lower left)
>
> Also interesting is the "chopping" going on between the 4 views.
> It's like there's differencing going on between things that should be
> independent.
>
> .... I think the trouble may be due to the nut behind my keyboard ...
>
> //#######################################################################
> Image file:
>
http://news.povray.org/*/attachment/%3Cweb.54375641cbb3d8155e7df57c0%40news.povray.org%3E/medallion1.png
> //#######################################################################
>
> #version 3.7;
> global_settings{ assumed_gamma 1.0 }
>
....
> #declare Feet = 12;
>
> #ifdef (SDL)
>   // do nothing
> #else
>
//--------------------------------------------------------------------------------------------------------<<<<
>
//--------------------------------------------------------------------------------------------------------<<<<
> //------------------------------------------------------------- Camera_Position,
> Camera_look_at, Camera_Angle
> #declare Camera_Number = 0;
>
//--------------------------------------------------------------------------------------------------------<<<<
>
//--------------------------------------------------------------------------------------------------------<<<<
...
>
//-------------------------------------------------------------------------------------------------------<<<<
>
//-------------------------------------------------------------------------------------------------------<<<<
> camera { location Camera_Position
>          right    x*image_width/image_height
>          angle    Camera_Angle
>          look_at  Camera_Look_At
>   }
...
>
> #declare Medallion =
> texture {
>   pigment {//uv_mapping
>    image_map {
>    png "Medallion1.png"
>    once
>    //map_type 1    // planar
>    //interpolate 0
>    //once
>    //texture { pigment {Red} }
>    //texture { Gold_Metal }
>    }
>   } //rotate x*90 //scale 0.25 translate <1, 0, 0>
> }

The image is mapped from <0,0> to <1,1> (the X-Y plane) and extend along 
the Z axis to infinity.

>
> #declare Gold = texture {T_Gold_2A finish {phong 1 metallic reflection {0.2}} }
>
> #declare Sine   = function (x,y) {sin (y/sqrt (pow (x,2) + pow (y,2)) )}
> #declare Circle = function (x,y) { 1- (pow (x,2) + pow (y,2)) }

This should be:
#declare Circle = function (x,y) { 1- sqrt(pow (x,2) + pow (y,2)) }

>
>
> //##############################################################################
> #declare Hemisphere =
> union {
> difference {
>   sphere {0, 1 }
>   box {0, 1 translate <-.5, -.5, 0> scale 2}
>   texture {Medallion translate -0.5}
>   scale <18, 18, 1.5>
> }

This half sphere extend toward -Y and it's flat part is on the X-Z plane
The image is mapped relative to the X-Y plane.
You need to rotate the image_map +90*x, translate it by -0.5 along the X 
axis and scale it by 2.

> cylinder {<0,0,0>, <10, 0, 0> 0.125}
> cylinder {<0,0,0>, <0, 10, 0> 0.125}
> cylinder {<0,0,0>, <0, 0, 10> 0.125}
> }
Reference axis, beter to colour them according to their directions: Red 
for the X, Green for the Y and Blue for the Z are standard.

>
>
>
> #declare Hemispheroid =
> difference {
>   sphere {0, 1}
>   box {0, 1 translate <-.5, -.5, 0> scale 2}
>   scale <18, 18, 1.5>
>   pigment {Green filter 0.99}
> }

Coincident with the previous hemisphere. Make the sphere larger by a 
*very* small amount: sphere{0, 1.00001}
Translate the box a tiny bit lower: box {0, 1 translate <-.5, -.50001, 
0> scale 2}

Those changes will make sure that this object is realy visible.

>
> object {Hemisphere   translate <-15, 10, 0> }
> //object {Hemispheroid translate <-15, 10, 0>}
>
> object {Hemisphere   rotate x*70 translate <15, 10, 0> }
> //object {Hemispheroid translate <15, 10, 0>}
>
> object {Hemisphere   translate <-15, -10, 0> }
> object {Hemispheroid rotate x*70 translate <-15, -10, 0>}
>
> object {Hemisphere   translate <15, -10, 0> }
> object {Hemispheroid translate <15, -10, 0>}
>
>
> //##############################################################################
> #declare Quarter =
> height_field {
>   function 200,200 {
>    pattern {
>     function {Circle (x, y)}
>     // waves scale 0.1
>     // turbulence 0.8
>    }
>   }
>   translate -z*1
>   /*pigment{ gradient <0,1,0>
>   color_map{  [0   color rgb <0, 0, 0>         ]  //Black
>     [1.0 color rgb <1, 1, 1>         ]  //White
>    }
>   }*/
>   scale <10, 5, 10> * 0.5
>   rotate x * 0
>     }
>
> #declare MedallionFunction =
> difference {
>   union {
>    object {Quarter}
>    object {Quarter rotate y*90}
>    object {Quarter rotate y*180}
>    object {Quarter rotate y*270}
>    }
>   sphere {0, 1 scale 2 inverse}
>   rotate x*90
>   texture {Medallion}
> }
>
>


Post a reply to this message

From: Bald Eagle
Subject: Re: Really weird image mapping results
Date: 12 Oct 2014 16:00:01
Message: <web.543adc746bae7a595e7df57c0@news.povray.org>
Alain <kua### [at] videotronca> wrote:

> The image is mapped from <0,0> to <1,1> (the X-Y plane) and extend along
> the Z axis to infinity.

Yes, I understood that.

> This should be:
> #declare Circle = function (x,y) { 1- sqrt(pow (x,2) + pow (y,2)) }

True.  I was messing around with all sorts of stuff, and abandoned that for the
time being while I tried to understand the mapping of a bona-fide hemisphere.

 //##############################################################################
> > #declare Hemisphere =
> > union {
> > difference {
> >   sphere {0, 1 }
> >   box {0, 1 translate <-.5, -.5, 0> scale 2}
> >   texture {Medallion translate -0.5}
> >   scale <18, 18, 1.5>
> > }
>
> This half sphere extend toward -Y and it's flat part is on the X-Z plane
> The image is mapped relative to the X-Y plane.
> You need to rotate the image_map +90*x, translate it by -0.5 along the X
> axis and scale it by 2.

Nope.
First off, my sphere is centered at the origin with radius of 1.
Next, I make a box extending from the origin to <1,1,1>
Then it gets translated halfway to the left, and halfway down, so it's still
sticking back in the +z direction.
Then it gets scaled by 2, and since its front face is at z=0, it gets scaled
relative to the origin to give a box that extends from <-1, -1, 0> to <1, 1, 2>
This chops off the back side of the sphere to give the flat part in the X-Y
plane, and the front part of the sphere extends in the -z direction.

The image map is therefore shifted by -0.5 in each direction to center it on the
origin, since the z-translation is irrelevant.

You can actually see that this is the case in the image - the view is looking at
the origin from -z, the image is mapped onto the convex face of the hemisphere,
and the rotated green hemisphere shows that it started off with the flat in X-Y.

If it makes you feel any better, I somehow had x and z all twisted around in my
head the other day when rotating an image map texture.

I looked it over and fixed the scaling, and it looks a lot better.  I got
confused between the image map itself, and the thing it was getting mapped on,
so I was expecting the "once" to map the image ONCE onto the _object_, but that
was my misinterpretation, and it did indeed need to be scaled.

> Coincident with the previous hemisphere.

I can't believe I got snookered by the coincident surface problem!
AAAAAAAAAAAAAaaaaaaaaaaaaaaaaaaaaaaaaaaaaarrrrrrrrrrrrrrrggggghhh!
:(


Thanks for helping me look this over - I took a walk, ate lunch, looked at it
with fresh eyes after you pointed those things out and it's looking like I
wanted and actually better than I expected.

Merci!


Post a reply to this message

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