19
게임 프로그래밍 11 th W k 2011 11 th Week , 2011 게임 기술의 분류 게임 기술의 분류 엔진 기술 엔진 기술 렌더링 엔진, 사운드 엔진, 인공지능 엔진, 물리 엔진 네트워크 기술 네트워크 기술 유선 기술, 무선 기술 서버 기술 서버 엔진 기술, 서버 구성 기술 디바이스 제작 기술 비디게임기, 바일 게임기, 아케이게임기

게임프로그래밍 - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2011/ug/src/15program.pdf · 게임프로그래밍 11th W k 2011Week, ... 온라인서버기술 멀티스레드

  • Upload
    leanh

  • View
    214

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 게임프로그래밍 - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2011/ug/src/15program.pdf · 게임프로그래밍 11th W k 2011Week, ... 온라인서버기술 멀티스레드

게임 프로그래밍

11th W k 201111th Week, 2011

게임 기술의 분류게임 기술의 분류

■ 엔진 기술■ 엔진 기술■ 렌더링 엔진, 사운드 엔진, 인공지능 엔진, 물리 엔진

네트워크 기술■ 네트워크 기술■ 유선 기술, 무선 기술

■ 서버 기술■ 서버 엔진 기술, 서버 구성 기술

■ 디바이스 제작 기술■ 비디오 게임기, 모바일 게임기, 아케이드 게임기비디 게임기, 바일 게임기, 아케이 게임기

Page 2: 게임프로그래밍 - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2011/ug/src/15program.pdf · 게임프로그래밍 11th W k 2011Week, ... 온라인서버기술 멀티스레드

네트워크 기술네트워크 기술

■ 일반적으로 TCP/IP 프로토콜 사용■ 일반적으로 TCP/IP 프로토콜 사용■ Windows에서 winsock API 사용

TCP 서버

k t

TCP 클라이언트

k tsocket

bind

socket

listen

acceptconnect

send/recv

close

send/recv

closeclose close

온라인 서버 기술온라인 서버 기술

■ 멀티 스레드 (multi thread)■ 멀티 스레드 (multi thread)■ 여러 개의 스레드를 이용하여 병렬 처리

■ IOCP (Input Output Completion Port)자 의 입출력 별 담당하■ 자료의 입출력을 별도로 담당하는 부분

■ 게임 서버 구조■ 일정 영역을 특정 서버가 담당 구조 MMORPG에서

부적절한 구조

Page 3: 게임프로그래밍 - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2011/ug/src/15program.pdf · 게임프로그래밍 11th W k 2011Week, ... 온라인서버기술 멀티스레드

게임 엔진의 개요게임 엔진의 개요

■ 게임 엔진의 정의■ 게임 엔진의 정의■ 게임을 제작하기 위해 제공되는 각종 API 집합

게임 엔진 구성요소■ 게임 엔진 구성요소■ 렌더링

애니메이션■ 애니메이션■ 사운드■ 물리■ 인공지능■ 서버■ 기타 – 맵 에디터

2D 컴퓨터 게임2D 컴퓨터 게임

■ 비트맵과 팔레트비트맵 파일에 대한 정보

BITMAPFILEHEADER

■ 비트맵과 팔레트■ 컴퓨터 게임에서 사용되는 이미지

■ BMP 파일 구조

비트맵 자체에 대한 정보BITMAPINFOHEADER

팔레트■ BMP 파일 구조

■ 팔레트: 8비트(0~255)씩 RGBRGBQUAD

이미지 데이터IMAGE DATA

■ 컬러키(colorkey)와 알파채널컬러키 이미지의 특정 픽셀을 화면에 그리지 않는■ 컬러키 – 이미지의 특정 픽셀을 화면에 그리지 않는방법 (예: 블루 스크린)알파채널 투명도를 0 255 정수 값으로 표현■ 알파채널 – 투명도를 0~255 정수 값으로 표현

Page 4: 게임프로그래밍 - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2011/ug/src/15program.pdf · 게임프로그래밍 11th W k 2011Week, ... 온라인서버기술 멀티스레드

그래픽 카드그래픽 카드

■ 그래픽 데이터를 처리하기 위해 사용되는 장치■ 그래픽 데이터를 처리하기 위해 사용되는 장치

■ GPU (Graphics Processing Unit)■ 그래픽 카드의 CPU■ 예전의 GPU – 그래픽 관련 작업만 처리■ 현재 GPU – 수치 계산 처리기를 내장하면서 CPU의

