gaurav Posted January 3, 2012 Share Posted January 3, 2012 (edited) Hello folks, It's kind of simple. But for better understanding, wish to avoid the habit of doing it the way i could make it work. Any alternatives / more efficient ways ? Thanks camdist.hipnc Edited January 3, 2012 by vectorblur Quote Link to comment Share on other sites More sharing options...
symek Posted January 3, 2012 Share Posted January 3, 2012 I would do this by getting camera Translation with extractTranformVOP, then lenght(cam_pos - P). Interestingly this seems to give more accurate results than a matrix inversion method. Seems like 32bit for inversion isn't enough (?)... camdist_skk.hipnc Quote Link to comment Share on other sites More sharing options...
Macha Posted January 3, 2012 Share Posted January 3, 2012 distance vop? Quote Link to comment Share on other sites More sharing options...
Kappy Posted January 4, 2012 Share Posted January 4, 2012 I always just use a UVTexture SOP, with the texture type set to "Perspective from Camera". The distance is in the uv[2] attribute (or $MAPW). Not sure about the relative efficiency, but it sure is easy! Quote Link to comment Share on other sites More sharing options...
3dbeing Posted January 4, 2012 Share Posted January 4, 2012 (edited) so i did some checking and the toNDC vop (cam near clip set to 0) gives the same result as the uv texture from camera space. This isn't suprising. But if I copy a point to the center of what appears to be the lense of the camera and use the distance vop, i get a different result, from slightly to not so slightly.. Why is this? Edited January 4, 2012 by 3dbeing Quote Link to comment Share on other sites More sharing options...
gaurav Posted January 4, 2012 Author Share Posted January 4, 2012 Thanks everyone for the replies. SYmek your examples and pro-tips are indeed very helpful as always. Quote Link to comment Share on other sites More sharing options...
gaurav Posted January 4, 2012 Author Share Posted January 4, 2012 Hi 3dbeing, Can you attach an example ? I am still a noob at coordinate space conversion jig within the geometry and shading contexts. Quote Link to comment Share on other sites More sharing options...
Macha Posted January 4, 2012 Share Posted January 4, 2012 so i did some checking and the toNDC vop (cam near clip set to 0) gives the same result as the uv texture from camera space. This isn't suprising. But if I copy a point to the center of what appears to be the lense of the camera and use the distance vop, i get a different result, from slightly to not so slightly.. Why is this? Did you choose the correct center? Is your object on 0,0,0 ? Quote Link to comment Share on other sites More sharing options...
3dbeing Posted January 4, 2012 Share Posted January 4, 2012 Did you choose the correct center? Is your object on 0,0,0 ? i am finding the camera origin point by merging the camera geo into a geo obj, blasting all but the cone, converting the cone to polys and blasting all but the circle part that represents the lense. Both the camera and the object are off all 3 axis in rotation and translation. I will post something later. But that distance vop gives a different number than using toNDC vop, while the toNDC vop and the texture from camera give identical results, so I'm curious where the discrepency is. Quote Link to comment Share on other sites More sharing options...
3dbeing Posted January 4, 2012 Share Posted January 4, 2012 So here are all the methods, I've appended to SYmeks file and I can only assume that it is the most accurate. Interestingly enough, or obviously, whichever, the inverse matrix option yields identical results as the camera texture and toNDC. The distance vop using a point at the center of the cam lens is off from SYmeks by .001? So my question is; why? The inverse matrix is inaccurate? Why is the point method off by .001? Quote Link to comment Share on other sites More sharing options...
eetu Posted January 4, 2012 Share Posted January 4, 2012 so i did some checking and the toNDC vop (cam near clip set to 0) gives the same result as the uv texture from camera space. This isn't suprising. But if I copy a point to the center of what appears to be the lense of the camera and use the distance vop, i get a different result, from slightly to not so slightly.. Why is this? Is the result correct in the center of the image, but gets worse further from the center? If so, I guess it could be related to the Pz being calculated perpendicular to the image plane, not the distance to camera.. Quote Link to comment Share on other sites More sharing options...
rdg Posted January 4, 2012 Share Posted January 4, 2012 (edited) I had a similar question the other day on the mailing list [1]. The answer was: uvTexture ( and most likely toNDC() ) only give correct results for the center of the projection. Hence distance(P, camOrigin) gives the proper distance for all points in all cases. [1] http://bit.ly/zlOjPU Edited January 4, 2012 by rdg Quote Link to comment Share on other sites More sharing options...
3dbeing Posted January 4, 2012 Share Posted January 4, 2012 wait wait wait... cam origin... ok now all things line up... using cam origin yields identical results to SYmeks method and the uv/toNDC issue makes sense... i can rest again peacefully... thanks rdg! Quote Link to comment Share on other sites More sharing options...
gaurav Posted January 4, 2012 Author Share Posted January 4, 2012 Very nice. I understand this much better than i did an hour ago. Thanks Quote Link to comment Share on other sites More sharing options...
3dbeing Posted January 4, 2012 Share Posted January 4, 2012 ohhh it seems my file didn't attach, so here are all 5 methods in use...and if you notice, the checkbox symek provided switches between the 2 results. camdist_3db.hipnc Quote Link to comment Share on other sites More sharing options...
Jason Posted January 4, 2012 Share Posted January 4, 2012 Yes, be careful about whether you need the distance to the camera plane, or the camera point. The camera plane is the same Z value as what you'd get from a z-depth map and the UV projection method will return this value. Using a distance() function against the camera will give you the camera point version. 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.