Hi Jonathan, After writing the above, I did manage to get it working for a LensNFunc, but not for a LensFunc function.
Using the lensNfunction virtual, I can return my own lens function to handle distortion, and I notice I can test the current projection mode (as set either in the camera or the scanline render), and return my custom function only for a certain mode(s). /*virtual*/ LensNFunc* lensNfunction(int mode) const { if (mode == LENS_PERSPECTIVE) { cout << "custom lens func" << endl; return my_lens_distort; } return CameraOp::lensNfunction(mode); } But if I try the same with lens_function(), I get no joy. In my case, it looks like lens_function() is never even called (as in, I don't get its cout, which is still my lame way of debugging) :) /*virtual*/ LensFunc* lens_function(int mode) const { cout << "custom projection func" << endl; return myLensFunc; } In any case, I was only interested in implementing my own LensNFunc, so it's all good. But I'd be interested in knowing whether lens_function() is meant to work differently, or if it's just not doing what it should be doing. Thanks again, Ivan On Tue, Jul 5, 2011 at 9:23 AM, Jonathan Egstad <jegs...@earthlink.net>wrote: > > However, I seem to be stuck at a very basic stage. How do I pass my own > function to the renderer. Using one of the lens functions you sent as an > example, I'm trying to get that returned > > So, taking this as an example: > > > > /*! Simple perspective projection lens function. */ > > static void myLensFunc(Scene* scene, CameraOp* cam, MatrixArray* > transforms, > > const VArray& in, Vector4& out, > > void* data) { > > out = transforms->matrix(LOCAL_TO_SCREEN).transform(in.PL(), 1.0f); > > } > > > > > > I want lens_function() to return the above for any "mode". Which I'm > naively trying to do like this: > > > > CameraOp::LensFunc* CamTest::lens_function(int mode) const { > > return &myLensFunc; > > } > > > > However, I'm not getting the result I want. Changing the "projection > mode" knob in my CamTest Op still behaves as usual, and seems to use the > right LensFunc for each projection mode, instead of myLensFunc. > > Am I interpreting this wrong? How should I be returning a pointer to my > custom function in lens_function()? > > The renderer *should* be requesting the lens functions directly from the > camera pointer that's put into the Scene structure. Don't forget that > there's a preference in the renderer to override the camera's projection > setting, however in both cases the lens func should be coming from the > camera pointer that's stored in the Scene. > > Unless something has changed in this logic recently it should work... As I > said, at DD we had a custom CameraOp that did exactly this - but then again > the last time I saw it working with my own eyes it was in Nuke version 5.0. > > I'll try it out with my custom StereoCam camera when I get a chance in the > next couple days. > > -jonathan > > > > On Mon, Jun 27, 2011 at 1:20 PM, Jonathan Egstad <jegs...@earthlink.net> > wrote: > > btw, don't worry about clipping the distorted vertices to the screen > bbox, the renderer only worries about clipping to the near-Z plane. The > only time you need to worry about the screen edges is if you're wrapping > around like the spherical projection does. > > > > > > > > On Jun 27, 2011, at 11:15 AM, Ivan Busquets wrote: > > > >> Wow, thanks for the info, Jonathan. I looked at CameraOp::LensNFunc, but > didn't know what to make of it, or where to start, really. So that's exactly > the kind of info I was hoping for. > >> > >> At DD there was a custom 'HypeCamera' that supported the 'Hype' > distortion file format so you could load a Hype file directly into the > camera and it applied the forward distortion via this method. There was > also a 'HypeDistort' geometry modifier that warped a card with the reverse > distortion so you could do a undistort/redistort in a single render/filter > pass. > >> > >> And that's exactly the kind of application I wanted it for. :) > >> > >> Thanks, > >> Ivan > >> > >> > >> On Mon, Jun 27, 2011 at 11:03 AM, Jonathan Egstad < > jegs...@earthlink.net> wrote: > >> So the current scanline renderer does handle general camera distortions > - with poly subdivision memory limitations. > >> > >> The CameraOp class supports several built-in linear projection and > non-linear distortions using its LensFunc/LensNFunc methods that are passed > back to the renderer via the CameraOp::lens_function()/lensNfunction() > virtual methods, then on to the Primitives in the Scene structure for use > during tessellation. > >> > >> You can implement your own LensFunc routines and return them via the > virtual method. The idea is that a primitive can subdivide itself using the > output of a LensFunc by passing in vertex info which gets modified. The > 'void *' parameter at the end is a way to get add'l info from the Primitive > into the lens function. > >> > >> > >> /*! Simple perspective projection lens function. */ > >> static void perspLensFunc(Scene* scene, CameraOp* cam, MatrixArray* > transforms, > >> const VArray& in, Vector4& out, > >> void* data) { > >> out = transforms->matrix(LOCAL_TO_SCREEN).transform(in.PL(), 1.0f); > >> } > >> > >> /*! Simple UV projection lens function. */ > >> static void perspLensFunc(Scene* scene, CameraOp* cam, MatrixArray* > transforms, > >> const VArray& in, Vector4& out, > >> void* data) { > >> out = transforms->matrix(CLIP_TO_SCREEN).transform(in.UV()*2.0f - > Vector4(1,1,1,1)); > >> } > >> > >> The LensNFunc method does the same thing, but operates on arrays of vert > info. > >> > >> At DD there was a custom 'HypeCamera' that supported the 'Hype' > distortion file format so you could load a Hype file directly into the > camera and it applied the forward distortion via this method. There was > also a 'HypeDistort' geometry modifier that warped a card with the reverse > distortion so you could do a undistort/redistort in a single render/filter > pass. > >> > >> > >> Have fun, > >> > >> -jonathan > >> > >> > >> On Jun 26, 2011, at 2:12 PM, Ivan Busquets wrote: > >> > >> > Hi, > >> > > >> > I've been looking at the lens_distortion parameters in CameraOp, and > was wondering if there's any way to implement a different lens > distortion/correction model within a CameraOp, or if one would need to write > a specific renderer to handle that. > >> > > >> > Specifically, I'm looking for a way to handle off-center and > asymmetric distortions. Assuming I can get a function that maps destination > to source vectors(uvs), would this be possible within a CameraOp? > >> > > >> > Many thanks, > >> > Ivan > >> > > >> > > >> > > >> > > >> > > >> > _______________________________________________ > >> > Nuke-dev mailing list > >> > Nuke-dev@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/ > >> > http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-dev > >> > >> _______________________________________________ > >> Nuke-dev mailing list > >> Nuke-dev@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/ > >> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-dev > >> > >> _______________________________________________ > >> Nuke-dev mailing list > >> Nuke-dev@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/ > >> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-dev > > > > > > _______________________________________________ > > Nuke-dev mailing list > > Nuke-dev@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/ > > http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-dev > > > > > > _______________________________________________ > > Nuke-dev mailing list > > Nuke-dev@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/ > > http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-dev > > _______________________________________________ > Nuke-dev mailing list > Nuke-dev@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/ > http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-dev >
_______________________________________________ Nuke-dev mailing list Nuke-dev@support.thefoundry.co.uk, http://forums.thefoundry.co.uk/ http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-dev