main
side
curve
  1. In Memory of LAJ_FETT: Please share your remembrances and condolences HERE

Expressions Help, After Effects - Lens Flares

Discussion in 'Fan Films, Fan Audio & SciFi 3D' started by PixelMagic, May 12, 2009.

Thread Status:
Not open for further replies.
  1. PixelMagic

    PixelMagic Jedi Grand Master star 5

    Registered:
    Oct 8, 2001
    Hey guys, I'm trying to do something with a lens flare I can't figure out. I am building custom anamorphic lens flares using Knoll Light Factory elements on different layers. I need to have all elements move with the main flare layer, and I know I can do that by pick whipping the "Light Source Location" However, I don't want to have it follow the vertical in the same amount as the horizontal.

    What I want is, for the horizontal to move exactly proportional to the main flare, but I want the vertical to only move about 10% as much. How do I pick whip it to the main flare location so that it follows horizontal properly, but limit it's vertical to only move 10% as much.

    I'm not that good with expressions yet, so I figured someone out there might be able to help.
     
  2. Teague

    Teague Jedi Padawan star 4

    Registered:
    Apr 9, 2006
    You couldn't do this parenting the expression to a null, that is scaled down 90%?
     
  3. drewjmore

    drewjmore Jedi Knight star 4

    Registered:
    Aug 15, 2007
    after you pick-whip the location the expression text-box will have a line of complicated looking text.

    At the beginning of that line of text insert "myVar=" and end the line with ";"

    That sets a variable equal to the x,y coordinate.

    Then add a new line: "[ myVar[0] , myVar[1]*.1 ];"

    That does the math you want and sends the result to the layer's position.
     
  4. Ryan_W

    Ryan_W VIP star 4 VIP

    Registered:
    Aug 15, 2001
    Keep in mind if you multiply a number by .1, it doesn't move toward the center, it moves toward the top left corner, where 0,0 is.
     
  5. BenMcEwan

    BenMcEwan Jedi Youngling star 3

    Registered:
    Jul 2, 2008
    I thought you could pile up all the different parts of the flare from KLF on 1 layer, then use a Global Position parameter?
    I may be wrong though - it's been a while since I last used it.
     
  6. PixelMagic

    PixelMagic Jedi Grand Master star 5

    Registered:
    Oct 8, 2001
    Humm, that math did work, but not in the way I expected. Sigh. I wish they would just update KLF to handle anamorphic flares properly. I've been struggling with this off and on for alike a year.

    If you watch a real anamorphic flare, the lens elements move quite alot if the flare moves left to right, but they barely movee at all when the flare moves vertically, however, they stay about right at the centerline of the flare.

    I successfully approximated this effect by having chroma hoops on one layer be a luma mask for a horizontal stripe on the layer below. However, they are very squared looking, and not rounded like some anamorphic artifacts. I suppose I could use a bokeh producing defocus on this element to get the effect I'm after. However, that's alot of work for a stinkin' flare. Ha.

    EDIT: This is what I have so far...

    [image=http://img.photobucket.com/albums/v58/PixelMagic/anamorphic_flare_01.jpg]
     
  7. Ryan_W

    Ryan_W VIP star 4 VIP

    Registered:
    Aug 15, 2001
    See if this gets you somewhere:

    main=thisComp.layer("positionLayer").transform.position;
    main is just a variable name... what you put after the equals sign is the position information for your main light source position.

    If you're new to expressions, you will see this type of line is happening throughout the whole expression. Any time you put text and then an equals sign, you are setting a variable. A variable is telling AE (javaScript) the name of something you want it to remember, that you will call upon later. After the equals sign, is what you want that variable to be. A semicolon is always how you end a line of code in expressions, before moving on to the next line. So, from now on, whenever you write your variable name in your expression, it will remember back to the line where you set it, and drop in that value (or collection of values).

    For this, you could also highlight everything after the equals sign and then pickwhip an effect point position to overwrite it and set your variable to that.


    w=thisComp.width;
    h=thisComp.height;

    Pretty self-explanatory. We obtain the compositions width and height for use in just a second.

    If you are new to expressions, you may wonder why in these and the following lines we do everything twice. Positional values in 2D space are 2-dimensional, meaning that they have 2 components: X and Y (width and height). In 3D space, it is a 3-dimension number, with Z added. A slider, for example, is a 1-dimensional value. If you want different things to happen to each dimension, you have to work on each separately and then integrate them back into an array at the end. An array is simply a collection of 1-dimensional values, into a multi-dimensional value. Like a 2D position, in this example.


    x=((main[0]-w/2)*1)+w/2;
    y=((main[1]-h/2)*0.1)+h/2;

    Here we first subtract half of the comp's width/height from the value to "center" the location relative to AE's [0,0] before multiplying it by our desired factor. That number is what you change to affect where that value floats between (or beyond) your source point and the center of frame. A value of 1 in the x line means it will be the same value, as 1*value=value. In the y line, we multiply it by a fraction of 1 so it only goes that corresponding fraction of the distance, in that dimension. If you put in a value greater than 1, then it will go beyond your source point.

    You may be wondering why in each line, after our variable main, we have bracketed numbers [0] and [1]. Remember that our main variable that we set is a 2D position value. This is actually an array, as mentioned before; containing 2 values: X and Y. So, since we need the X value only, in the first line, and the Y value only in the second line, we need to retrieve each one on it's own. JavaScript numbers start at 0 instead of 1. So, confusingly, the first value in an array is the [0] value and the second is the [1] value. Knowing that, read across the line again to see that we ask for the 0th position value (which is the first one, which is X) from our variable main which gives us the X value.


    [x,y]
    We enter the results as an array (by putting the values in brackets, separated by commas) to be used for this expression's final output. Yay!


    So, take the bold lines and put them in an expression for your position of your other flare element. For real-time control, make two Expression Control Sliders on it and pickwhip them into where those multiplication values are, so you can adjust the sliders to position your element relative to your source flare to taste.
     
  8. PixelMagic

    PixelMagic Jedi Grand Master star 5

    Registered:
    Oct 8, 2001
    Thanks for the help, Ryan. I appreciate you taking the time to do that, but it is so over my head it makes me want to cry. I've never done expressions before, so I have no idea what any of that meant. Maybe if I read it several times over I'll get it, but damn.

    Would it be too much to ask for you to do a quick little example scene file in AE, and then allow me to look at it? If not, that's ok.
     
  9. Ryan_W

    Ryan_W VIP star 4 VIP

    Registered:
    Aug 15, 2001
    Read it a few more times until it starts making sense. It looks kind of scary, but it's not that complicated, really.

    Like I said, if you just take all the bold lines and put them into your expression field for position (removing my annotations and modifying the first line as indicated) then you should see it work, and then you can poke and prod the code yourself to see what happens/breaks.

    I edited some of my annotations a little to try to explain in more detail some of the basics of what is happening.
     
  10. PixelMagic

    PixelMagic Jedi Grand Master star 5

    Registered:
    Oct 8, 2001
    Thanks Ryan, that seemed to get me part of the way there. However, the lens elements, which are a circle spread, act correctly horizontally, but do not stay locked to the center of the flare. They just stay in the middle of the comp and move very little verticaly.

    Here is an example I did over a year ago using the luma mask/chroma hoop/horizontal stripe trick.

    http://vimeo.com/975586

    Notice how the bright green elements pretty much stay lined up with the horizontal stripe with only a very slight drift vertically. I am trying to force KLF to do that with circle elements to get a look close to a true anamorphic flare.

    It may be that KLF just won't do what I am attempting. The math used by KLF for flare position may not allow it. It was just an experiment. I wish someone would just right a plug-in that would do anamorphic flares correctly.

    Anyway, I don't even really need them for anything, I just wanted to see if I could do them for fun.
     
  11. Ryan_W

    Ryan_W VIP star 4 VIP

    Registered:
    Aug 15, 2001
    Well, as I'm a little unclear on exactly how much of this is taking place inside the effect, and what is taking place on the layers, etc, it's a bit difficult to visualize and understand what makes it not do what you want it to do. So I'm not sure what to advise.
     
  12. PixelMagic

    PixelMagic Jedi Grand Master star 5

    Registered:
    Oct 8, 2001
    Well, Ryan, your expression got me half of the way there, and then I had a breakthrough that is giving me almost exactly what I want. If you have KLF, you can look at he scene file here...

    https://www.yousendit.com/download/dVlvWGJFMVh6RTkzZUE9PQ

    If you don't, just install the demo, and you'll be able to see what's happening. It's working pretty well now. I used a Transform effect to force the center of the elements to move with the flare center. They now slightly float above and below the center point, depending on how you move the flare.

    I now just have to figure out how I can control the offset from the center of the flare, and it'll be working nicely. Awesome. :)

     
  13. Ryan_W

    Ryan_W VIP star 4 VIP

    Registered:
    Aug 15, 2001
    You're on CS4 dude? Us old-timers can't open that new hotness.
     
  14. PixelMagic

    PixelMagic Jedi Grand Master star 5

    Registered:
    Oct 8, 2001
    Ha, sorry, I'm at work right now, and they upgraded me when the new one came out.
     
  15. BenMcEwan

    BenMcEwan Jedi Youngling star 3

    Registered:
    Jul 2, 2008
    Ryan: For someone that barely understands any sort of coding, your explanation above explained everything awesomely!
    Pixel: I'm lovin it! Nice
     
  16. PixelMagic

    PixelMagic Jedi Grand Master star 5

    Registered:
    Oct 8, 2001
    Starting to get somewhere. I am uploading a Vimeo vid of it. It will show up in a little while.

    [image=http://img.photobucket.com/albums/v58/PixelMagic/anamorphic.jpg]
     
  17. PixelMagic

    PixelMagic Jedi Grand Master star 5

    Registered:
    Oct 8, 2001
    Ok, Vimeo finally uploaded the video...

    http://vimeo.com/4650707
     
  18. Rhys

    Rhys Jedi Master star 4

    Registered:
    Jun 27, 2005
    Might be better to judge on actual footage.
     
  19. Teague

    Teague Jedi Padawan star 4

    Registered:
    Apr 9, 2006
    The greyness of the flare bugs me on a "should be set to add" level. Obviously the final flare should be set to screen, but as it interacts with itself, it looks odd to me.

    EDIT: Actually, the more I look at it, the more it works for me.
     
  20. PixelMagic

    PixelMagic Jedi Grand Master star 5

    Registered:
    Oct 8, 2001
    Well, I do think the elements are separating too far apart. I was trying to base it closely to reference seen at this link...

    http://claudiomiranda.com/lenstest/page2.html

    It is based off the flare in the lower right corner.

    Very good reference for showing the exact kind of effects I'm trying to achieve. I wish Knoll Light Factory could do things like this natively.

    You would expect you could just make a normal lens flare, and then stretch it out to 2.35, but it just doesn't seem to work that way.
     
  21. PixelMagic

    PixelMagic Jedi Grand Master star 5

    Registered:
    Oct 8, 2001
    Yay, finally.

    [image=http://img.photobucket.com/albums/v58/PixelMagic/anamorph_7_09.jpg]
     
  22. TrowaGP02a

    TrowaGP02a Jedi Master star 4

    Registered:
    Dec 24, 2004
    Wow looks great in still form, let's see it move!
     
  23. Ryan_W

    Ryan_W VIP star 4 VIP

    Registered:
    Aug 15, 2001
    Let me ask you a question. Have you ever actually seen, or can anybody show me an example of, an actual flare that has those super thin rays coming out?
     
  24. TrowaGP02a

    TrowaGP02a Jedi Master star 4

    Registered:
    Dec 24, 2004
    Actually yeah. This is the film I did effects for a while back, shot on 35mm with anamorphic lenses(more detail on site) and it is chock full of lens flares. The first shot with the firetruck has those thin lines on the flare, at least it looks like it to me.

    movie
     
  25. Ryan_W

    Ryan_W VIP star 4 VIP

    Registered:
    Aug 15, 2001
    Eh, there are rays, but about a dozen of them radiating out. That's a different thing.

    I've never seen the zillion little tiny super thin rays coming out, it always looks super computery to me and ruins the whole feel of it.
     
Thread Status:
Not open for further replies.