Game Programming I
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2006/gp1
컬러
May 22, 2006
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2006/gp1
주요 내용
Direct3D에서컬러를표현하는방법
삼각형에서의컬러셰이드구현원리의이해
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2006/gp1
컬러 표현 (1)
RGB 세성분을이용해컬러표현D3DCOLOR
D3DCOLORVALUE / D3DXCOLOR
Alpha Red Green Blue
32 bits
D3DCOLOR brightRed = D3DCOLOR_ARGB(255, 255, 0, 0);
D3DCOLOR someColor = D3DCOLOR_ARGB(255, 144, 87, 201);
D3DCOLOR xColor = D3DCOLOR_XRGB(144, 87, 201);
typedef struct _D3DCOLORVALUE {float r; // red component (0.0~1.0)float g; // green component (0.0~1.0)float b; // blue component (0.0~1.0)float a; // alpha component (0.0~1.0)
} D3DCOLORVALUE;
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2006/gp1
컬러 표현 (2)
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2006/gp1
RGB 컬러 모델
Red + Green + Blue R G B Color
0.0 0.0 0.0 Black
1.0 0.0 0.0 Red
0.0 1.0 0.0 Green
1.0 1.0 0.0 Yellow
1.0 0.0 1.0 Magenta
0.0 1.0 1.0 Cyan1.0 1.0 1.0 WhiteWhiteWhite
0.0 0.0 1.0 Blue
Green
Blue
Red
C
Y
M
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2006/gp1
Sample: Color Triangle
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2006/gp1
Sample: Color Triangle
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2006/gp1
“d3dUtility.h”
namespace d3d
{
.
.
.
const D3DXCOLOR WHITE( D3DCOLOR_XRGB(255, 255, 255) );
const D3DXCOLOR BLACK( D3DCOLOR_XRGB( 0, 0, 0) );
const D3DXCOLOR RED( D3DCOLOR_XRGB(255, 0, 0) );
const D3DXCOLOR GREEN( D3DCOLOR_XRGB( 0, 255, 0) );
const D3DXCOLOR BLUE( D3DCOLOR_XRGB( 0, 0, 255) );
const D3DXCOLOR YELLOW( D3DCOLOR_XRGB(255, 255, 0) );
const D3DXCOLOR CYAN( D3DCOLOR_XRGB( 0, 255, 255) );
const D3DXCOLOR MAGENTA( D3DCOLOR_XRGB(255, 0, 255) );
}
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2006/gp1
Global Color Constants
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2006/gp1
버텍스 컬러
버텍스구조체에컬러멤버추가
32비트데이터 D3DCOLOR만사용가능struct ColorVertex{
ColorVertex(){}ColorVertex(float x, float y, float z, D3DCOLOR c) {
_x = x; _y = y; _z = z; _color = c;}
float _x, _y, _z;D3DCOLOR _color;static const DWORD FVF;
};const DWORD ColorVertex::FVF = D3DFVF_XYZ | D3DFVF_DIFFUSE;
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2006/gp1
Vertex Colors (1)
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2006/gp1
Vertex Colors (2)
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2006/gp1
셰이딩 (1)
래스터라이즈과정중픽셀컬러를계산하기위해버텍스컬러가이용되는방식플랫셰이딩과그라우드셰이딩
플랫플랫 셰이딩셰이딩 (Flat Shading)첫번째버텍스에지정된컬러를이용하여일괄적으로도형의픽셀을채움
부드러운전환이없기때문에다소단조로운표현
그라우드그라우드 셰이딩셰이딩 (Gouraud Shading)부드러운셰이딩방식 (스무스셰이딩이라고도불림)
면을따라보간된버텍스컬러가입혀짐
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2006/gp1
셰이딩 (2)
그라우드
와이어프레임
퐁
플랫
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2006/gp1
Shading (1)
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2006/gp1
Shading (2)
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2006/gp1
연습 문제 (1)
사각형을그리시오.플랫셰이딩이용
그라우드셰이딩이용
조명을켜면어떤현상이일어나는가? 그이유는무엇이라생각하는가?
Sun-Jeong Kim http://www.hallym.ac.kr/~sunkim/teach/2006/gp1
연습 문제 (2)
Y축중심으로회전하는컬러큐브를그리시오.