김성철
차례
 SGL 소개 및 개발 동기
 SGL 구현 기능
 SGL 렌더링 파이프 라인
 시연
 The End
SGL 소개 및 개발 동기
• Software 3D Graphics rendering Library
• OpenGL 또는 DirectX 를 사용하지 않고
3D Graphics 를 표현
• OpenGL 의 Interface 를 모방하여 사용하기
쉬움
소개
개발동기
• 3D Graphics 이론의 실제적 이해
• Mobile Device 에 필요할 수 있기 때문
SGL 구현 기능
 삼각형 그리기
 Flat Shading
 Gouraud Shading
 Texture Mapping
 Ambient Lighting
 Point Lighting
 Object Culling
 Backface Culling
 Depth Sort
 OBJ Model Rendering
 MD2 Model Rendering
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
OBJECT 정의
sglPushMatrix();
sglTranslatef(0.0, 0.0, 0.0);
sglRotatef(a, 0, 0, 1);
sglBegin(SGL_TRIANGLES);
sglSetTexture(texId);
sglTexCoord2f(0.0f, 0.0f);
sglColor3f(1.0, 0.0, 0.0);
sglVertex3f(-1.0, -1.0, 1.0); //0
sglTexCoord2f(1.0f, 0.0f);
sglColor3f(0.0, 1.0, 0.0);
sglVertex3f( 1.0, -1.0, 1.0); //1
sglTexCoord2f(1.0f, 1.0f);
sglColor3f(0.0, 0.0, 1.0);
sglVertex3f( 1.0, 1.0, 1.0); //2
sglTexCoord2f(0.0f, 0.0f);
sglColor3f(0.0, 0.0, 1.0);
sglVertex3f(-1.0, -1.0, 1.0); //3
sglTexCoord2f(1.0f, 1.0f);
sglVertex3f( 1.0, 1.0,1.0); //4
sglTexCoord2f(0.0f, 1.0f);
sglVertex3f(-1.0, 1.0,1.0); //5
sglEnd();
sglPopMatrix();
1. 정점 정의 2. 인덱스 정의
SGLVertex pts[8] =
{
SGLVertex(-1.0, -1.0, 1.0, 0.0f, 0.0f), //0
SGLVertex( 1.0, -1.0, 1.0, 1.0f, 0.0f), //1
SGLVertex( 1.0, 1.0, 1.0, 1.0f, 1.0f), //2
SGLVertex(-1.0, 1.0, 1.0, 0.0f, 1.0f), //3
SGLVertex(-1.0, -1.0, 3.0, 0.0f, 0.0f), //4
SGLVertex( 1.0, -1.0, 3.0, 1.0f, 0.0f), //5
SGLVertex( 1.0, 1.0, 3.0, 1.0f, 1.0f), //6
SGLVertex(-1.0, 1.0, 3.0, 0.0f, 1.0f), //7
}; //정점(로컬좌표와 텍스춰좌표)
sglPushMatrix();
sglTranslatef(0, 0, 0);
sglScalef(3.0f, 3.0f, 3.0f);
sglRotatef(a, 1, 0, 1);
sglBegin(SGL_QUADS);
sglVertices(pts, 8);
sglSetTexture(texId);
sglIndex4i(0, 1, 2, 3); // FRONT
sglIndex4i(1, 5, 6, 2); // RIGHT
sglIndex4i(5, 4, 7, 6); // BACK
sglIndex4i(4, 0, 3, 7); // LEFT
sglIndex4i(4, 5, 1, 0); // DOWN
sglIndex4i(3, 2, 6, 7); // UP
sglEnd();
sglPopMatrix();
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()
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
Backface Culling
a
b
c
d
e
If VP dot nv > 0 then
plane visible = true
View Point
VP
VP
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
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
한다
Depth Sort
Depth Sort 전 Depth Sort 후
Object 를 구성하는 정점의
Z 좌표를 평균내어 Object를
정렬한다.
Texture Mapping
(0,0) (1,0)
(1,1)
(0,0) (1,0)
(1,1)
Nearest Filter
d
h
dP1 = L1/h
dP2= L2/h
texturePt = 보간하여 얻음
dx = range(0, L3)
color = ColorAt(texturePt)
drawPoint(P1 + dx, color)
P1 P2
L1
L2
L3
Viewport Clipping
모두 Clipping
부분 Clipping
(0,0)
(screenX, screenY)
레스터과정 전에
Viewport 공간을
넘는 부분을 제거한다.
SGL 예제에서는 Viewport
공간이 화면의 크기와 동일
하다.
시연
 EX1
