pak Posted November 8, 2017 Share Posted November 8, 2017 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 Quote Link to comment Share on other sites More sharing options...
f1480187 Posted November 9, 2017 Share Posted November 9, 2017 (edited) 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: VEX equivalent: // Point wrangle. @P = toNDC(chs("camera"), @P); @P.z = -ch("depth"); @P = fromNDC(chs("camera"), @P); camera_space_flatten.hipnc Edited November 9, 2017 by f1480187 1 Quote Link to comment Share on other sites More sharing options...
pak Posted November 9, 2017 Author Share Posted November 9, 2017 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 ~ Quote Link to comment Share on other sites More sharing options...
f1480187 Posted November 10, 2017 Share Posted November 10, 2017 (edited) 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: 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 November 10, 2017 by f1480187 3 Quote Link to comment Share on other sites More sharing options...
pak Posted November 10, 2017 Author Share Posted November 10, 2017 Thank you very much for this charming explanation! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.