POV-Ray : Newsgroups : povray.newusers : gradient question Server Time
28 Dec 2024 23:42:54 EST (-0500)
  gradient question (Message 1 to 10 of 12)  
Goto Latest 10 Messages Next 2 Messages >>>
From: Lothar Esser
Subject: gradient question
Date: 19 Sep 2001 14:08:32
Message: <3BA8DF4D.B476E3EC@helix.nih.gov>
Hi,
   at the risk of embarrassing myself: I have a question about gradient
in a pigment statement. What I want to do is to colour a cylinder which
is not necessarily aligned with x,y,z or any simple combination of it
from one end to the other with a simple gradient. For some reason an
arbitrary vector in the gradient statement seems to be ignored.
A statement like
   cylinder {
       <-1,-1,0>, <1,1,0>, 0.2
       texture { pigment { gradient <1,1,0> color_map { [ 0.0 color rgb
1] [1.0 color rgb <0,0,1>] } } } ... etc
works but if I have a cylinder with the end points like <-0.1,-1,0>,
<0.1,1,0> then I cannot figure out what the correct
gradient vector is: gradient <0.2,2,0> does not work. I thought I did
not understand it well enough so I played around with
other values just to find out that no matter what I use like <2,0.2,0>
or <0.1,2,0> or any other combination of numbers the color gradient on
my cylinder looks exactly the same. If someone would like an example I
can provide a simple povray input file.
I know a way around it would be to generate a generic cylinder of unit
length aligned with say x then apply a color gradient with using
gradient x and then I would have to scale and translate the whole thing
into its correct position. This can be done but seems rather
inconvenient.
My question is this: Is gradient broken for general vectors ? This could
be a potential problem for other people as well. Or am I doing something
wrong.
System: Irix 6.5 11m x-povray version 3.1g
Thanks,
   Lothar

--
Dr. Lothar Esser
NIH / NCI
Tel. 301-435-6163
email les### [at] helixnihgov


Post a reply to this message

From: Trevor Quayle
Subject: Re: gradient question
Date: 19 Sep 2001 14:18:37
Message: <3ba8e17d$1@news.povray.org>
I think the gradient vector gets normalized, it is only used as a direction,
not a scale.
You should therefore, add a scale statement (and probably translate the
pattern to the base of the cylinder)

cylinder {
  <-1,-1,0>, <1,1,0>, 0.2
  texture {
    pigment {
      gradient
      (<1,1,0>-<-1,-1,0>)
      color_map {
        [ 0.0 color rgb 1]
        [1.0 color rgb <0,0,1>]
      }
      scale vlength(<1,1,0>-<-1,-1,0>)
      translate <-1,-1,0>
    }
  }
}


-tgq


--
camera{location z*13look_at 0}light_source{15 15looks_like{sphere{0 10
}pigment{rgb 1}finish{ambient 15}}}union{torus{3,0.5rotate x*90}cone{y
*4,.5,-y*8,0}cone{-x*4,.5,x*8,0}pigment{rgb<.7,.6,.4>}finish{ambient 0
diffuse 0reflection{1fresnel on metallic 1}}interior{ior 25}rotate 15}
plane{y,-7pigment{checker rgb 0rgb 1scale 4}finish{diffuse.1}}//   TGQ


Post a reply to this message

From: Lothar Esser
Subject: Re: gradient question
Date: 19 Sep 2001 14:45:43
Message: <3BA8E804.27D68319@helix.nih.gov>
Trevor Quayle wrote:

> I think the gradient vector gets normalized, it is only used as a direction,
> not a scale.
> You should therefore, add a scale statement (and probably translate the
> pattern to the base of the cylinder)

   Yes. This is alright. I scaled and translated it. This example works, there
may however be a problem with scale also. What does not work is any non-trivial
vector. If scale and translate is not right, one should at least see that the
pattern being permendicular to the axis of the cylinder. However this is not
the case.
Try

  camera {
    right x
    up y
    location <0,0,-3>
    look_at < 0,0,0>
  }
  light_source {
    <0,100,-10>
    color rgb <1,1,1>
  }
  background {color rgb 1}

  cylinder {

    <-0.1,-1,0>, <0.1,1,0>, 0.2

    texture {
      pigment {
        gradient <0.2,2,0>
        color_map {
           [ 0.0  color rgb <1, 1, 1> ]
           [ 0.5  color rgb <1, 0, 0> ]
           [ 1.0  color rgb <0, 0, 1> ]
        }
      }
    //  scale 4
    //  translate <-0.1,-1,0>
      finish {
        ambient 0.8
        diffuse 0.5
        specular 0.1
        roughness 0.01
      }
    }
 }


Post a reply to this message

From: Trevor Quayle
Subject: Re: gradient question
Date: 19 Sep 2001 14:57:16
Message: <3ba8ea8c$1@news.povray.org>
The gradient should be perpendicular to the axis, I think what you are
seeing is an effect of perspective view and your aspect ratio. your aspect
ratio is 1:1, is your output image 1:1?


try this camera instead

camera {
  up y
  right x*image_width/image_height
  location <0,0,-3>
  look_at < 0,0,0>
}

it makes the aspect ratio of your camera and output image
(I think this is for 3.5 only though, if using 3.1 replace terms
"image_width" and "image_height" with the width and height of your image in
pixels)

-tgq


--
camera{location z*13look_at 0}light_source{15 15looks_like{sphere{0 10
}pigment{rgb 1}finish{ambient 15}}}union{torus{3,0.5rotate x*90}cone{y
*4,.5,-y*8,0}cone{-x*4,.5,x*8,0}pigment{rgb<.7,.6,.4>}finish{ambient 0
diffuse 0reflection{1fresnel on metallic 1}}interior{ior 25}rotate 15}
plane{y,-7pigment{checker rgb 0rgb 1scale 4}finish{diffuse.1}}//   TGQ


Post a reply to this message

From: Lothar Esser
Subject: Re: gradient question
Date: 19 Sep 2001 15:24:27
Message: <3BA8F118.538A3034@helix.nih.gov>
Trevor Quayle wrote:

> The gradient should be perpendicular to the axis, I think what you are
> seeing is an effect of perspective view and your aspect ratio. your aspect
> ratio is 1:1, is your output image 1:1?
>
> try this camera instead
>
> camera {
>   up y
>   right x*image_width/image_height
>   location <0,0,-3>
>   look_at < 0,0,0>
> }

Image_width = Image_height in my case. Try to run the example and plug in
different gradients with "odd" values: In my hand they look all *exactly* the
same until you use gradient x or x+y or something simple like this. Unless I
really do something stupid this looks to me like a real bug.
LE.


Post a reply to this message

From: Trevor Quayle
Subject: Re: gradient question
Date: 19 Sep 2001 15:38:47
Message: <3ba8f447$1@news.povray.org>
I'm not sure what you see as the problem

if you use gradient x the gradient is perpendicular to the x-axis, the color
map runs from 0 to 1 and then repeats (without scaling)

'x' is an internal operator which expands to <1,0,0>

using x+y gets you <1,0,0>+<0,1,0> = <1,1,0>
here the gradient would run in this direction, the color map would start at
the origin and run to distance of 1 in the <1,1,0> direction.

any vector that you put in for the orientation of the gradient represents
the direction of the gradient pattern.  The color_map will always run from 0
to a distance of 1 no matter how large the vector is. for <1,1,0> the color
map runs in the <1,1,0> direction but repeats at  the point <0.707,0.707,0>
(the length of this is 1) and so on.

-tgq



--
camera{location z*13look_at 0}light_source{15 15looks_like{sphere{0 10
}pigment{rgb 1}finish{ambient 15}}}union{torus{3,0.5rotate x*90}cone{y
*4,.5,-y*8,0}cone{-x*4,.5,x*8,0}pigment{rgb<.7,.6,.4>}finish{ambient 0
diffuse 0reflection{1fresnel on metallic 1}}interior{ior 25}rotate 15}
plane{y,-7pigment{checker rgb 0rgb 1scale 4}finish{diffuse.1}}//   TGQ


Post a reply to this message

From: Lothar Esser
Subject: Re: gradient question
Date: 19 Sep 2001 15:56:38
Message: <3BA8F8A3.1E33AF8B@helix.nih.gov>
Trevor Quayle wrote:

> I'm not sure what you see as the problem
>

I don't seem to be able to make myself clear:
My observation is that gradient apparently does not work at least in the way I
use it. It appears to be working for
gradients x and y and so on but not when the gradient is < 0.1, 1, 0 > . I
cannot tell for sure what happens but a
cylinder with the ends <-0.1,-1,0>, <0.1,1,0> does not get colored correctly
with such a gradient. Apart from scaling and translation effects, the pattern
should at least run perpendicular to the axis. More surprising is the fact that
no matter what I put in for a gradient vector it does not change the pattern.
Again simple things seem to work.
Maybe I put it into a challenge: I give you two points which represent the end
points of a cylinder and I ask you to
color it with a gradient going from say with at point 1 to blue at point 2.
Would you use something like this : ?
#declare p1 = <-0.1,-1,0>
#decalre p2 = <0.1,1,0>
cylinder { p1, p2, 0.2  texture { pigment { gradient (p2-p1) color_map { [][] }
} scale vlength ( p2-p1 ) translate p1 finish{} } }

Not having tried this exact scheme yet I predict that it works if p2-p1 = x or
y or x+y  etc. but not if it is anything else.
BTW I am not so sure about the scale. I have had some problems with it too. For
instance a cylinder of length 2.84 needed to
get a scale of 4. But lets deal with one problem at a time.

LE.


Post a reply to this message

From: Trevor Quayle
Subject: Re: gradient question
Date: 19 Sep 2001 16:12:29
Message: <3ba8fc2d$1@news.povray.org>
I used your code and modified it slightly to run a whole bunch of cylinders
with random endpoints.  I'll post my image in p.b.i for you.  If you can see
your problem with it maybe can can explain it a bit more carefully.  (BTW
the speckles on the ends of the cylinder come from the gradient having
coincident surfaces where it is repeating, multiply the scale factor by
something miniscule like 1.00001 to get rid of it)

code used:

camera {
  up y
  right x*image_width/image_height
  location <0,0,-10>
  look_at < 0,0,0>
}

light_source {
  <0,100,-10>
  color rgb <1,1,1>
}

background {color rgb 1}


#declare R1=seed(1);

#declare i = -5;
#while (i<=5)
  #declare j = -3;
  #while (j<=3)
    #declare p1 = <-1*rand(R1),-1*rand(R1),-1*rand(R1)>*5*(rand(R1)-0.5);
    #declare p2 = <1*rand(R1),1*rand(R1),1*rand(R1)>*5*(rand(R1)-0.5);
    cylinder{
      p1, p2, 0.2
      texture{
        pigment{
          gradient (p2-p1)
          color_map{
             [0.0 color rgb <1, 0, 0>]
             [1.0 color rgb <0, 0, 1>]
          }
        }
        scale vlength(p2-p1)
        translate p1
        finish {
          ambient 0.8
          diffuse 0.5
          specular 0.1
          roughness 0.01
        }
      }
      translate x*i+y*j
    }
    #declare j=j+1;
  #end
  #declare i=i+1;
#end


-tgq


Post a reply to this message

From: Lothar Esser
Subject: Re: gradient question
Date: 19 Sep 2001 17:43:33
Message: <3BA911B3.4D04232E@helix.nih.gov>
Trevor Quayle wrote:

> I used your code and modified it slightly to run a whole bunch of cylinders
> with random endpoints.  I'll post my image in p.b.i for you.  If you can see
> your problem with it maybe can can explain it a bit more carefully.  (BTW
> the speckles on the ends of the cylinder come from the gradient having
> coincident surfaces where it is repeating, multiply the scale factor by
> something miniscule like 1.00001 to get rid of it)

I posted my reply also on the povray binary images server.
Seems like I have a problem. I am running it on an sgi. At the moment I don't
very much feel like trying different compiler options but I will have to do
that I am afraid because this is not working.

LE


Post a reply to this message

From: Lothar Esser
Subject: Re: gradient question
Date: 19 Sep 2001 17:52:02
Message: <3BA913AF.F7223ACB@helix.nih.gov>
>

Now I ran the same script on Compaq Alpha with exactly the same wrong result.
Can you give me more details about your system ?
What is wrong with unix (?) if I may generalize here a bit ?
I am a bit puzzled right now.

LE


Post a reply to this message

Goto Latest 10 Messages Next 2 Messages >>>

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