[cairo] Radial shader transformation

Thomas Hunger info at teh-web.de
Mon Mar 1 15:12:54 PST 2004


> Instead the shader could be transformed by the difference between the space
> it was defined in and the current transform. This is just the inverse of
> the transform matrix when the shader was defined, multiplied by the current
> transform matrix. You could then use rotate and scale to define a tilted
> ellipse transform, and still scale and translate and even rotate as you
> draw your shapes.

Hm. If we'd introduce a gstate->shader_matrix, it could store the current 
tranformation matrix at creation time (1) and then multiply this with the 
gstate->ctm right before passing control points to the actual shader 
function.

cairo_save
  rotate (Pi/2)
 setup_linear_shader ()
cairo_restore
  rotate  (PI/2)
  cairo_rectangle 
  cairo_fill

would rotate the gradient by PI so actually mirroring it. Is that what you 
mean?

So we would have two possibilities:
1) a set_shader() always sets up a normalized shader of "size" == 1.0 so the 
user has to transform it to make it fit to whatever position, size and 
orientation one wants. this has the advantage that the set_shader() functions 
would be simple to call. It has the disadvantage that the user has to have 
implicit knowledge about the shaders definition of normal. i.e. does the 
linear shader cover -0.5 to 0.5 or 0.0 to 1.0, ist it horizontal or vertical 
by default. stuff like that. though I think it would not be a big problem if 
documented.

2) a set_shader() takes shader-specific arguments (probably similar to the 
svg-arguments). It has the disadvantage of a bulky interface. On the positive 
side it is more intuitive since the user can do stuff like
cairo_rectangle (0, 0, w, h);
cairo_set_shader_linear (0, 0, w, 0); 
to make an exactly fitting shader without needing extra transforms.

Both approaches seem ok to me. What do you think? (seems like you like the 
transform approach more, I just wanted to point out the issues I see with it)

Tom

P.S. level set methods look very interesting though the mathematics are too 
hard to grasp for me tonight. How could these be hardware accelerated?





More information about the cairo mailing list