작업 일부를 스스로 해결

DirectX (1)DirectX (1)

■ 게임 개발을 위한 전용 SDK(Software■ 게임 개발을 위한 전용 SDK(Software Development Kits)

Windows의 GDI(Graphic Device Interface)를 경유하■ Windows의 GDI(Graphic Device Interface)를 경유하지 않고 바로 하드웨어를 접근

■ 처음에는 4개 API(Application Programming■ 처음에는 4개 API(Application Programming Interface) 제공 – DirectDraw, DirectSound, DirectInput, DirectPlayp y

■ Direct3D 추가 3차원 게임 제작 능력 향상■ 현재 버전: DirectX11현재 버전

■ OpenGL■ 고품질 그래픽 처리를 위한 라이브러리■ 고품질 그래픽 처리를 위한 라이브러리

Page 5: 게임프로그래밍 - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2011/ug/src/15program.pdf · 게임프로그래밍 11th W k 2011Week, ... 온라인서버기술 멀티스레드

DirectX (2)DirectX (2)

■ DirectX의 구성요소■ DirectX의 구성요소■ DirectDraw, Direct3D – 그래픽

DirectSound DirectMusic 오디오■ DirectSound, DirectMusic – 오디오■ DirectInput – 입력 장치 (예: 조이스틱, 게임패드)

Di tPl 네트워크 장치■ DirectPlay – 네트워크 장치■ DirectShow – 멀티미디어 제어, 비디오 재생

Di tS t 설치 배포 파일 만들 때■ DirectSetup – 설치, 배포 파일 만들 때

Direct3D OverviewDirect3D Overview

■ Direct3D■ Direct3D■ A low-level graphics API (Application Programming

Interface)Interface)■ A mediator between the application and the

graphic device (3D hardware)graphic device (3D hardware)

Application Direct3D HAL GraphicsDevice

■ HAL (Hardware Abstraction Layer)

pp Device

■ HAL (Hardware Abstraction Layer)■ The set of device-specific code that instructs the

device to perform an operationdevice to perform an operation

Page 6: 게임프로그래밍 - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2011/ug/src/15program.pdf · 게임프로그래밍 11th W k 2011Week, ... 온라인서버기술 멀티스레드

3D 게임의 기초 (1)3D 게임의 기초 (1)

■ 3D 좌표계■ 3D 좌표계■ 왼손 좌표계 – DirectX

오른손 좌표계 OpenGL■ 오른손 좌표계 – OpenGL

왼손 좌표계 오른손 좌표계

3D 게임의 기초 (2)3D 게임의 기초 (2)

■ 정점(vertex)■ 정점(vertex)■ 3차원 물체를 그릴 때 가장 기본이 되는 점

벡터 ( t )■ 벡터 (vector)■ 크기와 방향을 가지는 물리적 특성

힘이나 에 사■ 힘이나 속도에 사용

■ 단위 벡터 – 크기가 1인 벡터■ 벡터의 연산

■ 벡터의 합, 차벡터의 합, 차■ 벡터의 내적, 외적

Page 7: 게임프로그래밍 - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2011/ug/src/15program.pdf · 게임프로그래밍 11th W k 2011Week, ... 온라인서버기술 멀티스레드

3D 게임의 기초 (3)3D 게임의 기초 (3)

■ 행렬■ 행렬■ 행과 열로 이루어진 직사각형 모양의 배열

항등 행렬 (id tit t i )■ 항등 행렬 (identity matrix)■ 대각성분은 1이고 나머지는 0인 행렬

′■ 이동 행렬 (translation matrix)

■ 왼손 좌표계:⎥⎤

⎢⎡

0010

0001 y

x

tZZ

tYY

tXX

+=′

+=′+=′

[ ] [ ]

⎥⎥⎥⎥⎥

⎦⎢⎢⎢⎢⎢

=′′′

1

0100

001011

zyx ttt

ZYXZYXztZZ +

■ 오른손 좌표계: ⎥⎦⎢⎣ zyx

⎥⎥⎥⎤

⎢⎢⎢⎡

⎥⎥⎥⎤

⎢⎢⎢⎡

=⎥⎥⎥⎤

⎢⎢⎢⎡

′′

010

001

Y

X

t

t

Y

X

y

x

⎥⎥⎥

⎦⎢⎢⎢

⎣⎥⎥⎥

⎦⎢⎢⎢

=

⎥⎥⎥

⎦⎢⎢⎢

11000

100

1

ZtZ z

3D 게임의 기초 (4)3D 게임의 기초 (4)

■ 크기 변환 행렬 (scaling matrix)■ 크기 변환 행렬 (scaling matrix)

YsY

XsX x

′=′

왼손 좌표계 ⎤⎡ 000s

ZsZ

YsY

z

y

=′

=

■ 왼손 좌표계:[ ] [ ]

⎥⎥⎥⎥⎤

⎢⎢⎢⎢⎡

=′′′000

000

000

11z

y

x

s

s

s

ZYXZYX

■ 오른손 좌표계:

⎥⎦

⎢⎣ 1000

⎤⎡⎤⎡⎤⎡

⎥⎥⎥⎥⎤

⎢⎢⎢⎢⎡

⎥⎥⎥⎥⎤

⎢⎢⎢⎢⎡

=

⎥⎥⎥⎥⎤

⎢⎢⎢⎢⎡

′′′

000

000

000

Z

Y

X

s

s

s

Z

Y

X

z

y

x

⎥⎥

⎦⎢⎢

⎣⎥⎥

⎦⎢⎢

⎣⎥⎥

⎦⎢⎢

⎣ 11000

000

1

sz

Page 8: 게임프로그래밍 - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2011/ug/src/15program.pdf · 게임프로그래밍 11th W k 2011Week, ... 온라인서버기술 멀티스레드

3D 게임의 기초 (5)3D 게임의 기초 (5)

■ 회전 행렬 ⎥⎤

⎢⎡ − 0sin0cos θθ

■ 회전 행렬■ 왼손 좌표계:

⎤⎡ 0001 ⎥⎥⎥⎥

⎦⎢⎢⎢⎢

⎣ 1000

0cos0sin

0010

θθ

[ ] [ ]⎥⎥⎥⎥⎤

⎢⎢⎢⎢⎡

−=′′′

0cossin0

0sincos0

0001

11θθθθ

ZYXZYX

⎦⎣ 1000

⎥⎥⎤

⎢⎢⎡− 00cossin

00sincos

θθθθ

오른손 좌표계

⎥⎦

⎢⎣ 1000

⎥⎥⎥

⎦⎢⎢⎢

⎣ 1000

0100

00coss θθ

■ 오른손 좌표계:

⎥⎤

⎢⎡ 0sin0cos θθ

⎥⎤

⎢⎡ −

i

00sincos

θθθθ

⎥⎤

⎢⎡⎥⎤

⎢⎡

⎥⎤

⎢⎡

′′

i

0001 XX

θθ

⎥⎥⎥⎥

⎦⎢⎢⎢⎢

−1000

0cos0sin

0010

θθ⎥⎥⎥⎥

⎦⎢⎢⎢⎢

⎣ 1000

0100

00cossin θθ

⎥⎥⎥⎥

⎦⎢⎢⎢⎢

⎣⎥⎥⎥⎥

⎦⎢⎢⎢⎢

−=

⎥⎥⎥⎥

⎦⎢⎢⎢⎢

′′

11000

0cossin0

0sincos0

1

Z

Y

Z

Y

θθθθ

⎦⎣ ⎦⎣⎦⎣⎦⎣⎦⎣

The Rendering Pipeline (1)The Rendering Pipeline (1)

■ Creating a 2D image given a geometric■ Creating a 2D image given a geometric description of the 3D world and a virtual cameracamera

■ Virtual cameraS if i h l f h ld h i■ Specifying the volume of the world that is seen

3D World 2D Image

Page 9: 게임프로그래밍 - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2011/ug/src/15program.pdf · 게임프로그래밍 11th W k 2011Week, ... 온라인서버기술 멀티스레드

The Rendering Pipeline (2)The Rendering Pipeline (2)

■ Sequence of steps necessary to generate 2D■ Sequence of steps necessary to generate 2D image

World Transformation

View Transform

Lighting

Projection Transform

Clipping

Rasterization

Viewport Transform

An Abridged Direct3D Rendering Pipeline

Local Space and World SpaceLocal Space and World Space

■ Building models in local space and then■ Building models in local space and then transforming them to world space

Local space local coordinate system■ Local space – local coordinate system■ World space – global coordinate system

W ld T f tiW ld T f ti■■ World TransformationWorld Transformation■ Changing coordinates relative to a local coordinate

t i t th l b l di t tsystem into the global scene coordinate system

W3

W2

GlobalCoordinate

System

W1LocalCoordinate

System

Page 10: 게임프로그래밍 - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2011/ug/src/15program.pdf · 게임프로그래밍 11th W k 2011Week, ... 온라인서버기술 멀티스레드

View SpaceView Space

■ Let the camera be centered about its own local■ Let the camera be centered about its own local coordinate system

View space camera coordinate system■ View space – camera coordinate system

■■ View TransformationView Transformationf i ll f h bj i ld■ Transforming all of the objects in world space to

view space

Up Vector CameraCoordinate

System

Right Vector V

y

Right Vector

Front Vector

GlobalCoordinate

System

LightingLighting

■ Realistic scene■ Realistic scene■ Specifying lights in world space transforming

lights into local space or view space carrying outlights into local space or view space carrying out the light calculation

■ Cinematic effects■ Cinematic effects■ Emphasizing (or hiding) certain parts of scene

An Unit Sphere A Lit Sphere A Lit Sphereand its Shadow

Page 11: 게임프로그래밍 - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2011/ug/src/15program.pdf · 게임프로그래밍 11th W k 2011Week, ... 온라인서버기술 멀티스레드

Projection Transformation (1)Projection Transformation (1)

■ Mapping the frustum into a box (canonicalcanonical■ Mapping the frustum into a box (canonical canonical view volumeview volume)

Expecting the vertices inside the frustum to be in■ Expecting the vertices inside the frustum to be in normalized device coordinatesnormalized device coordinates

■ x- and y- coordinates: [-1, 1] 2D projected vertices■ x and y coordinates: [ 1, 1] 2D projected vertices■ z-coordinates: [0, 1] depth buffering

■ Steps■ Steps■ Defining a frustum and aspect ratio■ Projecting vertices■ Projecting vertices■ Normalizing the coordinates■ Transforming the z-coordinate■ Transforming the z coordinate

Writing the projection equation with a matrix

Projection Transformation (2)Projection Transformation (2)

■ Frustum and aspect ratiow

R =■ Frustum and aspect ratio h

R =

Far Plane

Near Plane

βHorizontal Field of View Angle

αβVertical Field of View Angle

Eye / Center of Projectiony / j

Page 12: 게임프로그래밍 - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2011/ug/src/15program.pdf · 게임프로그래밍 11th W k 2011Week, ... 온라인서버기술 멀티스레드

ClippingClipping

■ Culling the geometry that is outside the■ Culling the geometry that is outside the viewing volume

Three possible locations

+z

■ Three possible locations(1) completely inside

keeping it Insidekeeping it(2) completely outside

lli itculling it(3) partially inside

( ti ll t id )(partially outside)splitting it

OutsidePartially Inside

+x+x

Viewport TransformViewport Transform

■ Transforming normalized device coordinates to■ Transforming normalized device coordinates to a rectangle on the back buffer (viewportviewport)

Image coordinates■ Image coordinates

(0,0) (320,0)

(320,240) (640,240)( , ) ( , )(0,240) (320,240)

(320,480) (640,480)

Multiple ViewportsMultiple Viewports

Page 13: 게임프로그래밍 - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2011/ug/src/15program.pdf · 게임프로그래밍 11th W k 2011Week, ... 온라인서버기술 멀티스레드

RasterizationRasterization

■ Computing the color of the individual pixels■ Computing the color of the individual pixels that make up the interiors and boundaries of trianglestriangles

■ Pixel operationE ) i i l h d d h b ff i d■ Ex) texturing, pixel shaders, depth buffering, and alpha blending

