2. 차례
SGL 소개 및 개발 동기
SGL 구현 기능
SGL 렌더링 파이프 라인
시연
The End
3. SGL 소개 및 개발 동기
• Software 3D Graphics rendering Library
• OpenGL 또는 DirectX 를 사용하지 않고
3D Graphics 를 표현
• OpenGL 의 Interface 를 모방하여 사용하기
쉬움
소개
개발동기
• 3D Graphics 이론의 실제적 이해
• Mobile Device 에 필요할 수 있기 때문
4. SGL 구현 기능
삼각형 그리기
Flat Shading
Gouraud Shading
Texture Mapping
Ambient Lighting
Point Lighting
Object Culling
Backface Culling
Depth Sort
OBJ Model Rendering
MD2 Model Rendering
5. SGL 렌더링 파이프 라인
OBJECT
TO
WORLD
WORLD
TO
CAMERA
CAMERA
TO
PROJECTION
PROJECTION
TO
SCREEN
Object
Culling
Backface
Culling
Lighting
&
Shading
Viewing
Volume
Clipping
Texture
Mapping
RASTER
Viewport
Clipping
DepthSort
7. OBJECT 변환 및 좌표 변환
행렬 스택을 구현함
sglPushMatrix(), sglPopMatrix()
SGL 은 ModelView, Camera, Projection, Viewport 행
렬을 사용
ModelView
(Object To World)
Camera
(World To Camera)
Projection
(Camera To Projection)
Viewport
(Projection To Screen)
sglRotatef()
sglTranslatef()
sglScalef()
sglLookAt() sglPerspective()
sglOrtho()
sglViewport()
8. Object Culling
A
B
C
Near Z
Far Z
D
C, D : culling
viewDistance
x
z
halfView
x/z = halfView/viewDistance
x = halfView*z / viewDistance
y/z = halfView/viewDistance
y = halfView*z / viewDistance
objX < -x or objX > x : culling
objY < -y or objY > y : culling
objZ < near Z
or objZ > Far Z : culling
10. Lighting And Shading
Ambient Lighting
- 빛의 색상에 Ambient 성분 곱
Point Lighting
- 표면의 법선과 내적하여 빛의 강약 성분 계산
d = n.dot(gp.light.diffuse);
if(d>0)
{
lightColor = gp.light.color;
lightColor.R *= gp.light.ambient.x;
lightColor.G *= gp.light.ambient.y;
lightColor.B *= gp.light.ambient.z;
intencity = (n.dot(gp.light.diffuse) + 1.0f) / 2.0f; //0도 1, 90도 0.5, 180도 0
lightColor *= intencity;
obj.localVertices[obj.plist[i].indexList[0]].color += lightColor;
obj.localVertices[obj.plist[i].indexList[1]].color += lightColor;
obj.localVertices[obj.plist[i].indexList[2]].color += lightColor;
if(obj.objectType == SGL_QUADS)
{
obj.localVertices[obj.plist[i].indexList[3]].color += lightColor;
}
}
L n
11. Viewing Volume Clipping
A
B
C
Near Z
Far Z
D
C, D : culling
viewDistance
x
z
halfView
x/z = halfView/viewDistance
x = halfView*z / viewDistance
y/z = halfView/viewDistance
y = halfView*z / viewDistance
VertexX < -x or VertexX > x : culling
VertexY< -y or VertexY > y : culling
VertexZ < near Z
or VertexZ > Far Z : culling
Object Culling 과 원리는 같고 단지
카메라 좌표계의 Vertex 좌표로 Clipping
한다