computer graphics
play

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 , , , = ,


  1. Computer Graphics - Camera Transformation - Stefan Lemme

  2. 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 π‘ˆ

  3. Overview β€’ Today – How to use affine transformations β€’ Coordinate spaces β€’ Hierarchical structures – Camera transformations β€’ Camera specification β€’ Perspective transformation

  4. 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

  5. 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 ...

  6. 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)

  7. Ray-tracing Transformed Objects β€’ Ray (world coordinates) β€’ π‘ˆ – set of triangles (local coordinates) β€’ 𝑁 – transformation matrix (local-to-world) 𝑝 + 𝑒 𝑒 𝑁 π‘ˆ

  8. 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) 𝑝 + 𝑒 𝑒 𝑁 π‘ˆ

  9. 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 π‘ˆ

  10. 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 ...

  11. 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

  12. 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

  13. Coordinate Systems y x z y view viewing transformation x world local z

  14. Coordinate Systems y y y x x x z z screen camera device parallel projection projective transformation perspective projection

  15. 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

  16. 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

  17. 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

  18. Projective Transformation y y x x z z device projective transformation

  19. Perspective Transformation πœ‡π‘¦, πœ‡π‘§, πœ‡ βˆ’1 , 1 𝑦, 𝑧, ? , 1 y y x x z z βˆ’π‘¨ , 𝑧 𝑦 𝑦, 𝑧, 𝑨, 1 βˆ’π‘¨ , ? , 1 𝑦, 𝑧, ?β‹… βˆ’π‘¨, βˆ’π‘¨

  20. 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

  21. Perspective Transformation y y x x z z Far: βˆ’1 ? , ? , βˆ’1,1 ? , ? , βˆ’1,1 βˆ’π‘œ = βˆ’ 𝑂 Near: ? , ? , βˆ’π‘œ, 1 0,0,0,1 𝐺

  22. 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βˆ’π‘œ)

  23. 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

  24. 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

  25. 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

  26. 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