Stefan Lemme
Computer Graphics
- Camera Transformation -
Computer Graphics - Camera Transformation - Stefan Lemme Overview - - PowerPoint PPT Presentation
Computer Graphics - Camera Transformation - Stefan Lemme Overview Last time Affine space , , Projective space set of lines through origin , , , = ,
β Affine space π©, πΎ,β β Projective space πΈπ β
π¦ π₯ , π§ π₯ , π¨ π₯ , 1
β Normalized homogeneous coordinates
β Affine transformations β Basic transformations
β Transforming normals
ππ¦π¦ ππ¦π§ ππ¦π¨ ππ¦ ππ§π¦ ππ§π§ ππ§π¨ ππ§ ππ¨π¦ ππ¨π§ ππ¨π¨ ππ¨ 1
β How to use affine transformations
β Camera transformations
β Object vertex positions β Can be hierarchically nested in each other (scene graph, transf. stack)
β Scene composition and object placement
β Illumination can be computed in this space
4
T_root //Position of the character in world T_ShoulderR //Right shoulder position T_ShoulderRJoint //Shoulder rotation <== User T_UpperArmR //Elbow position T_ElbowRJoint //Elbow rotation <== User T_LowerArmR //Wrist position T_WristRJoint //Wrist rotation <== User ... //Hand and fingers... T_ShoulderL //Left shoulder position T_ShoulderLJoint //Shoulder rotation <== User T_UpperArmL //Elbow position T_ElbowLJoint //Elbow rotation <== User T_LowerArmL //Wrist position ...
β Group objects hierarchically β Local coordinate system is relative to parent coordinate system β Apply transformation to the parent to change the whole sub-tree (or sub-graph)
π + π’ π π π
π + π’ π π π
def transform(T,M)
foreach p in T q = M*p
return out transform(T,M).intersect(ray)
π + π’ π πβ1 π
def intersect(obj,ray) Minv = obj.M.inverse() N = obj.M.normalTransform() local_ray = transform(ray,Minv) hit = obj.intersect(local_ray) global_hit.point = transform(hit.point,M) global_hit.normal = transform(hit.normal,N) return global_hit
T_root T_ShoulderR T_ShoulderRJoint T_UpperArmR T_ElbowRJoint T_LowerArmR T_WristRJoint ... T_ShoulderL T_ShoulderLJoint T_UpperArmL T_ElbowLJoint T_LowerArmL ...
apply+push πβ1 pop apply+pop π, π
π1 π
π2 π3 π4
β Coordinates relative to camera position & direction
β Illumination can also be done in that space
β After perspective transformation, rectilinear, in 0,1 3 β Normalization to view frustum, rasterization, and depth buffer β Shading executed here (interpolation of color across triangle)
β 2D transformation to place image in window on the screen
β typical for rasterization
12
z y x z y x
local world view viewing transformation
camera x y z x y z device x y screen projective transformation parallel projection perspective projection
z y x
world view viewing transformation
β Center of projection
β Optical axis: view-plane normal (VPN) β View up vector (VUP)
β Translation π βπππ β Rotation π π£, π :
π¨
π§, π¨ PRP VPN VUP
z y x
camera x y z
β Screen window
β Focal length π
π¨
β FOV
β Shear to move CW to center β Hπ¦π§ β
π·π
π¦
π , β π·π
π§
π
= 1 β
π·π
π¦
π
1 β
π·π
π§
π
1 1
CW π₯ β π
camera x y z
β Near/Far planes
β Frustrum boundaries open at 45β
2π π₯ , 2π β , 1
=
2π π₯ 2π β
1 1
β Far plane at π¨ = β1
1 πΊ , 1 πΊ , 1 πΊ = 1 πΊ 1 πΊ 1 πΊ
1 π π F
x y z x y z device projective transformation
x y z x y z ππ¦, ππ§, π β1 , 1 π¦, π§, ? , 1 π¦, π§, π¨, 1 π¦ βπ¨ , π§ βπ¨ , ? , 1 π¦, π§, ?β βπ¨, βπ¨
β From canonical perspective viewing frustum (= cone at origin around -Z-axis) to regular box [-1 .. 1]2 x [0 .. 1]
β Lines through the origin are mapped to lines parallel to the Z-axis
β Do not change X and Y additively (first two rows stay the same) β Set W to βz so we divide when converting back to 3D
β π = 1 1 π΅ πΆ π· πΈ β1 β Note: Perspective projection = perspective transformation + parallel projection
Still unknown 45Β° (-1, 1)
(-1, -1)
x y z x y z ? , ? , β1,1 Far: Near: ? , ? , β1,1 ? , ? , βπ, 1 β1 βπ = β π πΊ 0,0,0,1
β No shear of Z with respect to X and Y
β Mapping of two known points
β n = near / far (due to previous scaling by 1/far)
β 0,0, β1, 1 π = π 0,0, β1,1 π and (0,0,0,1)=P(0,0,βn,1)
β π = 1 1
1 1βπ π 1βπ
β1 β Transform Z non-linearly (in 3D)
π¨+π π¨(1βπ)
45Β°
x y z device x y screen parallel projection ππππ πππππ = 1 2 1 2 1 2 1 2 1
β Formally scaling in Z with factor 0 β Typically maintains Z in [0,1] for depth buffering
β Scaling (by 1/2 in X and Y) and translation (by (1/2,1/2))
β Delivers normalized device coordinates
1 2 1 2 1 2 1 2
0 or 1 1
β Scaling matrix to map to entire window on screen
β Some formats have origin at bottom left, some at top left β Needs additional translation
β Positioning on the screen
β Origin at upper left or lower left
β Bring near clipping plane into the origin
β π
π = ππ¦π§π¨π ππππ = 2 π₯πππ’β 2 βπππβπ’ 1 πππ βππππ
1 1 1 1 near 1
β Perspective Projection
πππππ π = ππ ππ‘π’ππ ππ ππ‘π’ππ ππππ πππππ π πππ π‘π ππππ ππ¦π§ πΌπ¦π§ π π
β Orthographic Projection
πππππ π = ππ ππ‘π’ππ ππ ππ‘π’ππ ππππ πππππ ππ¦π§π¨ π ππππ πΌπ¦π§π π
β Other literature uses different conventions
β [-1 .. 1]3 versus [0 ..1]3 versus ...
β ... β Results in different transformation matrices β so be careful !!!
β 3D: normalized [-1 .. 1]3 or [-1 .. 1]2 x [0 .. -1] β Clipping β Parallel projection
β Translation and scaling
β Where is the origin?
β Viewport transformation
β 2D: units in pixels [0 .. xres-1, 0 .. yres-1]
β Hierarchical modeling
β Each stack can be independently pushed/popped β Matrices can be applied/multiplied to top stack element
β Arbitrary matrices as attributes to vertex shaders that apply them as they wish (later) β All matrix stack handling must now be done by application
β Modeling transformations AND viewing transformation β No explicit world coordinates
β Simple specification
β Transformation provided by app, applied by vertex shader β Vertex or Geometry shader must output clip space vertices
β glViewport(x, y, width, height) β Now can even have multiple viewports
β Controlling the depth range (after Perspective transformation)
π π = π¦ π β π¦ = ππ π
f g r x
ο Theoretical (non-physical) model ο Sharp image everywhere ο Infinite depth of field ο Infinitely dark image in reality ο Diffraction effects in reality
f g b a r οs Lens formula defines reciprocal focal length (focus distance from lens of parallel light)
1 π = 1 π + 1 π π = ππ π β π
Object center at distance g is in focus at
πβ² = π π β π π β π β π
Object front at distance g-r is in focus at
Lens focuses light from given position on object through finite-size aperture onto some location of the film plane, i.e. create sharp image.
f
b a οe bβ
Ξπ = π 1 β π πβ²
Circle of confusion (CoC)
Ξπ‘ > Ξπ
Sharpness criterion based
Depth of field (DOF)
π < πΞπ‘ π β π ππ + Ξπ‘ π β π β π ~ 1 π
The smaller the aperture, the larger the depth of field DOF: Defined radius r, such that CoC smaller than βs οs
β Depth-of-field β Lens distortion β Aberrations β Vignetting β Flare β β¦
up forward
β r = sqrt(sscx^2 + sscy^2) β Ο = atan2(sscy, sscx)
β Equi-angular mapping β ΞΈ = r * fov / 2 (inclination angle) β Ο = Ο
β x = sin ΞΈ cos Ο β y = sin ΞΈ sin Ο β z = cos ΞΈ
β Equi-angular mapping β ΞΈ = sscy * fovy / 2 (elevation angle) β Ο = sscx * fovx / 2
β x = cos ΞΈ cos Ο β y = cos ΞΈ sin Ο β z = sin ΞΈ
up forward