Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Layer Z position driven by luminosity value

  • Layer Z position driven by luminosity value

    Posted by Bill Porter on September 26, 2012 at 3:04 pm

    Hi,

    I couldn’t find quite what I’m looking for and hope someone can help me with this.

    Is it possible for a 3D layer to get it’s Z value from a luminosity colour picker?

    Here is a diagram [that is supposed] to show what I’m trying to do. The gradient layer acts as a displacement map, so depending where the pink blob layer moves around on the X and Y, it’s Z position rises and falls. Or if I animated the displacement map luminosity the blobs will rise and fall accordingly. The blobs would pick their luminosity value from their XY position – I saw something about sampleImage() that might be able do this?

    Basically a bit like what you can do with trapcode form, but I want to do it on individual layers…

    It boggles my brain trying to fathom how I’d go about this, so any help would be greatly appreciated.

    Kevin Camp replied 13 years, 7 months ago 2 Members · 5 Replies
  • 5 Replies
  • Kevin Camp

    September 26, 2012 at 3:36 pm

    yep, sampleImage() is what you’r looking for… try this:

    mult = 1000;
    grad = thisComp.layer(“gradient”);
    rad = [.5,.5];
    z = mult * rgbToHsl(grad.sampleImage([value[0],value[1]], rad, true))[2];
    value – [0,0,z]

    change the grad variable to be your gradient layer name (mine was named ‘gradient’) and modify the mult variable to get the amount of offset you need.

    rad is the radius of the sample point — [.5,.5] samples a single pixel. a larger sample radius will average the value of the pixels in the radius, which can help smooth the movement. setting rad to [width,height] will use the full area of the layer as a sample point.

    dan ebberts has an example of sampleImage() with a nice explanation of it here:
    https://www.motionscript.com/design-guide/obscuration.html

    Kevin Camp
    Senior Designer
    KCPQ, KMYQ & KRCW

  • Bill Porter

    September 27, 2012 at 12:17 pm

    Bingo! That’s exactly what I’m after. Thank you so much!

    Dan Ebbert’s article is interesting. Is there a way I could do this for the opacity of the moving layer? – so when the layer is at the lowest Z point it has 0 opacity and 100 at the highest?

  • Kevin Camp

    September 27, 2012 at 4:22 pm

    yep… sampleImage() samples rgb and alpha, so if you change the z expression line to this:

    z = mult * grad.sampleImage([value[0],value[1]], rad, true)[3];

    it will sample the alpha data.

    Kevin Camp
    Senior Designer
    KCPQ, KMYQ & KRCW

  • Bill Porter

    September 28, 2012 at 11:29 am

    Thank you Kevin! I see what you mean… But, sorry I didn’t explain properly. What I meant was can the gradient layer drive the opacity value of the pink layer?

    So it would act a bit like this

  • Kevin Camp

    September 28, 2012 at 4:20 pm

    sorry, you can use the linear() function to interpolate one set of value to another…

    something like this would interpolate z position to a 0-100 value (like opacity):

    zMin = -1000;
    zMax = 0;
    linear(position[2], zMin, zMax, 100, 0)

    use the min and max variables to set a range for the z motion… in your example, if the lowest that the layer moves is -100 and the highest is -800, then the zMax value would be -100 and the zMin would be -800, and at those points the opacity would be 0 or 100 respectively.

    Kevin Camp
    Senior Designer
    KCPQ, KMYQ & KRCW

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy