1 / 28

Texture Mapping

Texture Mapping. 2001.7.25 김 성 남. Contents. Goal 2D Texture Mapping Texture Filtering Mipmap Sphere Mapping Projective Texture Mapping. Goal. 정교한 물체 표현 Polygon , computation time , memory 개선방법 중의 하나 :Texture Mapping Simplifying objects + texture mapping 현재 많이 사용되는 방법

sunee
Télécharger la présentation

Texture Mapping

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Texture Mapping 2001.7.25 김 성 남 1

  2. Contents • Goal • 2D Texture Mapping • Texture Filtering • Mipmap • Sphere Mapping • Projective Texture Mapping 2

  3. Goal • 정교한 물체 표현 • Polygon , computation time , memory • 개선방법 중의 하나 :Texture Mapping • Simplifying objects + texture mapping • 현재 많이 사용되는 방법 • 3D video game … 3

  4. 2D Texture Mapping (1/3) • 3D object의 surface에 미리 생성해 놓은 textureimage를 mapping 한 후 rendering 하는 방법 Texture Image + = 4

  5. 2D texture mapping (2/3) • 개념적인 계산과정 Texture 좌표계 (2D) Modeling 좌표계 (3D) Window 좌표계 (2D) Surface parameterization 5

  6. 2D texture mapping (3/3) • problems • Texture image의 내용과 그에 관련된 성질들을 어떻게 정의할 것인가? • 한장의 image를 rendering하기위해 여러 개의 texture를 사용할 경우 texture image들을 어떻게 하면 효과적으로 다룰 수 있을 것인가? • Surface parameterization 과정을 어떻게 정의할 것인가? • 각 Pixel에 해당하는 texture color를 어떻게 구할 것인가? • 각 Pixel에 대하여 texture color와 object의 base color와 어떻게 혼합할 것인가? 6

  7. 2D Texture Mapping 구조 Pixel Transfer & Image Subset Pixel Stroage glTexImage1D/2D/3D(*) Texture states Texture memory glTexParameter*(*) glEnable(*)/glDisable(*) Texel Generation glTexEnv*(*) (Ct,At) Texture Application Texturing (Cf,Af) (C,A) Fragment before texturing Fragment after texturing (xwd,ywd) Zwd (r,g,b,a) (s,t,r,q) (xwd,ywd) Zwd (r’,g’,b’,a’) (s,t,r,q) 7 Rasterization

  8. Texture Image 설정(1/8) • Image를 openGL sys’에 맞게 설정 : memory에 저장 • Format : main memory에 저장되어있는 texture image data의 저장형식, 각 texel을 구성하는 요소 값 • Type : 각 필드의 요소 데이터가 실제로 저장되는 type void glTexImage2D(GLenum target,Glint level,Glint internalFormat,Glsizei width, Glsizei height,Glint border,Glenum format,Glenum type,const Glvoid *texels); • GL_RGB,GL_BGR,GL_RGBA,GL_BGRA,GL_RED,GL_GREEN,GL_BLUE,GL_ALPHA,GL_LUMINANCE,GL_LUMINANCE_ALPHAGL_COLOR_INDEX … GL_BYTE,GL_SHORT,GL_INT,GL_FLOAT,GL_BITMAT,… 8

  9. Texture Image 설정(2/8) • Pixel Storage module • Memory에 존재하는 texture data가 (R,G,B,A)형태의 openGL sys’내부에서 사용되는 형식으로 변환 • Format 인자에 대해 어떤 상수값을 설정하건, memory에 저장되어 있는 각 texel 값은 일단 내부적으로 (R,G,B,A) 값으로 변환 • GL_RED의 경우, R 채널 값은 main memory에 저장된 값,G,B는 0, 그리고 A는 1 값으로 변환 • Piexel Transfer & Imaging Subset module • 다음 Pixel 이동 등 프로그래머가 설정한 방식으로 적절히 변환이 되어 texture memory에 올려진다. 9

  10. Texture Image 설정(3/8) • internalFormat : texture memory에 올려지는 각 texel이 실제로 어떤 형식으로 구성이 되는 지를 결정texture image의 texel에 저장될 수 있는 요소 데이터는R,G,B,A,L,I 값 등 38가지의 조합가능 • Level : texture image의 LOD 결정인자 내부형식 사용 RGBA 채널 대응 내부요소 GL_ALPHA A A GL_LUMINANCE R L GL_LUMINACE_ALPHA R,A L,A GL_INTENSITY R I GL_RGB R,G,B R,G,B GL_RGBA R,G,B,A R,G,B,A 10

  11. Texture Image 설정(4/8) • Texture object & binding • 여러장의 texture image를 생성할 경우에 효율을 높이기위한 방법 • Texture image 자체에 대한 정보 + texel 값을 구하는 방식에 대한 모든 정보를 저장하는 일종의 자료구조 • glTexImage2D(*) 함수를 반복적으로 호출하면서 매번 texture image를 texture memory에 올리는 것보다 더 빠르게 texture mapping 계산을 수행 void glGenTextures(Glsizei n, Gluint *textureNames); void glBindTexture(Glenum target, Gluint textureName); void glDeleteTexture(Glsizei n,const Gluint *textureNames); 11

  12. Texture Image 설정(5/8) • Texture states • glTexImage2D(*) : mipmap을 포함한 texture 자체에 대한 인자들로 형성, 해상도,경계두께,내부형식 등 • glTexParameter*(*) : 현재 fragment의 texture좌표가 주어졌을때, texture color를 계산하는데 영향 void glTexParameterf(Glenum target,Glenum pname,Glfloat param); 상태종류 인자 이름(pname) 사용가능 인자(param) 확대 필터 GL_TEXTURE_MAG_FILTER GL_NEAREST,GL_LINEAR 축소 필터 GL_TEXTURE_MIN_FILTER GL_NEAREST,GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_LINEAR 랩 모드(s,t,r) GL_TEXTURE_WRAP_S(_T,_R) GL_CLAMP,GL_REPEAT, GL_CLAMP_TO_EDGE 12

  13. Texture Image 설정(6/8) • Texel Generation module • 현재 처리하려는 fragment에 입힐 texture의 color(Ct,At)를 계산하는 과정 • Texel states module과 texture memory에 저장된 data를이용하여 texel을 생성하는 과정 • Texture Application module • (Ct,At)와 fragment 기반 color(Cf,Af)이 합성하여 fragment의 새로운 color (C,A)를 구하는 과정 void glTexEnvf(Glenum target,Glenum pname, Glfloat param); 13

  14. Texture Image 설정(7/8) 내부형식 GL_REPLACE GL_MODULATE GL_DECAL GL_BLEND GL_ALPHA C=Cf,A=At C=Cf,A=AfAt C=Cf,A=AfAt GL_LUMINANCE C=Lt,A=Af C=CfLt,A=Af C=Cf(1- Lt)+CcLt ,A=Af GL_LUMINACE_ALPHA C=Lt,A=At C=CfLt,A=AfAt C=Cf(1- Lt)+CcLt ,A=AfAt GL_INTENSITY C=It,A=It C=CfIt,A=AfIt C=Cf(1- It)+CcIt ,A=Af (1- It)+AcIt GL_RGB C=Ct,A=Af C=CfCt,A=Af C=Ct,A=Af C=Cf(1- Ct)+CcCt ,A=Af GL_RGBA C=Ct,A=At C=CfCt,A=Af At C=Cf(1-At)+CfAt ,A=At C=Cf(1- Ct)+CcCt ,A=Af At 14

  15. Texture Image 설정(8/8) • Texture 좌표의 설정 및 변환 • object의 modeling단계에서 vertex 좌표와 normal vector,texture좌표를 같이 설정하는 방식 : general • Rendering 계산시 programmer가 설정한 방식으로 각 vertex마다 동적으로 texture좌표를 자동 생성하는 방식 • Environment mapping, Projection mapping void glTexCoord2f(GLfloat s, Glfloat t); 15

  16. t 1.0 s 1.0 Example 16

  17. Texture Filtering(1/5) • Problem • Pixel을 통하여 보이는 texture image의 영역을 대표하는 color를 어떻게 구할 것인가? • Discrete screen space & texture space 사이의 변환을 통한 aliasing 발생을 어떻게 해결할 것인가? Pixel Pixel preimage 역변환 Texture space Screen space 17

  18. Texture Filtering(2/5) • Solution • Ideal • Screen space -> texture space로의 역변환을 통한 pixel의 preimage 영역을 찾아 이 영역에 대한 적분을 통하여 texture image의 color값을 결정 • 많은 계산시간 소요, 실시간 rendering에 부적합 • Sampling & Filtering 이용 • Continous 3D object space <-> Discrete 2D screen space 에서의 sampling & filtering 고려 • Discrete 2D texture space <-> Discrete 2D screen space에서의sampling & filtering 고려 18

  19. Texture Filtering(3/5) • Sampling • Texel에 대해서는 중심점 • Pixel에 대해서는 중심주변의 점 • Filtering • Nearest neighbor filter • Pixel중심에 대응하는 texture space 영역에서 가장 가까운 texel의 color를 texture color로 선택 • Bilinear Interpolation filter • 확대 상황에서는 좋은 결과 • 축소 상황에서는 nearest 비슷 Texel 중심 Pixel 중심 19

  20. Texture Filtering(4/5) 확대와 축소의 경계 확대 축소 texel texel pixel preimage pixel preimage 20

  21. Texture Filtering(5/5) • Average filter • Pixel의 preimage 영역의 모든 texel의 color를 평균 • 이상적인 filter와 가장 근사 (적분 -> 합) • Preimage영역의 texel 수에 따라 계산시간의 차이가 발생-> 실시간 rendering에 부적합 • 보완 • Mipmapping(Trilinear Interpolation filter) 21

  22. Mipmapping(1/3) • 라틴어 Multum In Parvo : 좁은 장소에 많은 것을 집어넣음 • L.Williams,”Pyramidal Parametrics”,SIGGRAPH 83 에서 제안 • Pre-calculation technique • 실시간적인 성능을 내기위해 미리 전처리를 통해 필요한 data 생성 • Multi-resolution technique • Texture image -> s,t축으로 해상도를 반으로 줄여나가는 방법 • 인접한 texel 4개의 평균값을 이용하여 낮은 해상도 image 생성 • Mipmap을 이용하면 texture memory 많이 사용 22

  23. Mipmapping(2/3) • Trilinear Interpolation을 이용한 mipmapping sampling point Level k0 texture Level k0 + 1 texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); 23

  24. Mipmapping(3/3) • Mipmap level 계산 : 정사각형을 통한 preimage 근사 • Area 중심 :aliasing 발생 가능성 높음 • 장축 중심 : Blurring 현상 Area 중심 장축 중심 preimage 24

  25. Texture 좌표의 자동생성 • 일반적인 경우 • Object에 대한 texture 좌표를 미리 계산 • Vertex 좌표를 기술할때 glTexCoord2*(*) 함수를 사용 명시적으로 붙여주는 방식 • Texture가 object에 고정이 되는 정적인 상황 • Object의 vertex에 대한 texture 좌표를 programmer가 동적으로 계산하는 경우 • Object의 vertex 좌표를 사용하여 texture좌표를 생성 • Object coordinates 사용하는 방법 • Eye coordinates 사용하는 방법 • Eye coordinates의 vertex의 normal vector의 방향을 사용하여 texture좌표 생성 void glTexGenf(GLenum coord,GLenum pname,GLfloat param); 25

  26. Sphere Mapping(1/2) • Texture 좌표의 자동생성 • Eye coordinates의 vertex normal vector를 이용 • Environment mapping, specular reflection 등 구현에 사용 • Eye coordinates를 기준으로 수행 t ye 1 (s,t) Reflection direction ze n r 1/2 u xe s V : vertex 1/2 1 Sphere map 26

  27. Sphere map Smooth shading Sphere Mapping(2/2) Sphere mapping을 이용한 Phong shading example Sphere map에 의한 highlight Sphere map에 의한 Phong shading 정반사를 제외한 rendering 27

  28. Projective Texture mapping • 2D texture image를 3D 공간으로 투사, object의 vertex에서의 texture좌표를 동적으로 생성 • Slide projector,spot lighting source,shadow 등의고급 기법을 구현 • M.Segal et al,”Fast Shadow and Lighting Effects Using Texture Mapping”,SIGGRAPH 92 제안 Slide projector 효과 Spot 광원 효과 28

More Related