[cairo] Fwd: Re: [Mesa3d-dev] more glitz points

Brian Paul brian.paul at tungstengraphics.com
Thu Apr 22 08:54:26 PDT 2004


David Reveman wrote:
> On Wed, 2004-04-21 at 15:44 -0600, Brian Paul wrote: 
> 
>>OK, I've whipped up some test programs (attached).
>>
>>The first demos 1D texture gradients.  Press 'g' to toggle between 
>>linear and radial gradients.  Press 'w' to change the texwrap mode 
>>between clamp and repeat.  Use the mouse to drag the object around the 
>>window.
>>
>>The second program demos 2D texture gradients and otherwise works the 
>>same way.
>>
>>I learned something in the process.
>>
>>To do a radial gradient with a 1D texture, I basically wrote my own 
>>glTexCoord() function (see MyTexgen()) which computes a 1D texture 
>>coordinate as a function of the (x,y) distance from the center of the 
>>window.  The results are quite terrible.  The reason is texcoord 
>>interpolation across the triangles is done linearly, while the radial 
>>gradient function is not linear in x,y.  The result is distortion in 
>>the application of the gradient.  It's easy to see when you drag the 
>>object around.  When the wrap mode is repeat, it's especially bad 
>>where the texcoord wraps around.
>>
>>Moral of the story: if the gradient is not linear w.r.t the x/y 
>>position, you need to use a 2D texture map.
>>
>>In my past project, I always used a 2D texture for the gradients so I 
>>never noticed the issue with 1D textures before.
>>
>>Of course, a fragment program would let you compute an arbitrary 
>>gradient function without the distortion issue since it would be 
>>evaluated per-pixel.
> 
> 
> Thanks for the examples Brian!
> Maybe they can help me write some better gradient code for glitz.

Just remember that my demos are just that.  I'm making GL API calls 
more frequently than necessary, for example.


> The linear gradients in your examples seems to be working the way I want
> them to, so I might be able do something similar for linear gradients in
> glitz.
> 
> Repeat of radial gradients in your examples is not working the way I'd
> like but that's probably possible to fix. However, I think it's going to
> be hard to not use fragment programs for radial gradients. You see, the
> radial gradients should really be elliptic gradients and represented
> with conic matrices. This makes it easy to manipulated the ellipses with
> transformation matrices (possible to do rotated elliptic gradients...). 

I believe the rotation and elliptical variations can be implemented 
with a texture matrix.  The texture matrix is applied after texgen.


> I also like the radial gradients to contain two ellipses, one inner
> ellipse and one outer ellipse, the gradient transition vector will be
> from the radius of the inner ellipse to the radius of the outer.

I'm not sure about that part.


> Here's a screenshot from a glitz application that uses an elliptic
> gradient with reflecting repeat. This might help you understand how I
> want repeat of radial gradients to work.
> http://www.cs.umu.se/~c99drn/pics/radial-grad.png

I'm confident that the gradient in that image could be produced with a 
2D texture, texgen and texture matrix.

-Brian





More information about the cairo mailing list