I t l tiI t l ti■■ InterpolationInterpolation■ Ex) color values, depth values, texture coordinates,

d t l RGB(0 255 0)and vertex normals RGB(0, 255, 0)

RGB(0, 127, 127)RGB(127, 127, 0)

RGB(255, 0, 0) RGB(0, 0, 255)RGB(127, 0, 127)

Light and Material Interaction (1)Light and Material Interaction (1)

■ Computing the vertex color based on■ Computing the vertex color based on light/material interaction

Specifying materials and lights and then applying a■ Specifying materials and lights, and then applying a light equation

■ Materials■ Materials■ Properties that determine how light interacts with

an objectan object■ Ex) reflecting, absorbing, shininess, transparency

Light rays eventually travel into the eye■ Light rays eventually travel into the eye

EyeEye

Page 14: 게임프로그래밍 - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2011/ug/src/15program.pdf · 게임프로그래밍 11th W k 2011Week, ... 온라인서버기술 멀티스레드

Light SourcesLight Sources

■ Directional lights■ Directional lights ■ No position + shooting parallel rays

Ex) Sun■ Ex) Sun

■ Point lights ■ Position + emitting light in all

directionsE ) li htb lb■ Ex) lightbulb

■ Spotlights■ Position + shining light through a

conical shapefl hli h■ Ex) flashlight

