SlideShare a Scribd company logo
1 of 16
김성철
차례
 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
감사합니다

More Related Content

What's hot

게임 개발을 위한 렌더링 기법 한성환
게임 개발을 위한 렌더링 기법   한성환게임 개발을 위한 렌더링 기법   한성환
게임 개발을 위한 렌더링 기법 한성환Yggdrasil610
 
I phone3d programming - Chap04:깊이와 현실감 향상시키기
I phone3d programming - Chap04:깊이와 현실감 향상시키기I phone3d programming - Chap04:깊이와 현실감 향상시키기
I phone3d programming - Chap04:깊이와 현실감 향상시키기hanstar17
 
Shadow mapping 정리
Shadow mapping 정리Shadow mapping 정리
Shadow mapping 정리changehee lee
 
[1023 박민수] 깊이_버퍼_그림자_1
[1023 박민수] 깊이_버퍼_그림자_1[1023 박민수] 깊이_버퍼_그림자_1
[1023 박민수] 깊이_버퍼_그림자_1MoonLightMS
 
포인트 셰도우
포인트 셰도우포인트 셰도우
포인트 셰도우Sukwoo Lee
 
[week11] R_ggmap, leaflet
[week11] R_ggmap, leaflet[week11] R_ggmap, leaflet
[week11] R_ggmap, leafletneuroassociates
 
[0212 박민수]환경 매핑
[0212 박민수]환경 매핑[0212 박민수]환경 매핑
[0212 박민수]환경 매핑MoonLightMS
 
Rendering realistic Ice objects
Rendering realistic Ice objectsRendering realistic Ice objects
Rendering realistic Ice objectsyong gyun im
 
2018.12.22 깊이 버퍼 그림자 매핑
2018.12.22 깊이 버퍼 그림자 매핑2018.12.22 깊이 버퍼 그림자 매핑
2018.12.22 깊이 버퍼 그림자 매핑Sukwoo Lee
 
Cascade Shadow Mapping
Cascade Shadow MappingCascade Shadow Mapping
Cascade Shadow MappingSukwoo Lee
 
[Paper] eXplainable ai(xai) in computer vision
[Paper] eXplainable ai(xai) in computer vision[Paper] eXplainable ai(xai) in computer vision
[Paper] eXplainable ai(xai) in computer visionSusang Kim
 
이미지프로세싱
이미지프로세싱이미지프로세싱
이미지프로세싱일규 최
 
Voxel based game_optimazation_relelase
Voxel based game_optimazation_relelaseVoxel based game_optimazation_relelase
Voxel based game_optimazation_relelaseYEONG-CHEON YOU
 
[1023 박민수] 깊이_버퍼_그림자
[1023 박민수] 깊이_버퍼_그림자[1023 박민수] 깊이_버퍼_그림자
[1023 박민수] 깊이_버퍼_그림자MoonLightMS
 

What's hot (20)

게임 개발을 위한 렌더링 기법 한성환
게임 개발을 위한 렌더링 기법   한성환게임 개발을 위한 렌더링 기법   한성환
게임 개발을 위한 렌더링 기법 한성환
 
3D Graphics 101
3D Graphics 1013D Graphics 101
3D Graphics 101
 
I phone3d programming - Chap04:깊이와 현실감 향상시키기
I phone3d programming - Chap04:깊이와 현실감 향상시키기I phone3d programming - Chap04:깊이와 현실감 향상시키기
I phone3d programming - Chap04:깊이와 현실감 향상시키기
 
Shadow mapping 정리
Shadow mapping 정리Shadow mapping 정리
Shadow mapping 정리
 
[1023 박민수] 깊이_버퍼_그림자_1
[1023 박민수] 깊이_버퍼_그림자_1[1023 박민수] 깊이_버퍼_그림자_1
[1023 박민수] 깊이_버퍼_그림자_1
 
포인트 셰도우
포인트 셰도우포인트 셰도우
포인트 셰도우
 
Lay Picking
Lay PickingLay Picking
Lay Picking
 
190909 ambient
190909 ambient190909 ambient
190909 ambient
 
[week11] R_ggmap, leaflet
[week11] R_ggmap, leaflet[week11] R_ggmap, leaflet
[week11] R_ggmap, leaflet
 
Bump Mapping
Bump MappingBump Mapping
Bump Mapping
 
[0212 박민수]환경 매핑
[0212 박민수]환경 매핑[0212 박민수]환경 매핑
[0212 박민수]환경 매핑
 
Rendering realistic Ice objects
Rendering realistic Ice objectsRendering realistic Ice objects
Rendering realistic Ice objects
 
2018.12.22 깊이 버퍼 그림자 매핑
2018.12.22 깊이 버퍼 그림자 매핑2018.12.22 깊이 버퍼 그림자 매핑
2018.12.22 깊이 버퍼 그림자 매핑
 
Cascade Shadow Mapping
Cascade Shadow MappingCascade Shadow Mapping
Cascade Shadow Mapping
 
