Fade in of geo based on Z position

   3233   1   0
User Avatar
Member
8 posts
Joined: Feb. 2017
Offline
Good evening,

First post here, so in advance thank you for all your input and advice, I'll for sure be posting here more and more due to my first steps in Houdini learning at as a Maya sidekick software, I'm overwhelmed for sure right away.

Ok, now about my problem, I'm sure it's laughable, I have imported geo and points are scattered onto it, normals for them are generated via wrangle, then they are animated via mountain sop, then sphere primitive is copied onto those points, the question is - how can I get the spheres to show up from 0 opacity (fade in, in other words) one after another from Z towards me, so the furthest points show up first then those which are close (geo is a tunnel), etc.

I tried creating a alpha for spheres via attrib wrangle, but I right away encountered a problem that the alpha has not been picked up by Mantra even though mat was connected, so I left that idea and due to strict deadline decided to ask the community folks.

Please, take a second to help me on this primitive issue.

Thank you.

Vadim

Attachments:
Screenshot from 2017-04-10 05-18-08.png (391.7 KB)

Best wishes
VS.
User Avatar
Member
7801 posts
Joined: Sept. 2011
Online
It sounds like you have two problems:

  1. How do I map Camera Z to Alpha?
  2. How do I render with Alpha affecting Opacity?

The second is simple depending on how complicated of a shader you are using. If you simply want a constant shader, you can use the Surface Color vop to get the point color/alpha as well as set a constant color. To apply the alpha to your shader, you need to premultiply the color by the alpha to fade it out as the alpha fades out. Multiply the color by the alpha and connect the result to Ce on a layer pack node. Then connect the alpha to the Of of that same layer pack. Then you can apply the layer pack as a material to your point cloud.

The first is best done in a shader, as getting Z-depth in geometry context requires looking up the camera, and applying a transform. To get Z distance in a shader, simply use “Pz” from the global variables node. Now how do we map distance to opacity? The smoothest way that is simplest is with the exponential function, this will look like ‘fog.’ Compute the exponential of negative Z distance, scaling the distance to control how quickly it fades out. Other methods that could be used are simply a fit or smooth function or quadratic, but these won't look as natural as an exponential. If you computed alpha in a shader, simply connect it to the Of of the layer pack, and multiply your color.

If you really want to get z-distance in sops, then you can use a few different methods. The simplest is using the uv texture node, but this will create screen space coordinates with distance as the uv attribute z component. If you like vex/wrangles, ptransform() can be used to transform the local position into camera space, making the z component the negative distance from camera. If vops are more your style, the same function is available as the transform vop. Then it is up to you how to map distance to Alpha.

Attachments:
dotty_tunnel.zip (41.2 KB)

  • Quick Links