4 corner gradient
mhopf at suse.de
Tue Jul 3 10:13:38 PDT 2007
On Jun 28, 07 10:46:29 -0700, Allen Akin wrote:
> | >> Using the i915 I try to create a 4 corner gradient rectangle using 2 3D
> | >> primitive triangles. I get a visible diagonal line between the two
> | >> triangles ...
> | >
> | > Gouraud shading uses linear interpolation. Essentially, each of the
> | > two triangles will be mapped to a planar (flat) triangle in RGB space.
> | > As the 4 vertices (red, green, blue, white) aren't co-planar, there
> | > will be a discontinuity (corner) along the diagonal where the two
> | > triangles meet.
> | >
> | > OTOH, bilinear interpolation between the vertices will produce a
> | > continuous surface (specifically, a ruled surface) with no
> | > discontinuities.
> | >
> | > AFAIK, you cannot achieve bilinear interpolation using OpenGL
> | > primitives...
> I have a vague recollection that you can do this in old-style OpenGL
> using texture mapping, but I can't find sample code at the moment.
It's pretty trivial. Allocate a 2x2 texture (or larger, if 2x2 is too
small to be supported) and set texture coordinates to hit the center of
the texels at the 4 vertices (That is 0.25 and 0.75, respectively). Set
up the texture to contain the 4 colors you want to interpolate between.
Enable texturing, modulate with GL_REPLACE, and you're done.
> | You could do it pretty simply with a pixel shader.
> Yep, that would be the way to go with current hardware.
In this case I don't see any advantage to using textures.
Matthias Hopf <mhopf at suse.de> __ __ __
Maxfeldstr. 5 / 90409 Nuernberg (_ | | (_ |__ mat at mshopf.de
Phone +49-911-74053-715 __) |_| __) |__ R & D www.mshopf.de
More information about the xorg