[Paper] eXplainable ai(xai) in computer vision
[Paper] eXplainable ai(xai) in computer vision[Paper] eXplainable ai(xai) in computer vision
[Paper] eXplainable ai(xai) in computer vision
 
이미지프로세싱
이미지프로세싱이미지프로세싱
이미지프로세싱
 
카툰 렌더링
카툰 렌더링카툰 렌더링
카툰 렌더링
 
그림자 이야기
그림자 이야기그림자 이야기
그림자 이야기
 
Voxel based game_optimazation_relelase
Voxel based game_optimazation_relelaseVoxel based game_optimazation_relelase
Voxel based game_optimazation_relelase
 
[1023 박민수] 깊이_버퍼_그림자
[1023 박민수] 깊이_버퍼_그림자[1023 박민수] 깊이_버퍼_그림자
[1023 박민수] 깊이_버퍼_그림자
 

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

[Ndc11 박민근] deferred shading
[Ndc11 박민근] deferred shading[Ndc11 박민근] deferred shading
[Ndc11 박민근] deferred shadingMinGeun Park
 
2015.12.10 defferd renderring_
2015.12.10 defferd renderring_2015.12.10 defferd renderring_
2015.12.10 defferd renderring_재현 최
 
Rendering realistic Ice objects
Rendering realistic Ice objectsRendering realistic Ice objects
Rendering realistic Ice objectsyong gyun im
 
[박민근] 3 d렌더링 옵티마이징_2
[박민근] 3 d렌더링 옵티마이징_2[박민근] 3 d렌더링 옵티마이징_2
[박민근] 3 d렌더링 옵티마이징_2MinGeun Park
 
Hierachical z Map Occlusion Culling
Hierachical z Map Occlusion CullingHierachical z Map Occlusion Culling
Hierachical z Map Occlusion CullingYEONG-CHEON YOU
 
[shaderx6] 3.7 Robust Order-Independent Transparency via Reverse Depth Peelin...
[shaderx6] 3.7 Robust Order-Independent Transparency via Reverse Depth Peelin...[shaderx6] 3.7 Robust Order-Independent Transparency via Reverse Depth Peelin...
[shaderx6] 3.7 Robust Order-Independent Transparency via Reverse Depth Peelin...종빈 오
 
[0312 조진현] good bye dx9
[0312 조진현] good bye dx9[0312 조진현] good bye dx9
[0312 조진현] good bye dx9진현 조
 
Deferred Shading
Deferred ShadingDeferred Shading
Deferred Shading종빈 오
 
Tips and experience of DX12 Engine development .
Tips and experience of DX12 Engine development .Tips and experience of DX12 Engine development .
Tips and experience of DX12 Engine development .YEONG-CHEON YOU
 
gametech 2012 Gladius project
gametech 2012 Gladius projectgametech 2012 Gladius project
gametech 2012 Gladius projectWuwon Yu
 
실전프로젝트 정서경 양현찬
실전프로젝트 정서경 양현찬실전프로젝트 정서경 양현찬
실전프로젝트 정서경 양현찬현찬 양
 
Implements Cascaded Shadow Maps with using Texture Array
Implements Cascaded Shadow Maps with using Texture ArrayImplements Cascaded Shadow Maps with using Texture Array
Implements Cascaded Shadow Maps with using Texture ArrayYEONG-CHEON YOU
 
[GPU Gems3] Chapter 28. Practical Post Process Depth Of Field
[GPU Gems3] Chapter 28. Practical Post Process Depth Of Field[GPU Gems3] Chapter 28. Practical Post Process Depth Of Field
[GPU Gems3] Chapter 28. Practical Post Process Depth Of Field종빈 오
 
Real-Time Global Illumination Techniques
Real-Time Global Illumination TechniquesReal-Time Global Illumination Techniques
Real-Time Global Illumination TechniquesJangho Lee
 
NDC2016 프로젝트 A1의 AAA급 캐릭터 렌더링 기술
NDC2016 프로젝트 A1의 AAA급 캐릭터 렌더링 기술NDC2016 프로젝트 A1의 AAA급 캐릭터 렌더링 기술
NDC2016 프로젝트 A1의 AAA급 캐릭터 렌더링 기술Ki Hyunwoo
 
Reflective Shadow Maps
Reflective Shadow MapsReflective Shadow Maps
Reflective Shadow MapsBongseok Cho
 
NDC11_슈퍼클래스
NDC11_슈퍼클래스NDC11_슈퍼클래스
NDC11_슈퍼클래스noerror
 
Tips and experience_of_dx12_engine_development._ver_1.2
Tips and experience_of_dx12_engine_development._ver_1.2Tips and experience_of_dx12_engine_development._ver_1.2
Tips and experience_of_dx12_engine_development._ver_1.2YEONG-CHEON YOU
 
