toNDC and screenspace projection. How?

   3623   4   1
User Avatar
Member
61 posts
Joined: Feb. 2006
Offline
Hi,

I want to get object points in a VOP or wrangle into their flattened (depth) position in viewport, as they would appear in the perspective rendered image. So, in a VOP or wrangle the toNDC() will get the first stage done but how to apply the final screen perspective translation afterwards inorder to see, through the scene camera, the final, flattened 2d geo that will match the final points-to-pixels perspective? The same way you used to make UV renders with scene camera before the H15 “UV render” rop came along.

The topic has come up a few times before and looking through posts, Ive not actualy seen one that works accurately. Anyone mastered this? Or do I need to workout the matrix transforms from scratch? (there doesnt seem to be a “toPerspective” funtion or vop like the “toNDC” funtion/node).

million thanks!
Frank
Edited by frankvw - July 3, 2017 11:58:36
User Avatar
Member
8573 posts
Joined: July 2007
Offline
toNDC() just converts to ndc space, it doesn't flatten
if you want to flatten it, multiply .z by 0
then you can offset to desired depth
and bring back in front of the camera if you want using fromNDC()
string cam = "/obj/cam1";
@P = toNDC(cam, @P); // to ndc space
@P.z *= 0;  // flatten
@P.z -= 1; // set depth
@P = fromNDC(cam, @P); // if you need bring back in front of cam
Edited by tamte - July 3, 2017 12:15:38
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
61 posts
Joined: Feb. 2006
Offline
Hi,
Thanks for trying but that doesnt work.

Perpsective translation after NDC will need to account for camera perpsective per point after that stage, extra level of transformation (ignoring back culling etc.,).

If you try your method, its a bit hit and miss and definitely will not lineup closely with a final rendered image, if you applied it as a camera background.

Maybe any of the sidefx mantra render developers here? Its such a standard matrix operation, I'm just trying to be a bit lazy.

cheers
Frank
User Avatar
Member
8573 posts
Joined: July 2007
Offline
I might have misunderstood what you need then, since toNDC() and fromNDC() take care of all perspective transformation per point for you

the code I posted simply flattens what you see in front of the camera

- if your source is already 0-1 screen space in correct depth, then just bring it in front of your camera using FromNDC()
- similarly if it's in world/object space and the only thing you care about is to flatten from it then use foNDC() and .z *= 0; if you have other means of bringing it as a background (like parenting to cam) and don't want to use fromNDC()
Edited by tamte - July 3, 2017 12:31:35
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
61 posts
Joined: Feb. 2006
Offline
Hi,
Actually, having had time to render it off and overlay it, its pretty good. Even on a large scene with animated characters and cameras, its quick as well.

Million thanks,
Frank
  • Quick Links