Skip to main content
Inspiring
April 19, 2023
Answered

transparency of 3d layer on top of 3d layer

  • April 19, 2023
  • 1 reply
  • 418 views

Hello community

I have a comp with a white text on black background within another comp. On top of this subcomp I have a PNG of a traffic cone . This PNG layer is randomly placed all over the comp (comp is filled with about 200 of these cones).

Since I have to export several texts in this way, I thought it would be good to distribute the traffic cones over the whole space at random positions and only display them when the white writing is visible underneath. My expression for the transparency property of the PNG is the following:

 

underlyingLayer = thisComp.layer("Name Comp");
if(underlyingLayer.sampleImage(transform.position, [0.5, 0.5])[0] > 0.5) {
  100;
} else {
  0;
}

 

That works quite well, but sadly only in 2D space. If I change the "Name Comp" to 3D and change its x rotation, the cones are not changing their visibility as if the text comp hasn't turned in 3D space.
I found out that it could have something to do with toWorld(), but I don't know where to put that into my expression.
Does anyone see where I made the mistake?

This topic has been closed for replies.
Correct answer Dan Ebberts

Try it this way:

underlyingLayer = thisComp.layer("Name Comp");
p = underlyingLayer.fromCompToSurface(position);
if(underlyingLayer.sampleImage([p[0],p[1]], [0.5, 0.5])[0] > 0.5) {
  100;
} else {
  0;
}

1 reply

Dan Ebberts
Community Expert
Dan EbbertsCommunity ExpertCorrect answer
Community Expert
April 19, 2023

Try it this way:

underlyingLayer = thisComp.layer("Name Comp");
p = underlyingLayer.fromCompToSurface(position);
if(underlyingLayer.sampleImage([p[0],p[1]], [0.5, 0.5])[0] > 0.5) {
  100;
} else {
  0;
}
Inspiring
April 19, 2023

Yes! That was it! Thanks @Dan Ebberts!