|
From: Daniel J S. <dan...@ie...> - 2007-02-04 22:34:05
|
Pierre wrote: > I put a meaningless example here: http://blog.thepimp.net/misc/gdshading/ > > The color stop points are in the comments, it is something like a > range -0.25..1.0 used "black blue red yellow". > > The results has no special value (besides being a nice shading effect > ;), psychedelic > but it may help to see how gdShadedTriangle works and what should > be done to match your needs. I've looked through the code a bit and your examples. (What command does one need to compile this program?) I'd have to think about your approach to be certain about the result. You've broken the thing down into a series of one dimensional linearities, first along the sides of the triangle to get a color, and then across the x dimension to further interpolate between those two. Seems logical, but it may be open for rounding problems. Another thing that makes me wonder a bit (and this may be a visual effect), is that I look at your gouraud3.png example: http://bugs.libgd.org/?getfile=25 and imagine looking at just one of the triangles, with blue in one corner, red in another, green in the third. Somehow it appears that they aren't blending together the way I would think. Would it be possible to generate a fairly big equilateral triangle, say, x0 = 10; y0 = 10; x1 = 310; y1 = 10; x2 = 160; y2 = 270; so that we'd expect a nice symmetrical blending of the components? I'll offer up an alternative construction, not that I'm suggesting a change, but just for the sake of brainstorming. If one thinks in terms of a single color component, it can be imagined as a two dimensional plane in three dimensional space (x and y are two dimensions, c the color a third dimension). Generalizing the z = m x + b idea for a line, we have three points for which we want a plane to pass through. Let w be a two dimensional vector, b a constant. Color is then c = w' * [x y]' + b i.e., if we know w and b, we can find any color value on that plane from the above formula. Given triplets (x_1, y_1, c_1), (x_2, y_2, c_2), (x_3, y_3, c_3), define matrix: A = | x_1 y_1 1 | | x_2 y_2 1 | | x_3 y_3 1 | and vector c = [c_1 c_2 c_3]' and vector d = [w b]'. Then A d = c and solving for d gives d = inv(A) c I wrote a 3D inverse routine the other day. Ultimately, this approach wouldn't mean much less code because of the inversion, but its advantage might be a little more precision, not sure. Anyway, I'd be interested in the equilateral "color triangle". Dan |