Skip to main content
Participating Frequently
May 17, 2006
Answered

shading a triangle (3-vertex gradient)

I'll ask it quite simple:
There is a triangle movie clip with vertices A (0, 0); B (256, 0); C (0, 256)
Each vertex has some color (e.g., A - red, B - green, C - blue).
I need to shade the entire area of this triangle by interpolating between these 3 colors.
Something like a gradient, but it has 3 vertices, not 2 like a linear one.

I tried two ways:
1) create a 256x256 BitmapData, attach it to my clip and shade the triangle in bitmap,
manually (just like people were programming 3d graphics before opengl&direct3d).
this works, but is very slow (of course).
2) create a 2x2 or 3x3 or some other lilttle square bitmap, shade it then scale it to 256x256
with smoothing option (attachBitmap's argument) enabled. this works quite fast and looks almost
right but not quite right.

I also thought on how to accomplish this with a gradient (maybe several gradients), but no ideas...
You can check out my code at: http://heilong.oceanography.ru/flash/lab/
This topic is closed to new replies. Start a new post to keep the conversation going.
Newsgroup_UserCorrect answer
Inspiring
May 19, 2006
Three overlapping gradient where it goes from solid color at vertex to same
colour with alpha=0 at opposite edge (and fill parallel to opposite edge)
works well.

If attachments work for you, you can see a small SWF that shows this.
--
Jeckyl


begin 666 example-triangle-shading.swf
M0U=3!O,```!XVBM@X$Q@8.AL8.!A9'!F^O__OS4'(T/*`R-6%^T#C *[+JTJ
M?KORM,ZTC"DOF!@8&(#R0(*!D0$$_@OJ-C &RM<\T#Z\<8+LY\9 !H8N-C8F
MH*S4-!8?!C,.)H1!34\KM!2D& A NH%F`$W!9P8S4"'8#&L.9H09.PVN%N6N
<4]::/F7*"B:0$6#7X#6(A8$98I #4 D`PVM%_@``
`
end

11 replies

Inspiring
May 17, 2006
Why do you keep posting exactly the same thing? There really isn't a question in there. Do you actually have a question?

Most people here are looking for help with basic stuff and not really up to Gouraud shading. Especially at a general theory level.

Seems you've got it sown up. 1) good but not fast 2) faster but not quite right.

Flash isn't really for complex rendering and bitmaps. Sure they've added a bitmap class and it does some nice things that were very difficult (and even not possible) before. But it is still quite tied to its past as a platform for delivering small files over the internet.

Translate