Announcement

Collapse
No announcement yet.

Tips&Tricks in AVS

Collapse
This is a sticky topic.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #31
    Here's the engine I created for Matrix_Reality.

    Dynamic Movement:
    Init
    code:

    js=.002;pi=acos(-1);pitch=0;yaw=0;density=.33;

    Frame
    code:

    j=if(above(j,1),-1+js*2,j+js);

    ox=cos(j*pi)*.125;oy=sin(j*pi)*.5;oz=j*3.5;

    ys=yaw;yaw=cos(j*pi)*.125;
    roll=(roll*5-ys*5)*.0125;pitch=sin(j*pi)*.125;
    pitch=if(above(abs(pitch),.5),sign(pitch)*.5,pitch);
    cy=cos(yaw*pi);cx=cos(pitch*pi);cz=cos(roll*pi);
    sy=sin(yaw*pi);sx=sin(pitch*pi);sz=sin(roll*pi);

    Point
    code:

    dx=x;dy=y;dz=1;

    tx=dx*cy-dz*sy;tz=dz*cy+dx*sy;
    ty=dy*cx-tz*sx;dz=tz*cx+dy*sx;
    dx=tx*cz-ty*sz;dy=ty*cz+tx*sz;

    kx=if(above(dx,0),abs((ox-1)/dx),abs((ox+1)/dx));
    ky=if(above(dy,0),abs((oy-1)/dy),abs((oy+1)/dy));
    kz=if(above(dz,0),abs((oz-4)/dz),abs((oz+4)/dz));

    k=min(min(kx,ky),kz);

    utx=oz+dz*kx;uty=oy+dy*kx;utz=ox+dx*kx;
    vtx=ox+dx*ky;vty=oz+dz*ky;vtz=oy+dy*ky;
    wtx=ox+dx*kz;wty=oy+dy*kz;wtz=oz+dz*kz;

    x=if(equal(k,kz),wtx,if(equal(k,kx),utx,vtx));
    y=if(equal(k,kz),wty,if(equal(k,kx),uty,-vty));

    alpha=(1/pow(2.71828,sqr(k*density)))*(1-abs(pow(j,5)));

    Blend:On | Bilinear:On | Wrap:On | RectCoord:On

    ----------------

    Superscope.
    Init
    code:

    n=200;js=.002;pi=acos(-1);pitch=0;yaw=0;density=.33;bp=.5;

    Frame
    code:

    bp=if(above(bp,-4),bp+.1,if(above(getspec(.1,.1,0),.25),-3.9,bp));bp=if(above(bp,8),-4,bp);
    by=if(above(bp,4),by*1.1,.05);
    ox=cos(j*pi)*.125;
    oy=sin(j*pi)*.5;
    oz=j*3.5;
    sy=sin(-yaw*pi);
    sx=sin(-pitch*pi);
    sz=sin(-roll*pi);
    cy=cos(-yaw*pi);
    cx=cos(-pitch*pi);
    cz=cos(-roll*pi);
    pitch=if(above(abs(pitch),.5),sign(pitch)*.5,pitch);
    roll=(roll*5-ys*5)*.0125;
    pitch=sin(j*pi)*.125;
    ys=yaw;yaw=cos(j*pi)*.125;
    j=if(above(j,1),-1+js*2,j+js);

    Point
    code:

    dx=cos(i*pi*20)*.01-ox;
    dy=sin(i*pi*20)*.01-oy+by-.05;
    dz=i*.05-oz+if(above(bp,4),4,3+(1-pow(1-(bp+4)*.125,3)*8))*.35;
    tx=dx*cz-dy*sz;ty=dy*cz+dx*sz;
    dy=ty*cx-dz*sx;tz=dz*cx+ty*sx;
    dx=tx*cy-tz*sy;dz=tz*cy+tx*sy;
    a=if(above(bp,-4),(1/pow(2.71828,sqr(dz*density))),0);
    red=if(below(dz,.1),0,1)*a;
    green=red;
    blue=0;
    k=1/if(equal(dz,0),1,dz);
    x=dx*k;y=dy*k;

    Draw: Lines
    -------------------

    The above is the room and a bullet from my Matrix_Reality preset. Here is a basic description of variables:
    • ox,oy,oz = Camera Position
    • pitch,roll,yaw = Camera Rotation Angles
    • density = Fog Density (Exponential Squared)
    • j = Synchronization Variable (js = timing speed)

    It limits the pitch to +/-.5 (Vertical) so there aren't any gimble situations, and automatic roll is created for changes in yaw.
    Attached Files
    1 | 2 | 3 | 4 | 3W | 4WW

    Comment


    • #32
      If you want to post long pieces of code, use <font=courier>...</font> (replace <> with square brackets) to prevent from stretching the page.

      Comment


      • #33
        Don't forget your manners, UnConeD

        PLEASE USE COURIER!!!
        "guilt is the cause of more disauders
        than history's most obscene marorders" --E. E. Cummings

        Comment


        • #34
          No tug, you got me wrong. I'm not saying that every tip in this thread are total bullshit, but what I am saying is that this thread shouldn't be filled with codes / tips (and posts like this ) that doesn't affect to fps rate "efficiently" . I tried some of these and I really couldn't see any fps difference between code A and code B. If some method saves alot fps compared to the others, yeah it's good to be mentioned, but if it saves only like 0.1 fps you think that this thread should be filled with codes/tips like these ?? :P

          And what comes to my presets. Usually the use of complex colors makes the preset slow. And colors aren't just that easy to optimize. Of course I always try to erase things you don't necessarily need & try to make it as fast as possible, but sometimes you just can't make it any faster without radical changes. Sure I can replace all those tricky colors with a Utone or two for some real boost up, but that's just not me....

          Comment


          • #35
            Okay, just a tip...as long as we're on this page of
            the thread, try just typing in your carriage returns
            like this...

            Anyway, just one thing to remember as AVSers: Any god
            damned thing is possible in AVS once you put your
            mind to it. Trust me, if I didn't keep telling
            myself this, I wouldn't be doing any of what I've
            been doing (i.e. 4D, life algorithms, etc.) I'd bet
            money that Jheriko's been having to reasure himself
            of this a lot for some of his scopes lately My
            point is, you shouldn't just give up because you think
            it can't be done. That's not a good reason. Give up
            because you're lazy, or because you need to clip your
            toenails, or for something important like that.
            "guilt is the cause of more disauders
            than history's most obscene marorders" --E. E. Cummings

            Comment


            • #36
              Here's a simple one that I'm sue everyone here knows. Might help a
              noob though. (that is kinda what this thread was intended to do, right?)

              sin, cos, and tan are all calculated from the radian value.
              This means the wavs have a period of 2*PI.

              sin(3.141) = sin(3.141) = sin(6.282) = 0
              sin (3.141/2) = 1
              sin (3.141*3/2) = -1
              Stoke me a clipper. I'll be back for Christmas.

              - Arnold Rimmer
              Red Dwarf

              Comment


              • #37
                Originally posted by Atero
                I'd bet money that Jheriko's been having
                to reasure himself of this a lot for some
                of his scopes lately
                That is true.

                I still have ideas that I'm forcing myself
                into doing right now, the coolest AVS i've
                made haven't been released yet because they
                don't work properly, but like atero said,
                anything is possible so I never give up on
                them, I just keep working on them in the
                background. Like that sonic battlefield from
                pack VI, I'm still working on that on and off.

                The point is never to give up, force yourself
                through to the end. Thats more general life
                advice though.


                Here is something more useful though; I'm certain
                that a lot of you out there know exactly what you
                want to do in AVS but have no idea about what
                sort of maths you need to do it. I'm also certain
                that there are a lot of mathematical methods
                that would be useful for AVS if we knew about them.
                Personally I think that maths is pretty important
                for AVS (the technical side at least) so if you
                have any maths questions my tip would be to check
                this cool page that I found, or alternatively send
                me some mail. I'm not going to pretend to know
                everything about maths but I have a lot of knowledge
                and a lot of textbooks too.

                [email protected]

                EDIT: Here are some trig identities to add to Jaheckelsafar's list, these will probably all have some applications in AVS, don't ask me what though:

                code:


                cos(pi/4) = sin(pi/4) = 1/sqrt(2)
                cos(pi/6) = sin(pi/3) = sqrt(3)/2
                cos(pi/3) = sin(pi/6) = 1/2

                (sin(x))^2+(cos(x))^2 = 1
                cos(x) = sin(x+pi/2)
                cos(-x) = cos(x)
                sin(-x) = -sin(x)
                tan(x) = sin(x)/cos(x)
                cot(x) = 1/tan(x) = cos(x)/sin(x)
                sec(x) = 1/cos(x)
                csc(x) = 1/sin(x)

                sin(x+y) = cos(x)sin(y)+sin(x)cos(y)
                sin(x-y) = cos(x)sin(y)-sin(x)cos(y)
                cos(x+y) = cos(x)cos(y)-sin(x)sin(y)
                cos(x-y) = cos(x)cos(y)+sin(x)sin(y)
                sin(2x) = 2sin(x)cos(x)
                cos(2x) = 2(cos(x))^2-1
                cos(2x) = 1-2(sin(x))^2
                cos(3x) = 4(cos(x))^3-3cos(x)
                sin(3x) = 3sin(x)-4(sin(x))^3


                There are a ton more things like this, identities
                for cos(ax) and sin(ax) for instance, but I can't
                remember them all off of the top of my head.
                Last edited by jheriko; 2 December 2002, 20:44.
                -- Jheriko

                'Everything around us can be represented and understood through numbers'

                Comment


                • #38
                  Damn...NOW I know why my trig teacher wanted me to memorize identities. She didn't show me the USEFUL ones.....
                  "guilt is the cause of more disauders
                  than history's most obscene marorders" --E. E. Cummings

                  Comment


                  • #39
                    Hey there,

                    I was wanting to ask, (I've spent the last week going throught the forums) If some one could give me a running example purley for reference how to create a plane in 3D SSC and effect it with this function

                    z=x*e^(-x^2-y^2)

                    I use a 3d ploting program that I'm used to and enter this

                    plot3d(x*exp(-x^2-y^2), x=-2..2 y=-2..2)

                    works fine .. You should see the triped stuff I'm getting "TRYING to emulate this to AVS.. I've totaly forgot how to rearange the "e" with log and I got paper and shit all over my desk and room. ahhhhhhhhh where's my text books... I'm also giving up smoking 3 days now.

                    z being the third axis of course, e is the exponent and ^ is to the power. Because I'm used to this program alot I tend to have blunders converting to AVS. Gimme a couple of weeks tho no probs but hey I'm always looking to learn quicker from some experienced bruzza'z.

                    If anyone feeling Crwayzie mabey give z=cos(x)*sin(y) a try and show us. I feel that if I see an example of something I've done I might be able to bridge the gap faster.



                    P.s. I's it just me or does anyone here alos go to sleep and end up dreaming about Freakin' equation's accompanied by some major tripped lighting visual dreams.... waaaaaaah. sheeesh If only I could remember what code I was dreaming I might be able to pull something awsome out of my subconcious ... I guess the best thing to say here is ...

                    Keep Dreaming

                    Rez---pec-t..

                    The VIzAG

                    Comment


                    • #40
                      here's an idea: do your own work instead of expecting us to do it for you.
                      "guilt is the cause of more disauders
                      than history's most obscene marorders" --E. E. Cummings

                      Comment


                      • #41
                        Cant say I actually expected that !

                        Comment


                        • #42
                          Atero: if you don't have anything constructive to add to someone's question, shut up please.

                          VisualAgnosia: the superscope is just a drawing tool... you give it (x,y) coordinates on the screen with a color if you wish.

                          So if you want to plot a graph of a function z=f(x,y), you'll first need to write code that traverses a grid of points in 2D rectangle, then calculates the z value for that point and then transforms the point with perspective.

                          The best way to do this is not to use the 'i' counter in the superscope, but make your own counters. For example, this draws a simple 20x20 grid:


                          init:
                          n=400;

                          per frame:
                          t=t-.05;px=0;py=0;ct=cos(t);st=sin(t);

                          per point:
                          gx=(px/19)*2-1; gy=(py/19)*2-1;
                          gz=-exp(-(sqr(gx)+sqr(gy))*4)*3+1.6;
                          x1=gx*ct-gy*st;y1=gx*st+gy*ct;
                          x=x1/(y1+3);y=gz/(y1+3);
                          px=if(below(px,19),px+1,0);
                          py=if(equal(px,0),py+1,py);
                          red=if(equal(px,1),0,1);green=red;blue=red;


                          There's a lot going on here, so I'll dissect it:

                          First, we have 400 points on our grid, so we set n to 400.
                          We'll be rotating the grid around, and we'll use 't' as the angle, which is decreased every frame by 0.05 radians. We also calculate the cosine and sine of the angle in the frame routine so we don't have to calculate it again every point, for speed reasons.
                          We'll be traversing a 20x20 grid, and we'll store the current grid point in (px,py). px and py will take on the values 0-19 (20 points), first x then y. We start at (0,0).

                          Per point, we transform (px,py) (between (0,0) and (19,19)) into (gx,gy) a point between (-1,-1) and (1,1). This is done by dividing by 19, multiplying by 2 and subtracting 1 (this piece can be done faster if we merge everything into one multiplication + add/sub, but this is easier to understand):
                          code:

                          /19 *2 -1
                          0..19 -> 0..1 -> 0..2 -> -1..1

                          Next, we calculate 'gz' based on gx and gy. I use exp(-(sqr(gx)+sqr(gy))) which is an exponential 'hump' the shape of the normal gaussian distribution. We multiply it by 3 and add 1.6 to make it fit in the AVS window.

                          Next we rotate (gx,gy) by t radians, so that we get the point (x1,y1). We now use x1 as the x-coordinate, gz as the y-coordinate (z points up) and y1 as the depth coordinate (y points into the screen). We transform it into perspective by dividing (x,y) by z (plus a camera offset of 3).

                          Now all we need to do is make sure (px,py) traverse the values 0-19. First, we check per point if px is smaller than 19: if so, we add 1. If px equals 19, we reset it back to zero. If px equals zero, we increase py by 1.
                          This has the effect of traversion one row on the grid, and when we reach the end, we go to the next row and start over.
                          code:

                          0 1 2 3 4 5 18 19
                          . . . . . . ..... . . |
                          . . . . . . ..... . . |
                          ----------> \|/
                          v

                          And finally there's a little extra: AVS draws the superscope as one chain of line segments. This means that there will be a connecting line between the different rows, which is not what we want. So, we set the color to black for that certain line segment, and white for all the rest: if you use additive or maximum blending, the black lines won't show up.

                          Tadaa... you now have a rotating plot.
                          You could duplicate the scope and reverse the meaning of gx and gy in the second copy, that way you get a grid of lines. Make sure you reload the preset to synchronize the two scopes... (result is attached)

                          So you see if you want to plot a graph, you have to do *everything* yourself.
                          Attached Files

                          Comment


                          • #43
                            Awsome

                            Well I didn't expect that either ...

                            Thats quite a conecise explantation, Totaly get it..mind you I'm gonna print it out and study it like I have with 10 or so other wicked posts I've found. I'm getting a bit of a progression thing happening... from a couple days ago I'm getting more and more things undercontrol... still a long way to go. As it goes it's just a matter of sticking with it and "Dreaming new ideas"

                            A bit of props for AVS

                            --- Studing maths.. which I find interesting usually.. To use something with a straight away effect on visuals in such a dynamic flow of colour and music... Somehow's effected the time I spend studying by three fold --- weird???

                            Thanks for the effort again UnConeD.
                            you've helped yet ANOTHER potential AVSer bridge another gap


                            A note to other neewuubies like me have a look the load example superscopes, the code in there will give some indication as to the layout of the code. B4 you wrote this last post UnConeD I was resorting to the 3D layout they had going on in there.

                            Peace

                            VIsAG

                            Comment


                            • #44
                              Tips and Tricks 2

                              Tuggummi started the first one, but that was long ago. I am sure there will be many new tricks (and Tips).
                              Just post them here,
                              Here's one:

                              when the amount of ssc's is quite large then cramp all of these into one.:
                              eg:

                              code:
                              init:
                              n=1000;a1=1/(499-1);vrem=n/10;pi=acos(-1);tpi=acos(-1)*2
                              point:
                              cp=bnot(cp);cn=cn+1;i1=i1+a1;colc=bnot(equal(cn,501));
                              trans=above(cn,500);v1=if(bnot(cn%vrem),v,v1+abs(v/10));
                              d=if(cp,1+v1*0.2,.98);th=t+i1*tpi; outx=sin(th)*d*r;outy=cos(th)*d*r;
                              inx=bnot(cp)*sin(th)*.3;iny=bnot(cp)*cos(th)*.3;
                              x=if(trans,outx,inx)+ox;y=if(trans,outy,iny)+oy;
                              red=colc;green=colc*.5;blue=0;
                              frame:
                              fr=fr+.01;t=t+ti*.1;ti=ti*.8;r=.4;cn=0;i1=0;ox=sin(fr)/2;oy=cos(fr)/2
                              beat:
                              ti=1;r=.5;hu=rand(618)*.01;fr=fr+sin(t*hu)

                              the trick is to draw everything in one ssc and then blacken out the point connecting the two objects.
                              then use a maximum or addictive blend to hide the trick
                              http://home.iitb.ac****~shreyaspotnis

                              Comment


                              • #45
                                Originally posted by Nic01
                                Shreyas : How about posting that code and explaining the code step by step?

                                On the other hand, colormaps can be used to replace a few colorclips. As long as the colors are not too close together, you can just use 2 of the same color and use a bounding box to make sure you get the right color.
                                I have done that thing to improve the speed, colourmaps and clips do the opposite!
                                i have already explained a bit of the code,but here's a detailed one.

                                set cn=cn+1 in point, this will increase value of cn every point, an ideal way to count the number of the point.

                                then use custom i values,
                                this is what i figured out:
                                incrementation value of i is inversely proportional to (n-1).
                                so, if n=10; then
                                after every point : i=i+1/(n-1);
                                i.e i=i+1/9;
                                i.e i=i+0.111111111111111111111111111111111.
                                so if you draw a circle using i1 instead of i when cn is less than 10 and then draw some other object when cn>10, then blacken out the point joining the two objects, you get two separate objects.

                                I hope you understood atleast some part of this, because I find it hard to explain things, especially complicated ones. if you cant figure out what this means, then maybe i will write an essay on this topic, after thinking hard and selecting my words
                                http://home.iitb.ac****~shreyaspotnis

                                Comment

                                Working...
                                X