Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions SampleImage to duplicated layers :0

  • SampleImage to duplicated layers :0

    Posted by Micheel Leavitt on July 17, 2009 at 6:33 pm

    I am trying to sample an evolving fractal noise layer to get the luminance (lightness?) value of the noise layer directly underneath another layer. I got the idea from Dan Ebbert’s Noise() tutorial here on creativecow

    https://library.creativecow.net/articles/ebberts_dan/noise.php

    but the problem is really weird. sampleImage() is taking the sample from only one place, so every layer is the same movement. I could have sworn that this would work:

    target = effect(“Spectrum Layer”)(“Layer”);
    x = transform.position;
    area = [width/2,height/2];
    s =target.sampleImage([x[0],x[1]],area)
    r = rgbToHsl(s);
    ease(r[2],0,1,-125,125)

    which it does, until I turn this on for position:

    //Source code courtesy of Dan Ebberts of motionscript.com
    numRows = thisComp.layer(“Null 1”).effect(“num Rows”)(“Slider”);
    numCols = thisComp.layer(“Null 1”).effect(“Num Columns”)(“Slider”);
    row = Math.floor((index – 1)/numCols);
    col = (index – 1)%numCols;
    x = col*width/(width-thisComp.layer(“Null 1”).effect(“xOverlap”)(“Slider”)/100);
    y = row*height/(height-thisComp.layer(“Null 1”).effect(“yOverlap”)(“Slider”)/100);
    xOffset = numCols-thisComp.layer(“Null 1”).effect(“xStart”)(“Slider”);
    yOffset = numRows-thisComp.layer(“Null 1”).effect(“yStart”)(“Slider”);
    z = effect(“output”)(“Slider”);
    poz = [x,y,0] + [xOffset,yOffset,z];

    then it gets weird. I duplicated it a few times, and they all have the same value for the Output from the sampleImage. I thought the result would be it would take the sample from the layers position value, which is different for each layer. I don’t even know where the sample is coming from, it doesn’t match with the fractal noise position or the null in the comp either. How would I fix the sampleImage expression so it will take the sample from the fractal noise layer starting at the grid layer’s centerpoint. I just need to know how to get it to duplicate properly so any help would be great. Thank you!

    Micheel Leavitt replied 16 years, 9 months ago 2 Members · 4 Replies
  • 4 Replies
  • Dan Ebberts

    July 17, 2009 at 9:06 pm

    Is your target layer comp-sized and always positioned at the center of the comp? If not, you need to convert your sampling layer’s position into the layer space of the target. It would look like this (not tested):

    s =target.sampleImage(target.fromWorld(toWorld(anchorPoint)),area)

    Dan

  • Micheel Leavitt

    July 18, 2009 at 2:47 am

    It didn’t work ): I tried changing it to look like this:

    target = effect(“Spectrum Layer”)(“Layer”);
    area = [width/2,height/2];
    x = thisLayer.fromWorld(toWorld(anchorPoint));
    s =s =target.sampleImage([x[0],x[1]],area);
    r = rgbToHsl(s);
    ease(r[2],0,1,-125,125)

    It didn’t work. If the position expression is off, it will work properly. If the position expression is turned back on (tested multiple times)it will take the sample from it’s position before the expression was turned on, and apply it to all duplicates (pieces are 15×15 if this helps, NTSC comp settings) The strangest part of all though…I don’t know why, but if I do this in this order it will work:

    Turn off position expression
    Turn off slider that has sample expression
    Turn on position expression
    Duplicate until grid is done
    Turn on the sample expression on EVERY layer, one at a time DX

    Works perfectly if you do this, and why??? I thought maybe because sampleImage is somehow glitched, but I don’t know anything about it really except it usually works great, until this. If this will help, the position expression is the same as the one posted above, and the new sample expression is:

    //I know its redundant, just in case the target is 3D for some reason
    target = effect(“Spectrum Layer”)(“Layer”);
    area = [width/2,height/2];
    x = target.fromWorld(toWorld(anchorPoint));
    s =s =target.sampleImage([x[0],x[1]],area);
    r = rgbToHsl(s);
    ease(r[2],0,1,-125,125)

    The steps I took up top work with the original sample expression as well, which really makes this strange to me. If anyone has an idea, any info on this would be great!

  • Dan Ebberts

    July 18, 2009 at 4:58 pm

    I don’t know what to tell you. I set up a test comp with a 15×15 layer whose position is controlled by an expression with this sampling expression and it works flawlessly:

    target = effect(“Spectrum Layer”)(“Layer”);
    s = target.sampleImage(target.fromWorld(toWorld(anchorPoint)),[width,height]);
    rgbToHsl(s)[2]

    Any duplicates of the layer also work. Hard to say what’s going on in your case without seeing your project.

    Dan

  • Micheel Leavitt

    July 19, 2009 at 6:09 pm

    It does work, flawlessly, until you apply the position expression I used.

    //Original code courtesy of Dan Ebberts of motionscript.com
    numRows = thisComp.layer(“Null 1”).effect(“num Rows”)(“Slider”);
    numCols = thisComp.layer(“Null 1”).effect(“Num Columns”)(“Slider”);
    row = Math.floor((index – 1)/numCols);
    col = (index – 1)%numCols;
    x = col*width/(width-thisComp.layer(“Null 1”).effect(“xOverlap”)(“Slider”)/100);
    y = row*height/(height-thisComp.layer(“Null 1”).effect(“yOverlap”)(“Slider”)/100);
    xOffset = numCols-thisComp.layer(“Null 1”).effect(“xStart”)(“Slider”);
    yOffset = numRows-thisComp.layer(“Null 1”).effect(“yStart”)(“Slider”);
    z = effect(“Final Range Value”)(“Slider”);
    poz = [x,y,0] + [xOffset,yOffset,z];

    its just your grid expression with some sliders, and when I duplicate it, they all follow the original layer’s sample, not a new sample for the offset. It works if you wiggle it though.

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