Presentation is loading. Please wait.

Presentation is loading. Please wait.

2009 GRAPHICS : PROJECT 1 BASED ON DX9 BASICS. Documented by Dongjoon Kim SNU CS Ph.D Course Student Contact : NOTE.

Similar presentations


Presentation on theme: "2009 GRAPHICS : PROJECT 1 BASED ON DX9 BASICS. Documented by Dongjoon Kim SNU CS Ph.D Course Student Contact : NOTE."— Presentation transcript:

1 2009 GRAPHICS : PROJECT 1 BASED ON DX9 BASICS. Documented by Dongjoon Kim SNU CS Ph.D Course Student Contact : dojo@cglab.snu.ac.kr NOTE

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

4 3D SPACE TRANSFORMATION

5 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 Rigid Space Linear Space Affine Space Projective Space Translation Rotation Shear Scale Perspective TR x1 y1 z1 p1 x2 y2 z2 p2 x3 y3 z3 p3 t1 t2 t3 1 Linear Transform Translation Projection

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

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

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

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

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

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

12 RENDER TO TEXTURE AND ITS TEXTURE MAPPING

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

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

15 SCENE STAGE SETTING & PROJECTION

16 Scene Stage Setting #1 x y z 1 : (1, 1, 1)6 : (-1, -1, -1) Object Space 3 2 1 Center : (2, 2, 1) Center : (-4, 2, -2) Center : (1, -3, -2) z x y World Space z x Parameter Setting for - D3DXMatrixLookAtLH - D3DXMatrixOrthogonalLH Phong Illumination! 0 2 1 3 45 67 Object1 Red Color Object2 Green Color Object3 Blue Color Rotation Axis : (1, -1, -1)

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

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

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(…)’

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 PROJECT SAMPLE CODE 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

23 PROJECT SAMPLE CODE 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

24 PROJECT SAMPLE CODE Pseudo code for CRenderManager Class 1. RenderScene1 // 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 // 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 PROJECT SAMPLE CODE Pseudo code for CRenderManager Class 1. RenderScene2 // 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 // 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.comkorfriend@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.


Download ppt "2009 GRAPHICS : PROJECT 1 BASED ON DX9 BASICS. Documented by Dongjoon Kim SNU CS Ph.D Course Student Contact : NOTE."

Similar presentations


Ads by Google