11 Replies Latest reply on May 19, 2006 2:32 PM by Newsgroup_User

    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/
        • 1. Re: shading a triangle (3-vertex gradient)
          Rothrock Level 5
          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.

          • 2. Re: shading a triangle (3-vertex gradient)
            heilong Level 1
            Thanks for your reply.
            Where should I post it, then?

            You got it right, it's either good+not fast or fast+not perfect.
            Well, flash has got that reputation and obviously it's not into anything calculations-heavy, but at this point it can handle a hundred or two triangles with 25 frames per second (on my machine, which is not the fastest nor the slowest). I want to create rather simple 3d stuff right now, and flash has got enough speed for that. If I can solve this riddle, that is. Or I'll have to content to just satisfactory shading quality.
            • 3. Re: shading a triangle (3-vertex gradient)
              Rothrock Level 5
              There may well be better forums on the web with regard to implementing such things – but I don't know them, sorry. However in general I would think what I'm talking about would be good etiquette for any site.

              If you aren't getting an answer don't just keep reposting the exact same message over and over. Update the same thread with a follow up of other ways you have approached the problem or something else you have learned in the interim.

              Additionally, you haven't really asked a question. Open-ended comments like yours are always less likely to be answered. Its kind of like making people figure out what kind of help you need and then supply it. Specifics provide a "way in" as it were.

              In this day and age I don't think too many people would be willing to risk downloading files from a stranger. So instead of posting a link to a directory with your entire project, break out the parts of the code that you need specific help or comment on.

              Finally, I think you probably really do have the solution in your own hand. It is very common with Flash that you have to balance performance with what you want. It is really finding that balance for the tradeoff.
              • 4. Re: shading a triangle (3-vertex gradient)
                blemmo Level 1
                There's a blog dealing with 3D in Flash: http://sandy.media-box.net/blog/
                There's also a library available there, maybe this could be of some use, although the creators state that it's not very useful before AS 3 comes out.

                • 5. Re: shading a triangle (3-vertex gradient)
                  heilong Level 1
                  blemmo, didn't find anything pertaining to shading there (.
                  Rothrock, I'll try to be more polite. I didn't know fla or swf files can be dangerous (e.g., contain viruses). In fact, I doubt it. I posted a link to a little test I made specifically for the matter, not an entire project (don't have any project on this yet ). I understand about balancing performance/quality, but it's sometimes possible to just find another way, another algorithm. I still wonder if it could be done with overlapping several gradients.
                  • 6. Re: shading a triangle (3-vertex gradient)
                    Level 7
                    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.

                    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%_@``

                    • 7. Re: shading a triangle (3-vertex gradient)
                      Rothrock Level 5
                      The danger is probably small IF they really are swf and fla files. Of course a zipped (or other technology) file is a whole other kettle of fish. And it isn't just the risk of viruses/trojans/etc. It is also just a hassle to have to download something figure it out and work through it. (Not that folks won't, but they are less likely.) Sorry if I seemed harsh. Nothing you did was wrong. I was just trying to give you some tips on how to get responses if original posts go unanswered. Basically, if that doesn't work try something else.

                      Jeckyl where is this file? I would like to see what this is all about. (PS: I would download a file from Jeckyl since he has been around here for so very, very long. And a few more posts from heilong and I would download from you too!)
                      • 8. Re: shading a triangle (3-vertex gradient)
                        Level 7
                        The attachment shows us if you use a newsreader (I'm using Mozilla
                        Thunderbird). One of many benefits that seem to come with this method
                        of forum use. (It's a very pretty triangle, too.)

                        Rothrock wrote:

                        > Jeckyl where is this file? I would like to see what this is all about.
                        • 9. Re: shading a triangle (3-vertex gradient)
                          heilong Level 1
                          Thanks for help, people, Jeckyl's solution seems to produce what I need. Working on it now... Thanks, Jeckyl. Thanks for tips, Rothrock.

                          ImagicDigital, is this forum somehow connected to Usenet? I use Mozilla myself, but I access this page thru www.adobe.com.
                          • 10. Re: shading a triangle (3-vertex gradient)
                            Rothrock Level 5
                            Cool. Now post back with some pretty thing you made using this technique. I want to see it in action!

                            ImagicDigital well you can't see things in square brackets! [Unless they fixed that.] I just never got the hang of using the newsreaders. The web forum is so much nicer for me.
                            • 11. Re: shading a triangle (3-vertex gradient)
                              Level 7
                              Yes, the forums are "replicated" to Usenet... Add a new account, choose
                              "newsgroup account", enter any name and email address you want, and put
                              "forums.macromedia.com" as the newsgroup server. You can then subscribe
                              to many of the different support forums that exist on Adobe.com.

                              It's described here:


                              Rothrock -- You're right Square brackets seem to work sometimes now
                              -- more than before. But not always. Can't remember exactly what
                              Jeckyl's testing found out about the ins and outs of that bug. Pros and
                              cons to both viewing methods. To each their own!

                              heilong wrote:
                              > ImagicDigital, is this forum somehow connected to Usenet? I use Mozilla
                              > myself, but I access this page thru www.adobe.com.