Jump to content
pak

World Space [3D] to Screen Space [2D] Transformation

Recommended Posts

I'm trying to transform/project 3d objects to a 2d planes that will look the same (with perspective) from camera.
Please have a look at the attached file to see my current workaround.

I am happy with the end result (this is what I wanted) but I feel this solution is far from being simple or clever (enough). How would you approach a similar problem?

P.S. Vex is okay, but a no-vex solution is what I am specifically looking for atm. 
 

world_to_camera_space.hipnc

Share this post


Link to post
Share on other sites

Looks clever enough for me. Allows for some interesting transformations to the grid. If you don't like to have grid on Scene level, you could Object Merge it within same SOP network, and specify camera as transform object.

If you look for more "pure" solution, try this:

camera_space_flatten.thumb.png.8ac3ef050a2471849528954b5c57c356.png

VEX equivalent:

// Point wrangle.

@P = toNDC(chs("camera"), @P);
@P.z = -ch("depth");
@P = fromNDC(chs("camera"), @P);

camera_space_flatten.hipnc

Edited by f1480187

Share this post


Link to post
Share on other sites

I've seen a similar solution on sidefx forums (posted the same question there).

This is very nice, very elegant. Thank you for the response.

I'm unable to wrap my head around what's going on there exactly. Tried looking the nodes step by step, viualizing te vectors (bind exported them to a point attribute), but still, I have not much clue on how this works. I would like to understand though.

How exactly do NDC nodes work? (documentation seems very plain in terms of technical/math explanation)

Feel free to link me to maths behind it ~

Share this post


Link to post
Share on other sites

You can visualize it by setting orthographic camera in a special way. Since Houdini's NDC is in 0..1 range (instead of -1..1), camera should have ortho width of 1.0 (instead of 2.0) and translated positive 0.5 units by X and Y (instead of looking at the center). Finally, it should account for aspect ratio controlled by "resolution" and "aspect" multiplier parameters in Houdini cameras.

Then you can see the nature of such transformation in 3D viewport:

ndc_demo.gif.c9d1714f6cf500b63006e0f16eca71d6.gif

You look through "camera window" and see the point at the center. It will have (x=0.5, y=0.5, z=depth) coordinates in screen space. X and Y are 2D coordinates in range 0..1, and scene depth is stored as Z. It doesn't respect camera's near and far bounds to map depth into 0..1 range, and uses real-world scale units instead. By setting Z to the same value you will flatten the object on the plane of such distance from the camera.

ndc_demo.hipnc

Edited by f1480187
  • Like 2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×