-
Random layer position constrained by another layer’s alpha
As per Mike’s suggestion, I am moving this discussion over here…
I am trying to create a 2.5D landscape with several hundred layers randomly positioned all over the landscape. I see how to have the position be random, but is there a way to limit the positions to only within the “island” of the landscape as defined by its alpha channel? This is something simple to do with trapcode’s particulate, but i need the shadows cast onto the ground and thats where trapcode is failing me.
thanksName: Mike Clasby
Date: Jan 6, 2008 at 6:26:45 am
Subject: Re: Random layer position constrained by another layer’s alphaThis modified Dan Ebberts’ expression is a good place to start. It goes on Position.
minX = 0;//Minimum x depth value
maxX = 500;//Maximum x depth value
minZ = 0;//Minimum z depth value
maxZ = 1000;//Maximum z depth value
op = thisComp.layer(“opLeader”).opacity;opX = linear(op,0,100,minX,maxX);
opZ = linear(op,0,100,minZ,maxZ);seedRandom(index, true);
x = Math.round(random(opX));
z = Math.round(random(opZ));[x, position[1], z]
Change the min/max X and Z as needed. All the Y’s are the same, I’m assuming you have a Floor if you want to cast shadows, so you Y needs to be at (or near) the Floor.
Is this close to what you want?
Name: Chris Coleman
Date: Jan 6, 2008 at 7:29:42 am
Subject: Re: Random layer position constrained by another layer’s alphaclose, but I think the opacity is one value for the entire layer. Is there an attribute than can look at the alpha channel at any given point? It is an illustrator file layer serving as the island map, and i want to make sure the trees randomly place themselves on the land. ( I did try your suggestion but to no avail. Thank you for puzzling thru this with me.
Name: Mike Clasby
Date: Jan 6, 2008 at 8:10:49 am
Subject: Re: Random layer position constrained by another layer’s alphaOh, I see what you’re trying to do.
Yes, you probably can, err, maybe Dan can, ask over at the Cow Expression Forum:
https://forums.creativecow.net/viewforum/227
I think if you combine this position expression from Colin:
minX = 0;//Minimum x depth value
maxX = 1000;//Maximum x depth value
minZ = 0;//Minimum z depth value
maxZ = 2000;//Maximum z depth value
seedRandom(index, true);
x = random(minX,maxX);
z = random(minZ, maxZ);
[Math.round( x), position[1], Math.round( z )]With an Opacity expression that is 100 when there is a Collision Detection, and 0 when not, from Dan’s page:
https://www.motionscript.com/design-guide/collision.html
But I don’t have AE CS3 or the expression finesse to do it.
Alternatively, you could just use Colin’s Position expression above, with the min/max set to hit the island, and then turn off the eyeballs of all trees landing off-island, and shy them so they don’t clutter up the stack. That way no collision detection necessary… er, actually you would be performing the collision detection, manually.
Name: Chris Coleman
Date: Jan 6, 2008 at 8:44:42 am
Subject: Re: Random layer position constrained by another layer’s alphaHmm. You have provided some good clues. I see where the two for loops in the collision test could look for the alpha. I am curious tho that if I turn off the opacity of the off island trees manually or with this script, will it still tie up processor time? I am looking to add 1000-2000 of these trees add if I am paying for the invisable ones, it would suck render time. Can an expression turn off the visibility switch or should I try to force a new seed for any tree that lands in the water?
(I never feel like I am accomplishing anything unless I am pushing AE to its limits, hehehe)