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. :stuck_out_tongue:

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.

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:

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

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.

Hm, getViewFOV() gives you exactly that, no?

Best regards,
Vlado

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.

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

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

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

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)

Thanks for sharing :slight_smile:

Best regards,
Vlado

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