Directional LightsDirectional Lights

■ Parallel light■ Parallel light■ A light source is very far away

Approximating all incoming light rays as parallel toApproximating all incoming light rays as parallel to each other

■ Ex) Sun■ Ex) Sun

LrL

Page 15: 게임프로그래밍 - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2011/ug/src/15program.pdf · 게임프로그래밍 11th W k 2011Week, ... 온라인서버기술 멀티스레드

Point LightsPoint Lights

■ Radiating light spherically in all directions■ Radiating light spherically in all directions■ Ex) lightbulb s

r

Lr

pr

■ Light vector( ) pspsL

rrrrr−−=

■ Directional – constant■ Point – varying from vertex to vertex

SpotlightsSpotlights

■ Having a position being aimed in a direction■ Having a position, being aimed in a direction, and radiating light through a cone

Ex) flashlight■ Ex) flashlightIntensity

1 αcos

sr

r

dr

α α8cosα128cos

■ Light vector:

Lr

− p

( )Lrrrrr

α02π− 2π

■ Light vector:■ Falloff:

( ) pspsL −−=( ) ( )( ) ( )( )ss dLf 0 ,max0 ,cosmax

rr⋅−== αα

Page 16: 게임프로그래밍 - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2011/ug/src/15program.pdf · 게임프로그래밍 11th W k 2011Week, ... 온라인서버기술 멀티스레드