[IGC2018] 유영천 개발자 - Voxel기반 네트워크 게임 최적화기법
[IGC2018] 유영천 개발자 - Voxel기반 네트워크 게임 최적화기법[IGC2018] 유영천 개발자 - Voxel기반 네트워크 게임 최적화기법
[IGC2018] 유영천 개발자 - Voxel기반 네트워크 게임 최적화기법강 민우
 
Gpu Gems 2 Chapter 15 Sketchy Rendering
Gpu Gems 2 Chapter 15 Sketchy RenderingGpu Gems 2 Chapter 15 Sketchy Rendering
Gpu Gems 2 Chapter 15 Sketchy Renderingyong gyun im
 

Similar to SGL : 소프트웨어 3D 렌더링 엔진 (20)

[Ndc11 박민근] deferred shading
[Ndc11 박민근] deferred shading[Ndc11 박민근] deferred shading
[Ndc11 박민근] deferred shading
 
2015.12.10 defferd renderring_
2015.12.10 defferd renderring_2015.12.10 defferd renderring_
2015.12.10 defferd renderring_
 
Rendering realistic Ice objects
Rendering realistic Ice objectsRendering realistic Ice objects
Rendering realistic Ice objects
 
[박민근] 3 d렌더링 옵티마이징_2
[박민근] 3 d렌더링 옵티마이징_2[박민근] 3 d렌더링 옵티마이징_2
[박민근] 3 d렌더링 옵티마이징_2
 
Hierachical z Map Occlusion Culling
Hierachical z Map Occlusion CullingHierachical z Map Occlusion Culling
Hierachical z Map Occlusion Culling
 
[shaderx6] 3.7 Robust Order-Independent Transparency via Reverse Depth Peelin...
[shaderx6] 3.7 Robust Order-Independent Transparency via Reverse Depth Peelin...[shaderx6] 3.7 Robust Order-Independent Transparency via Reverse Depth Peelin...
[shaderx6] 3.7 Robust Order-Independent Transparency via Reverse Depth Peelin...
 
[0312 조진현] good bye dx9
[0312 조진현] good bye dx9[0312 조진현] good bye dx9
[0312 조진현] good bye dx9
 
Deferred Shading
Deferred ShadingDeferred Shading
Deferred Shading
 
Tips and experience of DX12 Engine development .
Tips and experience of DX12 Engine development .Tips and experience of DX12 Engine development .
Tips and experience of DX12 Engine development .
 
gametech 2012 Gladius project
gametech 2012 Gladius projectgametech 2012 Gladius project
gametech 2012 Gladius project
 
실전프로젝트 정서경 양현찬
실전프로젝트 정서경 양현찬실전프로젝트 정서경 양현찬
실전프로젝트 정서경 양현찬
 
Implements Cascaded Shadow Maps with using Texture Array
Implements Cascaded Shadow Maps with using Texture ArrayImplements Cascaded Shadow Maps with using Texture Array
Implements Cascaded Shadow Maps with using Texture Array
 
[GPU Gems3] Chapter 28. Practical Post Process Depth Of Field
[GPU Gems3] Chapter 28. Practical Post Process Depth Of Field[GPU Gems3] Chapter 28. Practical Post Process Depth Of Field
[GPU Gems3] Chapter 28. Practical Post Process Depth Of Field
 
Real-Time Global Illumination Techniques
Real-Time Global Illumination TechniquesReal-Time Global Illumination Techniques
Real-Time Global Illumination Techniques
 
NDC2016 프로젝트 A1의 AAA급 캐릭터 렌더링 기술
NDC2016 프로젝트 A1의 AAA급 캐릭터 렌더링 기술NDC2016 프로젝트 A1의 AAA급 캐릭터 렌더링 기술
NDC2016 프로젝트 A1의 AAA급 캐릭터 렌더링 기술
 
Reflective Shadow Maps
Reflective Shadow MapsReflective Shadow Maps
Reflective Shadow Maps
 
NDC11_슈퍼클래스
NDC11_슈퍼클래스NDC11_슈퍼클래스
NDC11_슈퍼클래스
 
Tips and experience_of_dx12_engine_development._ver_1.2
Tips and experience_of_dx12_engine_development._ver_1.2Tips and experience_of_dx12_engine_development._ver_1.2
Tips and experience_of_dx12_engine_development._ver_1.2
 
[IGC2018] 유영천 개발자 - Voxel기반 네트워크 게임 최적화기법
[IGC2018] 유영천 개발자 - Voxel기반 네트워크 게임 최적화기법[IGC2018] 유영천 개발자 - Voxel기반 네트워크 게임 최적화기법
[IGC2018] 유영천 개발자 - Voxel기반 네트워크 게임 최적화기법
 
Gpu Gems 2 Chapter 15 Sketchy Rendering
Gpu Gems 2 Chapter 15 Sketchy RenderingGpu Gems 2 Chapter 15 Sketchy Rendering
Gpu Gems 2 Chapter 15 Sketchy Rendering
 

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

  • 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 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
  • 9. Backface Culling a b c d e If VP dot 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 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 한다
  • 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