fresnel.camera¶
Overview
Camera base class. |
|
Orthographic camera. |
|
Perspective camera. |
Details
Cameras.
- class fresnel.camera.Camera(_camera)¶
Bases:
objectCamera base class.
A
Cameradefines the view into theScene.Cameraspace is a coordinate system centered on the camera’s position. Positive x points to the right in the image, positive y points up, and positive z points out of the screen. The visible area in the image plane is centered onlook_atwith the givenheight. The visible width isheight * aspectwhere aspect is the aspect ratio determined by the resolution of the image inTracer(aspect = tracer.w / tracer.h).Cameraspace shares units withScenespace.Cameraprovides common methods and properties for all camera implementations.Cameracannot be used directly, use one of the subclasses.See also
- property basis¶
Orthonormal camera basis.
basisis computed fromposition,look_at, andup. The 3 vectors of the basis define the +x, +y, and +z camera space directions in scene space.- Type:
((3, 3)
numpy.ndarrayofnumpy.float32)
- property look_at¶
The point the camera looks at.
position - look_atdefines the +z direction in camera space.- Type:
((3, )
numpy.ndarrayofnumpy.float32)
- property position¶
Camera position.
- Type:
((3, )
numpy.ndarrayofnumpy.float32)
- property up¶
A vector pointing toward the +y direction in camera space.
The component of
upperpendicular tolook_at - positiondefines the +y direction in camera space.- Type:
((3, )
numpy.ndarrayofnumpy.float32)
- class fresnel.camera.Orthographic(position, look_at, up, height)¶
Bases:
CameraOrthographic camera.
- Parameters:
position ((3, )
numpy.ndarrayofnumpy.float32) – Camera position.look_at ((3, )
numpy.ndarrayofnumpy.float32) – The point the camera looks at (the center of the focal plane).up ((3, )
numpy.ndarrayofnumpy.float32) – A vector pointing toward the +y direction in camera space.height (float) – The height of the image plane.
An orthographic camera traces parallel rays from the image plane into the scene. Lines that are parallel in the
Scenewill remain parallel in the rendered image.positionis the center of the image plane inScenespace.look_atis the point inScenespace that will be in the center of the image. Together, these vectors define the image plane which is perpendicular to the line frompositiontolook_at.upis a vector inScenespace that defines the (+y) direction in the camera space).updoes not need to be perpendicular to the line from position to look_at, but it must not be parallel to that line.heightsets the height of the image sensor inSceneunits. The width isheight * aspectwhere aspect is the aspect ratio determined by the resolution of the image inTracer(aspect = tracer.w / tracer.h).Note
Only objects inside the rectangular cuboid defined by corners of the image sensor and the focal plane (extended to infinite height) will appear in the image.
Objects in front of the image plane will appear in the rendered image, objects behind the plane will not.
Tip
Place the camera
positionoutside the geometry of theScene. Decreaseheightto zoom in and increaseheightto zoom out.- classmethod fit(scene, view='auto', margin=0.05)¶
Fit a camera to a
Scene.Create an orthographic camera that fits the entire height of the scene in the image plane.
- Parameters:
view may be ‘auto’, ‘isometric’, or ‘front’.
The isometric view is an orthographic projection from a particular angle so that the x,y, and z directions are equal lengths. The front view is an orthographic projection where +x points to the right, +y points up and +z points out of the screen in the image plane. ‘auto’ automatically selects ‘isometric’ for 3D scenes and ‘front’ for 2D scenes.
- class fresnel.camera.Perspective(position, look_at, up, focal_length=0.5, focus_distance=10, f_stop=inf, height=0.24)¶
Bases:
CameraPerspective camera.
- Parameters:
position ((3, )
numpy.ndarrayofnumpy.float32) – Camera position.look_at ((3, )
numpy.ndarrayofnumpy.float32) – The point the camera looks at (the center of the focal plane).up ((3, )
numpy.ndarrayofnumpy.float32) – A vector pointing toward the +y direction in camera space.focal_length (float) – Focal length of the camera lens.
focus_distance (float) – Distance to the focal plane.
f_stop (float) – F-stop ratio for the lens.
height (float) – The height of the image plane.
A perspective camera traces diverging rays from the camera position through the image plane into the scene. Lines that are parallel in the
Scenewill converge rendered image.positionis the center of projectionScenespace.look_atis the point inScenespace that will be in the center of the image. Together, these vectors define the image plane which is perpendicular to the line frompositiontolook_at.upis a vector inScenespace that defines the (+y) direction in the camera space).updoes not need to be perpendicular to the line from position to look_at, but it must not be parallel to that line.Note
Only objects inside the rectangular pyramid defined by the position and corners of the image sensor (extended to infinite height) will appear in the image.
Perspectivemodels an ideal camera system with a sensor and a thin lens. The sensor lies in the image plane and is the location where the pixels in the rendered image will be captured.heightsets the height of the sensor inSceneunits. The width isheight * aspectwhere aspect is the aspect ratio determined by the resolution of the image inTracer(aspect = tracer.w / tracer.h).focal_lengthsets the distance betweenpositionand the image plane.Note
The camera
heightshould be small relative to the objects in theScenewith those objects in front of the image plane. If the scene units are decimeters, the defaultheightof 0.24 is 24 mm, the height of a 35 mm camera sensor.Tip
There are two ways to zoom a perspective camera. 1) Move the position of the camera while keeping the focal length fixed. Photographers call this “zooming with your feet” and it maintains a fixed field of view. 2) Increase the
focal_lengthto zoom in or decrease it to zoom out while keeping position fixed. This is the the equivalent of rotating the focal length setting on a zoom lens. Changingfocal_lengthchanges the field of view.Like a digital camera, the
Perspectivecamera must be focused. The focal plane is parallel to the image plane at a distancefocus_distancefrom the cameraposition. Objects on the focal plane will be in sharp focus. Objects in front of and behind the plane will be out of focus. Out of focus areas in an image are called bokeh and can be used to draw the viewer’s attention to the subject that is in clear focus. The space in front of and behind the focal plane that appears to be in focus is the depth of field. Setf_stopto control the amount of depth of field. Small, non-zero values will lead to very little depth of field and a value of inf will extend the depth of field to infinity.Note
There are convenience methods to set the camera parameters:
focus_ontakes a point and computes thefocus_distanceto put that point on the focal plane.depth_of_fieldcomputes thef_stopneeded to achieve a given depth of field.vertical_field_of_viewcomputes thefocal_lengthneeded to achieve a given field of view angle.
Tip
The default
heightof 0.24 works well for scene objects that are size ~1 or larger. If the typical objects in your scene are much smaller, adjustheightby an appropriate fraction.- property depth_of_field¶
The distance about the focal plane in sharp focus.
The area of sharp focus extends in front and behind the focal plane. The distance between the front and back areas of sharp focus is the depth of field.
The depth of field is a function of
focus_distance,focal_length,f_stop, andheight.Setting
depth_of_fieldcomputesf_stopto obtain the desired depth of field as a function offocus_distance,focal_length, andheight.Note
depth_of_fielddoes not remain fixed after setting it.- Type:
- property f_stop¶
F-stop ratio for the lens.
Set the aperture of the opening into the lens in f-stops. This sets the range of the scene that is in sharp focus. Smaller values of
f_stopresult in more background blur.Tip
Use
depth_of_fieldto set the range of sharp focus inScenedistance units.- Type:
- property focal_length¶
Focal length of the camera lens.
The focal length relative to the image
heightsets the field of view. Given a fixedheight, a largerfocal_lengthgives a narrower field of view.Tip
With the default height of 0.24, typical focal lengths range from .18 (wide angle) to 0.5 (normal) to 6.0 (telephoto).
See also
- Type:
- property focus_distance¶
Distance to the focal plane.
The focus distance is the distance from the camera position to the center of focal plane.
- Type:
- property focus_on¶
A point in the focal plane.
The area of sharp focus extends in front and behind the focal plane.
The focal plane is a function of
focus_distance,position, andlook_at.Setting
focus_oncomputesfocus_distanceso that the given point is on the focal plane.Note
focus_ondoes not remain fixed after setting it.- Type:
(3, )
numpy.ndarrayofnumpy.float32)
- property vertical_field_of_view¶
Vertical field of view.
The vertical field of view is the angle (in radians) that the camera covers in the +y direction. It is a function of
focal_lengthandheight.Setting
vertical_field_of_viewcomputesfocal_lengthto achieve the given field of view.Note
vertical_field_of_viewdoes not remain fixed after setting it.- Type: