[cairo] Fwd: Re: [Mesa3d-dev] more glitz points
brian.paul at tungstengraphics.com
Wed Apr 21 14:44:40 PDT 2004
David Reveman wrote:
> On Wed, 2004-04-21 at 12:25 -0600, Brian Paul wrote:
>>David Reveman wrote:
>>>On Wed, 2004-04-21 at 09:33 -0700, Jon Smirl wrote:
>>>>--- Brian Paul <brian.paul at tungstengraphics.com> wrote:
>>>>>> Most programmatic surfaces are implemented using fragment programs and
>>>>>> they will only be available on hardware supporting the fragment program
>>>>>You certainly don't need fragment programs to do color gradients like
>>>>>those. At worst, you have to just compute per-vertex texcoords to do
>>>>>radial gradients. You can use texgen for texcoords for linear
>>>>>gradients. I've done both in past projects (long before fragment
>>>You're probably right, and I'd love if someone would contribute with
>>>some code that could do this. Although I think it might be hard make it
>>>work with glitz's rendering model (the xrender model). It might also be
>>>hard to make it support the different spread types; pad, repeat and
>>Pad, repeat and reflect sound like OpenGL's GL_CLAMP, GL_REPEAT and
>>GL_MIRRORED_REPEAT texture wrap modes.
> This is actually what I'm using with the current version of glitz. I
> calculate a gradient offset value in the fragment program, then use it
> to fetch a pixel from a 1D texture with one of the above mentioned
> texture wrap modes.
>>I could probably whip up a GLUT demo showing various kinds of gradient
>>rendering. Would that help?
> That would be great. I hope that's not to much trouble for you. This way
> I could easily see how it would be possible to improve glitz's gradient
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
The second program demos 2D texture gradients and otherwise works the
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
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 2380 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20040421/36fbbdfc/gradients.tar.tar
More information about the cairo