You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi all,
I have a hard time understanding the target value of the DOF-effect of r3f Drei.
If I calculate the distance from the camera to the target object in world coordinates in the useFrame() hook and pass it as WorldFocusDistance to the component via a state variable, the DOF works as intended.
const worldTarget = new THREE.Vector3();
const worldCam = new THREE.Vector3();
const [distance, setDistance] = useState(0.0);
useFrame(() => {
dofTarget.current.getWorldPosition(worldTarget); // ref to target object
dofCam.current.getWorldPosition(worldCam); // ref to camera
setDistance(worldCam.z - worldTarget.z);
});
<EffectComposer disableNormalPass>
<DepthOfField worldFocusDistance={distance} bokehScale={6}/>
</EffectComposer>
Trying to achieve the same result with the target property, doesn't achieve any usable results.
I am sure that using the built-in target route would be more performant, but I cannot figure out how to use it correctly on my own. Any help would be appreciated.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi all,
I have a hard time understanding the target value of the DOF-effect of r3f Drei.
If I calculate the distance from the camera to the target object in world coordinates in the useFrame() hook and pass it as WorldFocusDistance to the component via a state variable, the DOF works as intended.
Trying to achieve the same result with the target property, doesn't achieve any usable results.
I am sure that using the built-in target route would be more performant, but I cannot figure out how to use it correctly on my own. Any help would be appreciated.
Beta Was this translation helpful? Give feedback.
All reactions