Computer Graphics - Camera Transformation - Stefan Lemme
Overview β’ Last time β Affine space π©, πΎ,β β Projective space πΈ π β β’ set of lines through origin π¦ π§ π¨ β’ π¦, π§, π¨, π₯ = ππ¦, ππ§, ππ¨, ππ₯ = π₯ , π₯ , π₯ , 1 β Normalized homogeneous coordinates β’ Points π¦, π§, π¨, 1 β’ Vectors π¦, π§, π¨, 0 π π¦π¦ π π¦π§ π π¦π¨ π π¦ β Affine transformations π π§π¦ π π§π§ π π§π¨ π π§ π π¨π¦ π π¨π§ π π¨π¨ π π¨ 0 0 0 1 β Basic transformations β’ Translation, Scaling, Reflection, Shearing, Rotation β Transforming normals β’ π = π β1 π
Overview β’ Today β How to use affine transformations β’ Coordinate spaces β’ Hierarchical structures β Camera transformations β’ Camera specification β’ Perspective transformation
Coordinate Systems β’ Local (object) coordinate system (3D) β Object vertex positions β Can be hierarchically nested in each other (scene graph, transf. stack) β’ World (global) coordinate system (3D) β Scene composition and object placement β’ Rigid objects: constant translation, rotation per object, (scaling) β’ Animated objects: time-varying transformation in world-space β Illumination can be computed in this space 4
Hierarchical Coordinate Systems β’ Hierarchy of transformations 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 ...
Hierarchical Coordinate Systems β’ Used in Scene Graphs β 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)
Ray-tracing Transformed Objects β’ Ray (world coordinates) β’ π β set of triangles (local coordinates) β’ π β transformation matrix (local-to-world) π + π’ π π π
Ray-tracing Transformed Objects β’ Option 1: transform the triangles def transform(T,M) out = {} foreach p in T q = M*p out.insert(q) out.rebuildIndexStructure() return out transform(T,M).intersect(ray) π + π’ π π π
Ray-tracing Transformed Objects β’ Option 2: transform the ray 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 π + π’ π π β1 π
Ray-tracing through a Hierarchy T_root T_ShoulderR apply+push π β1 T_ShoulderRJoint T_UpperArmR T_ElbowRJoint T_LowerArmR T_WristRJoint pop ... T_ShoulderL T_ShoulderLJoint T_UpperArmL apply+pop π, π T_ElbowLJoint T_LowerArmL ...
Instancing β’ π β set of triangles β’ local coordinates β’ memory β’ π π β transformation matrices β’ local-to-world β’ Multiple rendered objects β’ Correct lighting, shadows, etc... β’ Never βmaterializedβ in memory π 2 π 1 π 3 π π 4
Coordinate Systems β’ Local (object) coordinate system (3D) β’ World (global) coordinate system (3D) β’ Camera/view/eye coordinate system (3D) β Coordinates relative to camera position & direction β’ Camera itself specified relative to world space β Illumination can also be done in that space β’ Normalized device coordinate system (2.5D) β After perspective transformation, rectilinear, in 0,1 3 β Normalization to view frustum, rasterization, and depth buffer β Shading executed here (interpolation of color across triangle) β’ Window/screen (raster) coordinate system (2D) β 2D transformation to place image in window on the screen Goal: Transform objects from local to screen β typical for rasterization 12
Coordinate Systems y x z y view viewing transformation x world local z
Coordinate Systems y y y x x x z z screen camera device parallel projection projective transformation perspective projection
Viewing Transformation β’ External (extrinsic) camera parameters β Center of projection β’ projection reference point (PRP) y β Optical axis: view-plane normal (VPN) VUP β View up vector (VUP) x z β’ Needed Transformations PRP y β Translation π βπππ β Rotation π π£, π : view β’ πππ β₯ β π¨ VPN β’ πππ β Span π§, π¨ viewing transformation x world z
Viewing Transformation β’ Internal (intrinsic) camera parameters β Screen window π₯ β’ center of the window (CW) CW β’ width, height β β Focal length π β’ projection plane distance along β π¨ β FOV π β’ Instead of π y β’ CW in the center β’ vertical/horizontal β’ aspect ratio x β’ Needed Transformations β Shear to move CW to center π·π π¦ 1 0 β 0 π z π·π π·π π·π π§ π§ β H π¦π§ β π¦ 0 1 β 0 π , β = camera π π 0 0 1 0 0 0 0 1
Viewing Transformation β’ Internal (intrinsic) camera parameters β Near/Far planes F β’ π, πΊ β’ Render only objects between Near and Far β’ Normalization Transformations β Frustrum boundaries open at 45 β π 2π 0 0 0 y π₯ π 2π 2π 2π β’ π 0 0 0 π₯ , β , 1 = β x 0 0 1 0 0 0 0 1 β Far plane at π¨ = β1 1 0 0 0 πΊ z 1 0 0 0 1 1 1 β’ π πΊ , πΊ , πΊ = camera πΊ 1 0 0 0 πΊ 0 0 0 1
Projective Transformation y y x x z z device projective transformation
Perspective Transformation ππ¦, ππ§, π β1 , 1 π¦, π§, ? , 1 y y x x z z βπ¨ , π§ π¦ π¦, π§, π¨, 1 βπ¨ , ? , 1 π¦, π§, ?β βπ¨, βπ¨
Perspective Transformation β’ Perspective transformation β From canonical perspective viewing frustum (= cone at origin around -Z-axis) to regular box [-1 .. 1] 2 x [0 .. 1] β’ Mapping of X and Y β Lines through the origin are mapped to lines parallel to the Z-axis β’ xΒ΄= x/-z and yΒ΄= y/-z (coordinate given by slope with respect to z!) β 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 β’ Determines last row (-1, 1) 45Β° β’ Perspective transformation 1 0 0 0 0 1 0 0 -z β π = π΅ πΆ π· πΈ Still unknown (-1, -1) 0 0 β1 0 β Note: Perspective projection = perspective transformation + parallel projection
Perspective Transformation y y x x z z Far: β1 ? , ? , β1,1 ? , ? , β1,1 βπ = β π Near: ? , ? , βπ, 1 0,0,0,1 πΊ
Perspective Transformation β’ Computation of the coefficients A, B, C, D β No shear of Z with respect to X and Y β’ A = B = 0 β Mapping of two known points β’ Computation of the two remaining parameters C and D β n = near / far (due to previous scaling by 1/far) β’ Following mapping must hold 0,0, β1, 1 π = π 0,0, β1,1 π and β (0,0,0,1)=P(0,0,βn,1) β’ Resulting Projective transformation 1 0 0 0 45Β° 0 1 0 0 β π = 1 π 0 0 1βπ 1βπ 0 0 β1 0 -z β Transform Z non-linearly (in 3D) 0 -1 -n -1 π¨+π β’ έ β²= β π¨(1βπ)
Projection to Screen y y x x z screen device 1 1 parallel projection 0 0 2 2 1 1 π πππ πππππ = 0 0 2 2 0 0 0 0 0 0 0 1
Parallel Projection to 2D β’ Parallel projection to [-1 .. 1] 2 β Formally scaling in Z with factor 0 β Typically maintains Z in [0,1] for depth buffering β’ As a vertex attribute (see OpenGL later) β’ Transformation from [-1 .. 1] 2 to NDC ([0 .. 1] 2) β Scaling (by 1/2 in X and Y) and translation (by (1/2,1/2)) β’ Projection matrix for combined transformation β Delivers normalized device coordinates 1 1 0 0 2 2 1 1 0 0 β’ π πππ πππππ = 2 2 0 0 0 or 1 0 0 0 0 1
Viewport Transformation β’ Scaling and translation in 2D β Scaling matrix to map to entire window on screen β’ π π ππ‘π’ππ (π¦π ππ‘, π§π ππ‘) β’ No distortion if aspects ration have been handled correctly earlier β’ Sometime need to reverse direction of y β Some formats have origin at bottom left, some at top left β Needs additional translation β Positioning on the screen β’ Translation π π ππ‘π’ππ (π¦πππ‘, π§πππ‘) β’ May be different depending on raster coordinate system β Origin at upper left or lower left
Orthographic Projection β’ Step 2a: Translation (orthographic) β Bring near clipping plane into the origin β’ Step 2b: Scaling to regular box [-1 .. 1] 2 x [0 .. -1] β’ Mapping of X and Y 2 0 0 0 π₯πππ’β 1 0 0 0 2 0 0 0 0 1 0 0 β π π = π π¦π§π¨ π ππππ = βπππβπ’ 0 0 1 near 1 0 0 0 0 0 0 1 πππ βππππ 0 0 0 1
Recommend
More recommend