1 : Frame Mode
2 : Flat Shade
3 : Texture Mapping Mode
4 : Gouraud Shade
 Ex2
F1 : OBJ Model Rendering
F2 : MD2 Model Rendering
1 : Frame Mode
2 : Flat Shade
3 : Texture Mapping Mode
4 : Gouraud Shade
The End
감사합니다

SGL : 소프트웨어 3D 렌더링 엔진

  • 1.
  • 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
  • 6.
    OBJECT 정의 sglPushMatrix(); sglTranslatef(0.0, 0.0,0.0); sglRotatef(a, 0, 0, 1); sglBegin(SGL_TRIANGLES); sglSetTexture(texId); sglTexCoord2f(0.0f, 0.0f); sglColor3f(1.0, 0.0, 0.0); sglVertex3f(-1.0, -1.0, 1.0); //0 sglTexCoord2f(1.0f, 0.0f); sglColor3f(0.0, 1.0, 0.0); sglVertex3f( 1.0, -1.0, 1.0); //1 sglTexCoord2f(1.0f, 1.0f); sglColor3f(0.0, 0.0, 1.0); sglVertex3f( 1.0, 1.0, 1.0); //2 sglTexCoord2f(0.0f, 0.0f); sglColor3f(0.0, 0.0, 1.0); sglVertex3f(-1.0, -1.0, 1.0); //3 sglTexCoord2f(1.0f, 1.0f); sglVertex3f( 1.0, 1.0,1.0); //4 sglTexCoord2f(0.0f, 1.0f); sglVertex3f(-1.0, 1.0,1.0); //5 sglEnd(); sglPopMatrix(); 1. 정점 정의 2. 인덱스 정의 SGLVertex pts[8] = { SGLVertex(-1.0, -1.0, 1.0, 0.0f, 0.0f), //0 SGLVertex( 1.0, -1.0, 1.0, 1.0f, 0.0f), //1 SGLVertex( 1.0, 1.0, 1.0, 1.0f, 1.0f), //2 SGLVertex(-1.0, 1.0, 1.0, 0.0f, 1.0f), //3 SGLVertex(-1.0, -1.0, 3.0, 0.0f, 0.0f), //4 SGLVertex( 1.0, -1.0, 3.0, 1.0f, 0.0f), //5 SGLVertex( 1.0, 1.0, 3.0, 1.0f, 1.0f), //6 SGLVertex(-1.0, 1.0, 3.0, 0.0f, 1.0f), //7 }; //정점(로컬좌표와 텍스춰좌표) sglPushMatrix(); sglTranslatef(0, 0, 0); sglScalef(3.0f, 3.0f, 3.0f); sglRotatef(a, 1, 0, 1); sglBegin(SGL_QUADS); sglVertices(pts, 8); sglSetTexture(texId); sglIndex4i(0, 1, 2, 3); // FRONT sglIndex4i(1, 5, 6, 2); // RIGHT sglIndex4i(5, 4, 7, 6); // BACK sglIndex4i(4, 0, 3, 7); // LEFT sglIndex4i(4, 5, 1, 0); // DOWN sglIndex4i(3, 2, 6, 7); // UP sglEnd(); sglPopMatrix();
  • 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 FarZ 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
  • 9.
    Backface Culling a b c d e If VPdot nv > 0 then plane visible = true View Point VP VP
  • 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 NearZ 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 한다
  • 12.
    Depth Sort Depth Sort전 Depth Sort 후 Object 를 구성하는 정점의 Z 좌표를 평균내어 Object를 정렬한다.
  • 13.
    Texture Mapping (0,0) (1,0) (1,1) (0,0)(1,0) (1,1) Nearest Filter d h dP1 = L1/h dP2= L2/h texturePt = 보간하여 얻음 dx = range(0, L3) color = ColorAt(texturePt) drawPoint(P1 + dx, color) P1 P2 L1 L2 L3
  • 14.
    Viewport Clipping 모두 Clipping 부분Clipping (0,0) (screenX, screenY) 레스터과정 전에 Viewport 공간을 넘는 부분을 제거한다. SGL 예제에서는 Viewport 공간이 화면의 크기와 동일 하다.
  • 15.
    시연  EX1 1 :Frame Mode 2 : Flat Shade 3 : Texture Mapping Mode 4 : Gouraud Shade  Ex2 F1 : OBJ Model Rendering F2 : MD2 Model Rendering 1 : Frame Mode 2 : Flat Shade 3 : Texture Mapping Mode 4 : Gouraud Shade
  • 16.