Texture MappingTexture Mapping

■ Technique to map image data onto a triangle■ Technique to map image data onto a triangle■ To increase the details and realism of our scene

T t■ Texture■ Matrix of pixels similar to a surface but can be

d t t i l d h l l lmapped onto triangles and may have several levels of detail (e.g. mipmaps)

Texture Coordinates (1)Texture Coordinates (1)

■ Texture coordinate system consists of a u-axis■ Texture coordinate system consists of a u-axis and a v-axisT lT l■■ TexelTexel■ The coordinates (u, v) identify an element on the

texturetexture■ Normalized coordinate

i t l [0 1] i d

(0, 0) (1, 0)+u

interval [0, 1] is used

(0, 1) (1, 1)+v

Page 17: 게임프로그래밍 - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2011/ug/src/15program.pdf · 게임프로그래밍 11th W k 2011Week, ... 온라인서버기술 멀티스레드

Texture Coordinates (2)Texture Coordinates (2)

■ Define a corresponding triangle on the texture■ Define a corresponding triangle on the texture that is to be mapped to the 3D triangle

(u0, v0) (u1, v1)+u

(x1, y1, z1)

(x0, y0, z0)

(u2, v2)

+v(x2, y2, z2)

3D Triangle Corresponding Texture Triangle

v

Three Types of MappingThree Types of Mapping

■■ Texture mappingTexture mapping■■ Texture mappingTexture mapping■ Using images to fill inside of polygons

■■ EnvironmentEnvironment (reflection) mappingmappingf f■ Using a picture of the environment for texture maps

■ Allowing simulation of highly specular surfaces

■■ Bump mappingBump mapping■ Emulating altering normal vectors during the

rendering process

Page 18: 게임프로그래밍 - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2011/ug/src/15program.pdf · 게임프로그래밍 11th W k 2011Week, ... 온라인서버기술 멀티스레드

Texture MappingTexture Mapping

Geometric Model Texture Mappedpp

Environment MappingEnvironment Mapping

Page 19: 게임프로그래밍 - graphics.hallym.ac.krgraphics.hallym.ac.kr/teach/2011/ug/src/15program.pdf · 게임프로그래밍 11th W k 2011Week, ... 온라인서버기술 멀티스레드

Bump MappingBump Mapping