Announcement

Collapse
No announcement yet.

VRay Physical Camera FOV

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • VRay Physical Camera FOV

    What is the equation for the FOV of a VRay Physical camera that takes into account focal distance? It seems to be a completely arbitrary function unique to VRay.

    There must be an equation since the Max viewport cameras match. I'm getting a lot of requests to add VRay support to a script I wrote but I can't help them unless Chaosgroup helps me with this problem. Help me help your customers.

    The current work around I'm telling everyone to use is to convert to perspective view from the VRay Camera and then hit CTRL+C to create a max camera and then manually record the FOV or focal length from the max camera. This however obviously doesn't work if they shift their focal distance during the shot or zoom.
    Gavin Greenwalt
    im.thatoneguy[at]gmail.com || Gavin[at]SFStudios.com
    Straightface Studios

  • #2
    The actual formula is somewhat complicated, but you can use this script to set the VRayPhysicalCamera in the current active viewport to a specified FOV value:
    Code:
    fn setFOV f = (
    	cam=getActiveCamera()
    	
    	left=0.001
    	right=100
    	
    	middle=(left+right)*0.5
    	cam.focal_length=middle
    	redrawViews()
    	
    	curFov=getViewFOV()
    	while abs(f-curFov)>0.00001 do (
    			if (f>curFov) then right=middle
    			else left=middle
    			
    			middle=(left+right)*0.5
    			cam.focal_length=middle
    			redrawViews()
    			curFov=getViewFOV()
    	)
    )
    Best regards,
    Vlado
    I only act like I know everything, Rogers.

    Comment


    • #3
      Thanks for the quick reply but I actually need to go in the opposite direction in this instance in order to match a camera in the The Foundry's Nuke to the VRay Physical camera.
      Gavin Greenwalt
      im.thatoneguy[at]gmail.com || Gavin[at]SFStudios.com
      Straightface Studios

      Comment


      • #4
        Hm, getViewFOV() gives you exactly that, no?

        Best regards,
        Vlado
        I only act like I know everything, Rogers.

        Comment


        • #5
          Well that's a much better work around. But it only works if the camera is in an active viewport.

          I prefer not to tamper with a user's viewport layout if at all possible.
          Gavin Greenwalt
          im.thatoneguy[at]gmail.com || Gavin[at]SFStudios.com
          Straightface Studios

          Comment


          • #6
            It is true, but I don't have another work-around for the moment. The FOV depends on many things, distortion among them too. It's possible to derive the exact formula, but I have to do more digging.

            Best regards,
            Vlado
            I only act like I know everything, Rogers.

            Comment


            • #7
              For those who are curious the equation is actually very simple.

              Max_Focal_Length = (Focus_Distance)(Focal_Length)/(Focus_Distance-Focal_Length)
              Gavin Greenwalt
              im.thatoneguy[at]gmail.com || Gavin[at]SFStudios.com
              Straightface Studios

              Comment


              • #8
                Oh an important disclaimer for that function is that it assumes everything is in millimeters. Here is some example code:

                tempDType = units.DisplayType
                tempDMType = units.MetricType

                units.DisplayType = #metric
                units.MetricType = #millimeters

                if selCam.specify_focus==true then (focDist = units.formatValue (selCam.focus_distance)) else (focDist = units.formatValue (selCam.target_distance))

                units.MetricType = tempDMType
                units.DisplayType = tempDType

                focDist = (substring focDist 1 (focDist.count-2)) as float

                NukeEm.f_length = ((focDist*selCam.focal_length)/(focDist - selCam.focal_length))*(selCam.zoom_factor)
                Gavin Greenwalt
                im.thatoneguy[at]gmail.com || Gavin[at]SFStudios.com
                Straightface Studios

                Comment


                • #9
                  Thanks for sharing

                  Best regards,
                  Vlado
                  I only act like I know everything, Rogers.

                  Comment


                  • #10
                    Hi,
                    this thread has already been very helpful but I need some more
                    clarification.


                    I have a standard camera and would like to create an identical VRay Camera.

                    To match the VrayCam's fov to the standard's one works perfectly with
                    the "fn setFOV f" code that Vlado posted (which utilises the
                    getViewFOV() command).

                    Now I would like to calculate that same focal length for the Vray Cam
                    with the equations posted.



                    Let's say I want to match a Standard Camera with a fov of 43.603
                    (horizontal); then I get with the "setFOV 43.603 " function a focal
                    length of 44.0683 for the Vray Cam. With that value the Vray Cam matches
                    perfectly the standard cam.

                    But if I use the following code, I get to an focal length of 46.2849,
                    which doesn't match.
                    /* Oh an important disclaimer for that function is that it assumes
                    everything is in millimeters. Here is some example code: */

                    selCam = $Camera01_VPC
                    /*--> This is the VRayCam that's supposed to match to another standard one*/


                    tempDType = units.DisplayType
                    tempDMType = units.MetricType

                    units.DisplayType = #metric
                    units.MetricType = #millimeters

                    if selCam.specify_focus==true then (
                    focDist = units.formatValue(selCam.focus_distance)
                    ) else (
                    focDist = units.formatValue(selCam.target_distance)
                    )

                    units.MetricType = tempDMType
                    units.DisplayType = tempDType

                    focDistStr = (substring focDist 1 (focDist.count-2))

                    focDistStr = substitutestring focDistStr "," "."
                    focDist = focDistStr as float
                    format "focDist %\n" focDist

                    /*Max_Focal_Length =
                    (Focus_Distance)(Focal_Length)/(Focus_Distance-Focal_Length)*/

                    Max_Focal_Length =
                    (focDist*(selCam.Focal_Length))/(focDist-selCam.Focal_Length)
                    format "Max_Focal_Length %\n" Max_Focal_Length

                    Is the code correct like this? Where is the problem?

                    thanks,
                    Lena

                    Comment

                    Working...
                    X