FORUMS: list search recent posts

Limit alpha to just a portion of the layer for use with sampleImage

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
David Cabestany
Limit alpha to just a portion of the layer for use with sampleImage
on Jul 24, 2013 at 4:17:35 pm

I'm trying to control the opacity of a layer based on the alpha of a beam. The end point of the beam never moves but it appears and disappears and what I want is to have the other layer appear and disappear based on the alpha of the end point of the beam.

I'm using the expression below, which has the beam as target layer and then I added a null with a point control (target pos) to limit the area to the end point, but my guess is right now is taking the alpha from that layer and not the beam, how do I revise the expression to take the alpha of the beam's end point into account?

Thanks everyone,
David.

target=thisComp.layer("beam");
alpha=target.sampleImage((thisComp.layer("target pos").effect("Point Control")("Point")),[1,1])[3];

if
(alpha=1)
{
100
}
else
{
0
}
;


Return to posts index

Dan Ebberts
Re: Limit alpha to just a portion of the layer for use with sampleImage
on Jul 24, 2013 at 4:26:47 pm

I think you probably just need to add sampleImage()'s third parameter (postEffect) and set it to true.


Dan



Return to posts index

Mitch Mann
Re: Limit alpha to just a portion of the layer for use with sampleImage
on Jul 24, 2013 at 4:32:23 pm

Just use a track matte, I'm not sure why you need expressions here.


Return to posts index


David Cabestany
Re: Limit alpha to just a portion of the layer for use with sampleImage
on Jul 24, 2013 at 4:42:42 pm

The object I'm trying to make transparent is an audio spectrum, I might change the expression to drive the height of the peaks instead of the transparency of the layer instead, the same beam also drives an if/the expression on text, when it's fully opaque it shows some random reading but when it's transparent it needs to show 0, so a track matte is not helpful in this case.

Thanks,


Return to posts index

David Cabestany
Re: Limit alpha to just a portion of the layer for use with sampleImage
on Jul 24, 2013 at 4:40:11 pm

Thanks Dan, much appreciated as always.
How do I add that parameter, I tried typing it after the point control and before the arrays but didn't work, can you tell me its exact syntax?



I checked your blog as well Adobe's entry on sampleImage but I'm not very clear on where to include the third and fourth parameters.

Again, thank you very very much.


alpha=target.sampleImage((thisComp.layer("target pos").effect("Point Control")("Point"))(postEffect=true),[.5,.5])[3];


Return to posts index

David Cabestany
Re: Limit alpha to just a portion of the layer for use with sampleImage
on Jul 24, 2013 at 4:48:42 pm

I think I got the syntax right, but the behavior is still not as expected, I now the expression is functional because if I change the value of alpha to 0 the layer reacts to it, it's just not changing each frame as I ned it to.

target=thisComp.layer("beam");
alpha=target.sampleImage((thisComp.layer("target pos").effect("Point Control")("Point")),[.5,.5])[3],(postEffect=true);

if
(alpha=1)
{
100
}
else
{
0
}
;


Return to posts index


Xavier Gomez
Re: Limit alpha to just a portion of the layer for use with sampleImage
on Jul 24, 2013 at 5:22:41 pm

Hello, i haven't read the full thread but i noticed you mispelled your condition: if (alpha=1) should be if (alpha==1). It might fix it.

By the way the whole last statement can be shortened to:

(alpha==1) ? 100 : 0;

Xavier.


Return to posts index

David Cabestany
Re: Limit alpha to just a portion of the layer for use with sampleImage
on Jul 24, 2013 at 5:37:42 pm

Thanks Xavier, I added the extra = sign but no luck, it change the return value to 1% but that was it, it still doesn't change over time.

My new expression reads like it's shown below.

Best,
D.

target=thisComp.layer("beam");
alpha=target.sampleImage((thisComp.layer("target pos").effect("Point Control")("Point")),[.5,.5])[3];

(alpha==1) ? 100:0;


Return to posts index

Xavier Gomez
Re: Limit alpha to just a portion of the layer for use with sampleImage
on Jul 24, 2013 at 8:14:03 pm

I dont see how you can get 1% opacity since your expression can only return 0 or 100.
Two things that might happen:
- the alpha at your beam endpoint is never exactly 1, hence your expression always returns 0;
- you are sampling the wrong point (this could come from the point control attached to the null).

I tried this expression on a fake project and it did what it is supposed to do:

target = thisComp.layer("beam");
P = thisComp.layer("beam").effect("Beam")("Ending Point");
target.sampleImage(P,[.5,.5],true)[3] * 100;

If it works for you too then you can replace the last line with:
alpha = target.sampleImage(P,[.5,.5],true)[3];
(alpha==1) ? 100 : 0;

Xavier


Return to posts index


David Cabestany
Re: Limit alpha to just a portion of the layer for use with sampleImage
on Jul 25, 2013 at 4:59:15 am

I don't know either, but that's what's happening, as soon as I change the = to ==, >= or <= the value drops to 1.
I checked the point form where I'm sampling by zooming in as much as I could and reading the alpha value on the info panel, I'm getting absolute 0.
The point I'm sampling is the only thing on the null and I even tried it on a dummy comp with nothing more but a solid, no matter where I placed the point I wasn't able to get the expected readings, yet I imported an older project with a similar expression but applied to an optical flare and it works as expected.

I'll try your revised expression first thing tomorrow, thanks a lot for taking the time.

I can post the project if anyone wants to take a look.

I'm completely puzzled about this.
David.


Return to posts index

David Cabestany
Re: Limit alpha to just a portion of the layer for use with sampleImage
on Jul 25, 2013 at 9:11:55 pm

Hey Javier I just tried the expression that you kindly wrote, it works perfect! Thanks a lot, you just saved me a ton of keyframe, if at all possible to keyframe that!

Best,
David.

Below is the revised version to drive the text, in case anyone needs it.

posterizeTime(10);
target = thisComp.layer("beam");
P = thisComp.layer("beam").effect("Beam")("Ending Point");
alpha = target.sampleImage(P,[.5,.5],true)[3];

if (alpha==1)
{

n=random(-16,24);
n.toFixed(3)+" dB]";
}
else{
0+"dB]"
};


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]