Focus on object

   25786   19   2
User Avatar
Member
184 posts
Joined: March 2015
Offline
Hi,

I have got a really silly question but I couldnt figure it out yet. I want the camera to stay focused on a specific object, even if the object or the cam is moving. Is there an easy one-klick solution?
User Avatar
Staff
5212 posts
Joined: July 2005
Offline
It's not exactly one click, but there's a Look At parameter on the Camera object. Select the object that you want to look at and it'll do the rest. It won't auto-frame the object, though.
User Avatar
Member
184 posts
Joined: March 2015
Offline
Hey,

and this will set the focus sweet spot automatically onto the object?
User Avatar
Member
59 posts
Joined: May 2015
Offline
twod
It's not exactly one click, but there's a Look At parameter on the Camera object. Select the object that you want to look at and it'll do the rest. It won't auto-frame the object, though.

What if I want to control the focus but I don't want to change camera's constraint?

In other words, I still want to control cam pos, rot, without pointing at any particular object in the scene, but I do want to control the focus distance (as if I were changing focus on my camera using the lens' focusing ring).

An example for this comes from Blender:
Andrew
Houdini Apprentice
User Avatar
Staff
3464 posts
Joined: July 2005
Offline
on the Sampling Tab of the camera object there is a parameter called Focus Distance
NOTE - this will only work when you have Depth of Field turned ON

if you select the camera and hit Enter in the viewport you'll get the handles for the camera, then use the “z” hotkey
now you'll have a little square thingy and two arrow thingys
move the square thingy to the distance you want to focus and the arrows to narrow the depth of field

I made a little file to show you one way to have more control over the two main parameters you need to adjust to have focus track an object

I built a geometry object and inside I merged in the camera origin and the center point of a null object
I made a poly line with those two points and the measured it's length
I then used a prim() function on the Focus Distance Parameter of cam1

now I can place the null object - called “focus_target” anywhere in the scene and that will drive the focal distance…which doesn't seem all that great…but if you unparent the null from the camera it can now become a child of anything in your scene…and if it's a moving object the focal distance will update as needed.

the other parameter you need to adjust is the F-Stop - large values mean a deep focal distance, small values mean a very tight range that will be in focus.

in the ropnet the mantra node has Enable Depth of Field turned ON.

you can make this way better of course…but it's something to play with

and you should check this out:
https://www.youtube.com/watch?v=01UlqkRRcgQ [youtube.com]

HTH

Attachments:
focus_distance.0.hipnc (794.1 KB)

Michael Goldfarb | www.odforce.net
Training Lead
SideFX
www.sidefx.com
User Avatar
Member
184 posts
Joined: March 2015
Offline
lol, that much effort for a focus track In other software packages you just have to drag and drop the tracking object in a slot. As much as I love Houdini, some simple things should just be easy. But thanks for the answer!
User Avatar
Member
59 posts
Joined: May 2015
Offline
Thank you so much Michael,

great setup and good to know this is possible with Houdini.

Thanks for the detailed explanation.

Cheers
Andrew
Houdini Apprentice
User Avatar
Member
8832 posts
Joined: July 2007
Offline
you can just put following expression to Focus Distance parm without any extra steps
vlength(vtorigin(“.”, “../focus_target”))
it will measure world space distance from camera to focus object (in this case named focus_target in the same level as camera)
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
59 posts
Joined: May 2015
Offline
tamte
you can just put following expression to Focus Distance parm without any extra steps
vlength(vtorigin(“.”, “../focus_target”))
it will measure world space distance from camera to focus object (in this case named focus_target in the same level as camera)

Thanks,

that's very handy!
Andrew
Houdini Apprentice
User Avatar
Member
184 posts
Joined: March 2015
Offline
Thanks, thats great!
User Avatar
Member
1 posts
Joined: Sept. 2013
Offline
So long story short, there is no Maya F type function? You all are going on and on about coding F stops and random stuff but it's really a simple question. Can you focus the camera on something or not?
User Avatar
Staff
3464 posts
Joined: July 2005
Offline
Matt Slanchik
So long story short, there is no Maya F type function? You all are going on and on about coding F stops and random stuff but it's really a simple question. Can you focus the camera on something or not?

this thread is about a camera's focus - not what applications refer to as ‘focus’
if you want to snap the camera view to a selected Object - use ‘f’
Michael Goldfarb | www.odforce.net
Training Lead
SideFX
www.sidefx.com
User Avatar
Member
709 posts
Joined: Feb. 2017
Offline
Hey Everybody,

vlength(vtorigin(“.”, “../focus_target”))

this method is not working in houdini 16 anymore. Can somebody give me the right vex/expression that i can put into Focus Distance to focus on an object?

Thank you!
Cheers
CYTE
User Avatar
Member
57 posts
Joined: Jan. 2015
Offline
this seems to work in 16, but I'm not sure it's the best way

distance(ch(“tx”),ch(“ty”),ch(“tz”),ch(“../CameraTarget/tx”),ch(“../CameraTarget/ty”),ch(“../CameraTarget/tz”))

Chris
User Avatar
Member
2 posts
Joined: July 2017
Offline
CYTE
vlength(vtorigin(“.”, “../focus_target”))
It's still working but the comma needs to be in ascii (").
The correct code is

vlength(vtorigin(".", "../focus_target"))

Edit by ndickson: Fixed forum text formatting
Edited by videlam - Nov. 16, 2017 06:48:49
User Avatar
Member
709 posts
Joined: Feb. 2017
Offline
Hey videlam,
wow thank you!
User Avatar
Member
2 posts
Joined: July 2017
Offline
I made a script to create a null and set the focus on it.
On the shelf, create a new tool and copy/paste the code

import toolutils
scene_viewer = toolutils.sceneViewer()
selected_objects = scene_viewer.selectObjects("Select a camera and press Enter",allowed_types = ["cam"])
object = hou.selectedNodes()
netparent = object[0].parent()
selectname = str (object[0])
focus_obj = netparent.createNode("null", selectname+'_focus_target')
d_focus=('vlength(vtorigin(".", "../'+str(focus_obj)+'"))')
hou.parm('/obj/'+selectname+'/focus').setExpression(str(d_focus))
User Avatar
Member
280 posts
Joined: Aug. 2018
Online
This vector length to focus distance expression works fine in SOP's - but can anyone provide a step by step method of getting this to work in Solaris?
User Avatar
Member
1 posts
Joined: April 2021
Offline
I have the same issue, with not getting it to work in Solaris. Any help appreciated.
User Avatar
Member
1 posts
Joined: Aug. 2018
Offline
Hi,

I realise this is rather late but I've found videlam's bit of code really useful for creating a focus object for Karma.

I too wanted to get use it in solaris and having watched some of solaris essentials

https://www.sidefx.com/solaris-essentials-lops-karma-matx/ [www.sidefx.com]

I realised a way - use the code above to create your focus object and then when you go to solaris use stage or create a lopnetwork, then use scene import(all) for your whole scene or scene import (camera) import to bring in your camera - and it will include the focus distance to the object. If you go back to object context and fiddle around with the focus object - back in solaris it will update. It works animating the focus object for focus pulls etc.

This is probably really obvious to seasoned users but as someone who has just started experimenting with Karma it is not. As this topic is what I found when searching for karma focus object it might be one other people's first result.

Hope that helps someone.
  • Quick Links