Redering Pipeline

Post on 15-Apr-2017

200 views 0 download

Transcript of Redering Pipeline

Rendering Pipeline

- Study Group: DevRookie - Author: Daeyoung Hwang

Define Rendering PipelineRendering PipelineSource Code in practice

Define Rendering PipelineRendering PipelineSource Codes in practice

Why do we need to understand ?

Shader programming

Optimize performance of rendering

Computer is a machine box which only distinguish 0 and 1

Then how to display 3D world ?

Does teapot actually exist in 3D world ?

3D Virtual worldIn 2D monitor

Fake!!

Process of making 2D Image using virtual camera that defines perspec-tive view of 3D world and geometry expression about 3D world

Rendering Pipe-line ?

Define Rendering PipelineRendering PipelineSource Codes in practice

Whole Process of Rendering Pipeline

Tessellation Clipping Projection Viewport Rasterization

Apply Tex-ture

Render Backend

Convert Local

Convert World

Convert View

Back-face Culling Light

Display

1. Convert Local

Unique coordinate of one model (Model Coordinate)

No problem expressing single object like model viewer

2. Convert World

Convert objects in local space to world co-ordinate

TransformMovement,Rotation,Scale

3. Convert View (Convert Camera)

Convert camera to zero of coordinate=> Convert all objects

4. Back-face Culling

Set polygon which assigned clock wise of winding order as front-face polygon

5. Light

Calculate color of vertex using light formula including light source vector, sight vector, face-normal vector

6. Tessellation

Increase, decrease vertexes freely at GPU

7. Clipping

Clip polygon which is outof sight

According to viewingfrustum

8. Projection

Process of getting 2d dimension from 3d dimension

Perspective / orthographicprojection

9. Viewport Screen Mapping

Convert to window screen coordinate

10. Rasterize (triangle setup)

Calculate converted polygon into pixel to display on screen

Result – 2D Image todisplay on monitor

11. Apply TextureUse UV coordinate (0~1)

12. Render backend

Is it okay to write on video memory ?• Alpha Test• Stencil Test• Z buffer Test

12. Render Backend

How to write on video memory?• Alpha Blending• Fog• Anti-aliasing

Define Rendering PipelineRendering PipelineSource Codes in practice

VOID SetupMatrices(){

// convert to worldD3DXMATRIXA16 matWorld;D3DXMatrixIdentity( &matWorld );g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );

// convert to view(camera)D3DXVECTOR3 vEyePt( 0.0f, 3.0f,-5.0f ); // position of eyeD3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f ); // position of looking atD3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );// Up VectorD3DXMATRIXA16 matView;D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );

// convert projectionD3DXMATRIXA16 matProj;// matProj : matrix to set value// D3DX_PI/4 : FOV (Field of View)// 1.0f : the aspect ratio// 1.0f : near clipping plane// 100.0f : far clipping planeD3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );

}

Summary

Reference• Windows DirectX Graphics Document• DirectX 9 를 이용한 3D GAME 프로그래밍 입문• 3D 게임 프로그래밍 ( 개정판 )• allosha blog http://bit.ly/9vtHSg