4 corner gradient

Glynn Clements glynn at gclements.plus.com
Thu Jun 28 03:03:26 PDT 2007


Tom De Man wrote:

> This might be slightly off topic but I can't resist asking the experts
> here:
> 
> 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 (which is ugly). If I use software routines to make a gradient
> rectangle it looks good.
> I've tested making the rectangle with 4 triangles (all to the center), but
> I get a cross then (although less visible).
> 
> Is this something due to how triangles are colored, due to some 3D param
> or is it inevitable ?

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, although you may be able to get an adequate approximation
by using a sampled Bézier patch (glMap2, glEvalMesh2, etc).

-- 
Glynn Clements <glynn at gclements.plus.com>



More information about the xorg mailing list