sibarrick Posted April 4, 2005 Share Posted April 4, 2005 Hi all, Does anyone know how to build a matrix that will project the points of an object onto the viewing plane of a camera or light. I know how to transform the points from world space to the camera space but then how do you do the perspective projection onto the viewing plane using the FOV and the image res of the camera or light? I've found various descriptions of how to do this but when I try to impliment them they don't work with Houdini's camera FOV's and image res. I did find one formula that seemed to work but it wasn't a matrix, and so didn't allow me to transform z too, which is actually what I need to really do. Ultimately what I want to do is build a cop that lets you input 2 images with Pz info, one from the point of view of a camera and one from a light and then by specifying where the light was it will add shadows to the image. Of course if there is a cop that I don't know about that already does this then that would be handy too Any help gratefully recieved. Oh I should add that I can't do this with any built in space change functions. Firstly because you can't use them in cops and secondly because this is just a test for something that will eventually be done outside of Houdini, I just trying to figure out the maths for it. Quote Link to comment Share on other sites More sharing options...
edward Posted April 4, 2005 Share Posted April 4, 2005 This stuff is covered in most introductory computer graphics programming material. Lots of links if you look up "perspective projection matrix". For example, the lecture notes here: http://www.student.cs.uwaterloo.ca/~cs488/ EDIT: Try bottom of page 60 if you download the lecture notes from above. Quote Link to comment Share on other sites More sharing options...
Jason Posted April 4, 2005 Share Posted April 4, 2005 Does this help? Look at the SOP method. Velocity Rendering Tutorial Quote Link to comment Share on other sites More sharing options...
sibarrick Posted April 4, 2005 Author Share Posted April 4, 2005 Does this help? Look at the SOP method.Velocity Rendering Tutorial 17265[/snapback] Hi Jason, unfortunately this was exactly what I was trying to avoid, it uses those lovely built in space change functions, I want to know the math behind the functions. Edward, that link looks like exactly what I want, I try it out later, sometimes it seems to be hard to track down the basics. All my CG books describe the process but none of them are very precise about what is going on. For some reason my google search completely failed to turn up anything like this. All I got was a bunch of papers on doing perspective shadow mapping or openGL implimentations without the explaination. That link looks really handy, ta. Quote Link to comment Share on other sites More sharing options...
sibarrick Posted April 5, 2005 Author Share Posted April 5, 2005 Ok you clever people now I'm really stuck. Edwards link was great and when I implimented the code all looked good. However I had to use the tangent and not the cotangent to get sensible results. BUT when I compare it with doing the same projection with the UVtexture sop I found they didn't match. Digging a little deeper I find that according to the notes in Edwards link the Houdini projection is the incorrect way to do things. Take a look at the attached and you will see that the UVtexture sop distorts lines into curves whereas the method in the link does not. This raises two questions. 1. Is the Houdini UVtexture sop wrong or just different, and does this have any implications else where. Does it actually matter? Surely though people use this method of textureing for matching to live action plates so surely the UVtexture sop must work? 2. I still don't know how to match the way Houdini does it, in the attached example I've had to fudge it by manually altering the FOV value so that it no longer matches the light that it's linked to. If anyone has any answers to either of these questions I'd really appreciate it, in the meantime I'll keep digging. test1000.zip Quote Link to comment Share on other sites More sharing options...
Wolfwood Posted April 5, 2005 Share Posted April 5, 2005 <snip>...smart people stuff... <snip> On a side note the toNDC vex function produces the same results as the UVTexture SOP. sop ndcThingy(string cam = "") { P = toNDC(cam,P); } Quote Link to comment Share on other sites More sharing options...
Wolfwood Posted April 5, 2005 Share Posted April 5, 2005 2. I still don't know how to match the way Houdini does it, in the attached example I've had to fudge it by manually altering the FOV value so that it no longer matches the light that it's linked to. I took a quick peek at your vex setup and have one question... The aperture of the light/camera also effects the view frustum but I don't see it being taken into account anywhere? Quote Link to comment Share on other sites More sharing options...
sibarrick Posted April 5, 2005 Author Share Posted April 5, 2005 I took a quick peek at your vex setup and have one question...The aperture of the light/camera also effects the view frustum but I don't see it being taken into account anywhere? 17307[/snapback] That's a good point, I hadn't even begun to think about that, all the notes I've read so far only talk about the FOV. Changing aperture just seems to create a linear scale, if this is true it shouldn't be too hard to incorporate. By the way I've uploaded a new version as I made some errors in the original that I've already fixed. I'll totally confused at the moment and it's late so I'm off to bed. With any luck by the morning Edward and Mario will have sorted this mess out for me ..... One thing I'm thinking is that if you don't care about Z, and for texture mapping you mostly don't then the whole distortion thing doesn't matter it's only introduced by looking at the complete projection. All I really want to know is what transform do Sesi use, I have most of it now but I'm still having to fudge the FOV value so something is definately missing. Quote Link to comment Share on other sites More sharing options...
edward Posted April 5, 2005 Share Posted April 5, 2005 I don't really have time to delve into this but it seems like you're treating the focal length as the angle of view when it's not. See the bottom of this page: http://cade.scope.edu/courseware/notes/hou.../integrate.html TIP: If you combine the two sources of info, the atan/cot functions cancel out. Quote Link to comment Share on other sites More sharing options...
sibarrick Posted April 5, 2005 Author Share Posted April 5, 2005 Doh! That must be it. Thank you Edward, I'm not really up on camera descriptions, sure am learning a lot now. ta Quote Link to comment Share on other sites More sharing options...
sibarrick Posted April 5, 2005 Author Share Posted April 5, 2005 That did the trick! ta Ed. Quote Link to comment Share on other sites More sharing options...
edward Posted April 6, 2005 Share Posted April 6, 2005 See? Nothing magical after all. It's all just triangles. Quote Link to comment Share on other sites More sharing options...
sibarrick Posted April 9, 2005 Author Share Posted April 9, 2005 In case anyone was wondering what all this was about. Here is the result so far. It's a cop that lets you add depth map shadows in post. It's WIP - I still need to add a softness control. If anyone knows what the best way to do this is please let me know. I'm still researching it and there seems to be an a lot of different approaches. To see what it's doing go to the cop editor and bypass any of the file sops that are called light1* you should see the shadow for that object magically dissappear. Depth_composite.zip Quote Link to comment Share on other sites More sharing options...
edward Posted April 9, 2005 Share Posted April 9, 2005 That's cool. All you're missing now is an option to output an alpha channel instead you that we can blur it for soft shadows. :thumbsup: Could you also use autogen shadow maps? I wonder what space those maps are in. I guess you could always just look at the IFD. Quote Link to comment Share on other sites More sharing options...
sibarrick Posted April 9, 2005 Author Share Posted April 9, 2005 That's cool. All you're missing now is an option to output an alpha channel instead you that we can blur it for soft shadows. :thumbsup: Could you also use autogen shadow maps? I wonder what space those maps are in. I guess you could always just look at the IFD. 17445[/snapback] I've added soft shadows too now and alpha channel. see attached I think it will work with autogen shadow maps - they just store the depth like Pz deep rasters do. cop_shadows1000.zip Quote Link to comment Share on other sites More sharing options...
edward Posted April 10, 2005 Share Posted April 10, 2005 Are you multi-sampling for the soft shadows? I guess that's more accurate than blurring. Quote Link to comment Share on other sites More sharing options...
sibarrick Posted April 10, 2005 Author Share Posted April 10, 2005 Indeed the quality parameter is specifying number of samples, although I do it like a convolution filter where the dimension of the filter is actually (quality + 1) x (quality + 1) This gives better results although slower because it actually jitter the points around in the light space. If you just want to blur the hard edge result set the quality and the softness to 0 and then blur the alpha channel and use it in a composite. Quote Link to comment Share on other sites More sharing options...
edward Posted April 10, 2005 Share Posted April 10, 2005 Ooops, I didn't check the alpha channel. .... Hmm .... it might more useful to output it as a mask (M) channel instead while retaining original alpha. Quote Link to comment Share on other sites More sharing options...
sibarrick Posted April 10, 2005 Author Share Posted April 10, 2005 (edited) I was just following your suggestion Easily changed though. Actually not so easily changed. You can't create planes in Vex (unless I'm missing something) so I'm stuck with the alpha solution. Edited April 11, 2005 by sibarrick Quote Link to comment Share on other sites More sharing options...
doc Posted April 11, 2005 Share Posted April 11, 2005 Actually not so easily changed. You can't create planes in Vex (unless I'm missing something) so I'm stuck with the alpha solution. 17473[/snapback] You can try connecting your image to a color COP, which should add an M channel. then you can rename it with the rename COP 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.