1 / 27

2009 Graphics : project 1 based on DX9 basics

note. 2009 Graphics : project 1 based on DX9 basics. Documented by Dongjoon Kim SNU CS Ph.D Course Student Contact : dojo@cglab.snu.ac.kr. REQUIREMENTS. Requirements for Project1 based on DX9. 1. 3D Space Transformation (Closed in Projection Space) 2. Camera Control in WS

flint
Download Presentation

2009 Graphics : project 1 based on DX9 basics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. note 2009 Graphics : project 1 based on DX9 basics . Documented by Dongjoon Kim SNU CS Ph.D Course Student Contact : dojo@cglab.snu.ac.kr

  2. REQUIREMENTS

  3. Requirements for Project1 based on DX9 • 1. 3D Space Transformation (Closed in Projection Space) • 2. Camera Control in WS • 3. Shader model 3.0 (HLSL) • 4. Render To Texture and Its Texture Mapping ( Read-back Techniques ) • 5. Phong-based Illumination REQUIREMENTS

  4. 3D SPACE TRANSFORMATION

  5. Projective Space • Space and Transformation Matrix • 1. Transformation in Projection Space(3D) can be defined by 4x4 matrix • 2. DX API defines row major matrix and vector. • - mat1~3 = mat1*mat2*mat3 3D SPACE TRANSFORMATION Affine Space x1 y1 z1 p1 x2 y2 z2 p2 x3 y3 z3 p3 t1 t2 t3 1 Linear Transform Rigid Space Linear Space Projection Shear Scale Translation Rotation Translation Perspective TR

  6. Transformation : 3D Space Definition for the Scene 3D SPACE TRANSFORMATION Object Space World Space Viewing Space Projection Space Window Space

  7. Transformation : 3D Space Definition for the Scene 3D SPACE TRANSFORMATION z • Object Designer's Space • Coordinate system and unit are defined by the Designer Object Space World Space x Viewing Space Projection Space y Window Space

  8. Transformation : 3D Space Definition for the Scene 3D SPACE TRANSFORMATION • Scene Stage • Objects and Camera(Eye) and Light resources Object Space World Space Viewing Space Projection Space Window Space

  9. Transformation : 3D Space Definition for the Scene ( D3DX ) 3D SPACE TRANSFORMATION Object Space Viewing Space World Space World Space Viewing Space Projection Space • Camera(Eye)-Origin Coordinate System • Unit is same as WS's one • Use 'D3DXMatrixLookAtLH(…)’ Window Space

  10. Transformation : 3D Space Definition for the Scene ( D3DX ) 3D SPACE TRANSFORMATION Viewing Space Object Space World Space view frustum Projection Space Viewing Space (1, 1, 1) z Normalized view frustum Projection Space (-1, -1, 0) • Normalized Viewing Space • Clipping and Depth Test • Use 'D3DXMatrixPerspectiveLH(…)' or Orthogonal Window Space

  11. Transformation : 3D Space Definition for the Scene ( D3DX ) 3D SPACE TRANSFORMATION Object Space Normalized view frustum World Space X MinZ Projection Space x (pix) Y Window Space MaxZ Viewing Space (1, 1, 1) Y X x (pix) z Height Height View Port Projection Space (-1, -1, 0) Width z (0.f~1.f) y (pix) Width y (pix) Window Space typedef struct D3DVIEWPORT9 { DWORD X, Y; DWORD Width, Height; float MinZ, MaxZ; } D3DVIEWPORT9, *LPD3DVIEWPORT9; Use IDirect3DDevice9::SetViewport or Default ViewPort

  12. RENDER TO TEXTURE AND ITS TEXTURE MAPPING

  13. Render To Texture • 1st Make 2D Texture as Render Target • - IDirect3DDevice9::CreateTexture • - Usage : D3DUSAGE_RENDERTARGET • - Ref : Find the Index with ‘D3DUSAGE’ in DX SDK Document • 2nd Bind 2D Texture resource to Surface (Display Memory – Back buffer) • - IDirect3DTexture9::GetSurfaceLevel • 3rd Define Rectangle Vertice (POSITION and TEXTURE) • - IDirect3DDevice9::CreateVertexBuffer • ----------------------------------------------------------------------------------------------------- • 4th Set Render Target with the Surface • - IDirect3DDevice9::SetRenderTarget • 5th Set Proxy Vertex Buffer Resources • - IDirect3DDevice9::SetStreamSource • 6th Setting another resources and states • 7th Draw RENDER TO TEXTURE AND ITS TEXTURE MAPPING

  14. Texture Mapping by Using Shade model 3.0 • 1st Use D3DXCreateEffectFromFile(…) • 2nd Bind texture resource to Shader Effect • - ID3DXBaseEffect::SetTexture • 3rd Flush effect state changes before ‘Draw’ • - ID3DXEffect::CommitChanges • ---------------------------------------------------------------------------------------------------- • 4th Declare • - ‘texture g_tex2DTest;’ in fx code • 5th Sampler State Setting • - sampler2D TestSampler2D = sampler_state{ • Texture = (g_tex2DTest); • … • } • 6th tex2D( TestSampler2D, float2(x, y) ); • - x, y must be normalized : 0~1 • - Return type is float4 vector RENDER TO TEXTURE AND ITS TEXTURE MAPPING

  15. SCENE STAGE SETTING & PROJECTION

  16. Scene Stage Setting #1 SCENE STAGE SETTING & PROJECTION 1 : (1, 1, 1) 6 : (-1, -1, -1) x Object3 Blue Color z 4 5 3 0 1 Center : (2, 2, 1) Object1 Red Color x 6 7 1 2 Center : (1, -3, -2) 3 Object Space Object2 Green Color y y 2 Center : (-4, 2, -2) x Rotation Axis : (1, -1, -1) Phong Illumination! z World Space z Parameter Setting for - D3DXMatrixLookAtLH - D3DXMatrixOrthogonalLH

  17. Scene Stage Setting #2 SCENE STAGE SETTING & PROJECTION x (0, 500, -500) (1000, 500, 0) y Rotation Axis : X-axis (0, -500, -500) (1000, -500, 0) World Space z Parameter Setting for - D3DXMatrixLookAtLH - D3DXMatrixPerspectiveLH

  18. Projections SCENE STAGE SETTING & PROJECTION x x (pix) Height z Render To Texture by orthogonal projection y (pix) World Space for Scene 1 Width Texture Mapping (0, 500, -500) (1000, 500, 0) x (pix) x y Render To Screen (Back-buf) Perspective projection Height (0, -500, -500) (1000, -500, 0) y (pix) World Space for Scene 2 Width z

  19. PROJECT SAMPLE CODE

  20. CRenderManager Class • 1. CRenderManager Class in Project1Renderer.cpp/h • Scene1,2’s initial Camera State • Two Vertex Declarations • POSITION&NORMAL for Scene1 • POSITION&TEXTURE for Scene2 • Two Vertex Buffers • Cube vertex buffer with index buffer for Scene1 • Rect. Vertex buffer for Scene2 • You may change the Camera state • CameraControlScene1(), CameraControlScene2() • Don’t have to do ‘Present(…)’ PROJECT SAMPLE CODE

  21. CRenderManager Class • RenderScene1() • Use m_matWS2OS_3 array • Setting the Shading Space to the Object Space • Cheaper way • May be used the World Space as the Shading Space • Orthogonal Projection • Render To Texture • RenderScene2() • Texture Mapping • Perspective Projection • Render To Back-buffer (Window Screen)

  22. Sample Shader Code • 2. Project1DX9.fx • You may change the sampler states and data structure • Use the Shader model 3.0 • Phong illumination model is available only in the shader code • You may assume that the light resource model is simplified. • may use parallel-light ray • may use the View direction as the parallel-light ray direction • In this case, specular can be represented as power of diffuse term PROJECT SAMPLE CODE

  23. Pseudo code for CRenderManager Class • 1. Initialization • Declare Rendertarget Texture • Create Shader Effect • Initial Matrix Setting : World Space  Object Space • Vertex / Index Bufffers : Given buffers PROJECT SAMPLE CODE

  24. Pseudo code for CRenderManager Class • 1. RenderScene1 PROJECT SAMPLE CODE // Backup Old RenderTarget Surface with Scene1’s camera states // Make View and Projection matrix // Set Device Resources such as buffers and declarations // Set Texture as RenderTarget // Effect Technique and Pass Begin for i : 0 to 2 { // Object[i] Parameters to the Shading Space and Set the parameters // Set the matrix : Object to Display(Screen) Space // CommitChanges // Draw  Run the Shader code } // Effect Technique and Pass End // Set the Old Render Target

  25. Pseudo code for CRenderManager Class • 1. RenderScene2 PROJECT SAMPLE CODE // Make View and Projection matrix with Scene2’s camera states // Set Device Resources such as buffers and declarations and Textures // Effect Technique and Pass Begin // CommitChanges // Draw  Run the Shader code // Effect Technique and Pass End // Set the Old Render Target

  26. PROJECT SUBMISSION

  27. E-MAIL : korfriend@gmail.com Due-Day : 2009/10/6, 23:59:59 (My Gmail Time --;) Delay Penalty : -20% per day Don’t have to submit a document about this HW. Submit your source files.

More Related