textures - github pages · opengl texturing snippet cs 148: introduction to computer graphics and...
TRANSCRIPT
![Page 1: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/1.jpg)
CS 148: Summer 2016Introduction of Graphics and ImagingZahid Hossain
Textures
http://www.pling.org.uk/cs/cgv.html
![Page 2: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/2.jpg)
TextureMapping§ Atechniqueforspecifyingvariationsinsurfacereflectancepropertiesofan
object§ Storethereflectanceasanimageand“map”itontotheobject§ Thestoredimageiscalledatexturemap
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 2
![Page 3: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/3.jpg)
§ Atexturemapisdefiedinitsown2Dcoordinatesystem,parameterizedby(u,v)
§ Establishacorrespondencebyassigning(u,v)coordinatestotrianglevertices
TextureCorrespondence
(0,0) (1,0)
(0,1) (1,1)
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 3
![Page 4: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/4.jpg)
OpenGLTexturingSnippet
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4
![Page 5: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/5.jpg)
§ Then,foreachpixelinsideatriangle,calculatethepixel’s(u,v)texturecoordinatesusingbarycentric interpolationofthetrianglevertices’texturecoordinates
TextureCoordinates
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 5
![Page 6: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/6.jpg)
PixelColor§ Giventhepixel’s(u,v)texturecoordinates,useinterpolationinthetexture
maptofindthepixel’scolor
??
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 6
![Page 7: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/7.jpg)
PixelColor:NearestNeighbor
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 7
![Page 8: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/8.jpg)
PixelColor:BilinearInterpolation
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 8
LinearlyInterpolate
![Page 9: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/9.jpg)
PixelColor:BilinearInterpolation
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 9
AnotherLinearlyIn
terpolate
![Page 10: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/10.jpg)
NearestNeighborVsBilinear
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 10
![Page 11: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/11.jpg)
NearestNeighborVsBilinear
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 11
More on this when we discuss “Sampling”
![Page 12: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/12.jpg)
ScreenSpacevs.WorldSpace§ Triangleschangeshapenonlinearlyviaperspectivetransformation,
leadingtodifferentbarycentricweightsbeforeandaftertheperspectivetransformation
§ Interpolatinginscreenspaceresultsintexturedistortion§ Interpolatinginworldspacerequiresprojectingallpixellocations
backwardsfromscreenspacetoworldspace,whichisexpensive
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 12
![Page 13: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/13.jpg)
TextureDistortion
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 13
p’0
p’1
p0
p1𝑠 ≠ 0.5
𝑡 = 0.5
𝑡: Screen-spaceparameter𝑠:World-spaceparameter
![Page 14: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/14.jpg)
TextureDistortion
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 14
p’0
p’1
p0
p1𝑡 ≠ 0.5
𝑠 = 0.5
𝑠: Screen-spaceparameter𝑡:World-spaceparameter
Screen-space and World-space parameters don’t match !
![Page 15: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/15.jpg)
TextureDistortion§ Uniformincrementsalongtheedgeinworldspacedonotcorrespondtouniformincrements
alongtheedgeinscreenspace§ Barycentric interpolation (whichislinear)doesnotaccountforthisnonlinearity
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 15
![Page 16: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/16.jpg)
MeshRefinement§ Refinementofthetrianglemeshimprovestheresult§ Anonlinearfunctioncanbeapproximatedasa
piecewiselinearfunctioniftheintervalsaresmallenough
§ Howeversomeerrorsarestillobvious,especiallyatT-junctionswherelevels-of-refinementchange
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 16
Subdivide
Tjunction
![Page 17: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/17.jpg)
MeshRefinement
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 17
Does not work !
![Page 18: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/18.jpg)
PerspectiveCorrectInterpolation
§ Findtherelationshipbetweenthebarycentricweightsinscreenspaceandthoseinworldspace
§ Usethisrelationshiptocomputetheworldspacebarycentric weightsfromthescreenspacebarycentric weights
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 18
![Page 19: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/19.jpg)
PerspectiveCorrectInterpolation
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 19
Twopoints inworldspace
![Page 20: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/20.jpg)
PerspectiveCorrectInterpolation
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 20
Twopoints inworldspace
Interpolation inworldspace
![Page 21: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/21.jpg)
PerspectiveCorrectInterpolation
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 21
Twopoints inworldspace
Interpolation inworldspace
Projecttheinterpolatedpointonthescreen
![Page 22: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/22.jpg)
PerspectiveCorrectInterpolation
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 22
Twopoints inworldspace
Interpolation inworldspace
Projecttheinterpolatedpointonthescreen
![Page 23: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/23.jpg)
PerspectiveCorrectInterpolation
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 23
Interpolationofthesametwopoints inscreenspace(afterprojection)
![Page 24: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/24.jpg)
PerspectiveCorrectInterpolation
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 24
Interpolationofthesametwopoints inscreenspace(afterprojection)
Screenspacepointandworld-spacepointafterprojectionmustmatch
![Page 25: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/25.jpg)
PerspectiveCorrectInterpolation
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 25
Interpolationofthesametwopoints inscreenspace(afterprojection)
Screenspacepointandworld-spacepointafterprojectionmustmatch
Afteralgebra
![Page 26: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/26.jpg)
PerspectiveCorrectInterpolation
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 26
ScreenSpaceTriangle WorldSpaceTriangle
![Page 27: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/27.jpg)
PerspectiveCorrectInterpolation
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 27
Finally!
![Page 28: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/28.jpg)
PerspectiveCorrectInterpolation
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 28
Finally!
![Page 29: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/29.jpg)
Aliasing
Whatweget Whatwewant
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 29
![Page 30: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/30.jpg)
Aliasing
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 30
LargetextureSmallimage
Source pixels covers many destination pixels
![Page 31: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/31.jpg)
Aliasing
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 31
LargetextureSmallimage
Source pixels covers many destination pixels
![Page 32: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/32.jpg)
MIPMaps§ Multum inParvo:Muchinlittle,manyinsmallplaces
§ Precomputes thetexturemapsatmultiple resolutions, usingaveraging asalowpassfilter
§ Whentexturemapping, choosetheimagesizethatapproximatelygivesa1to1pixeltotexel correspondence
§ Theaveraging“bakes-in”allthenearbypixelsthatotherwisewouldnotbesampledcorrectly
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 32
![Page 33: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/33.jpg)
MIPMaps§ 4neighboringpixelsofthehigherlevelareaveragedtoformasingle
pixelinthelowerlevel
§ Startingatabaseresolution,youcanstoreEVERYcoarserresolutioninpowersof2
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 33
![Page 34: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/34.jpg)
MIPMaps§ 4neighboringpixelsofthehigherlevelareaveragedtoformasingle
pixelinthelowerlevel
§ Startingatabaseresolution,youcanstoreEVERYcoarserresolutioninpowersof2
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 34
![Page 35: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/35.jpg)
MIPMaps
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 35
![Page 36: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/36.jpg)
MIPMaps
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 36
gluBuild2DMipmaps
![Page 37: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/37.jpg)
Φ
y
AssigningTextureCoordinates§ Forcertainsurfaces,the(u,v)texturecoordinatescanbegenerated
procedurally§ Example:Cylinder
§ maptheucoordinatefrom[0,1]to[0,2 π]forΦ§ mapthevcoordinatefrom[0,1]to[0,h]fory§ Thiswrapstheimagearoundthecylinder
§ Formorecomplexsurfaces,(u,v)mustbedefinedpervertexmanuallyorbyusingproxyobjects
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 37
![Page 38: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/38.jpg)
ProxyObjects– Step1• Assigntexturecoordinatestointermediate/proxyobjects:§ Example:Cylinder§ wraptexturearoundtheoutsideofthecylinder§ notthetoporbottom,inordertoavoiddistortingthetexture
§ Example:Cube§ unwrapthecubeandmaptextureovertheunwrappedcube§ thetextureisseamless acrosssomeoftheedges,butnotnecessarily
others
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 38
![Page 39: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/39.jpg)
ProxyObjects– Step2§ Maptexturecoordinatesfromtheintermediate/proxyobjecttothe
finalobject§ Threewaysofmappingaretypicallyused
§ Usetheintermediate/proxyobject’ssurfacenormal§ Usethetargetobject’ssurfacenormal§ Useraysemanatingfromcenteroftargetobject
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 39
![Page 40: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/40.jpg)
CubeMapping
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 40
http://learnopengl.com/#!Advanced-OpenGL/Cubemaps
![Page 41: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/41.jpg)
ProjectiveTexturing
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 41
• TreatlightSourceasa• Renderthescenenormallyfromtheactualcamera
http://www.nvidia.com/object/Projective_Texture_Mapping.htmlSegal et.al.SIGGRAPH’92
![Page 42: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/42.jpg)
ProjectiveTexturing• AssignTextureCoordinates(s,t,r)toposition(x,y,z)
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 42
![Page 43: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/43.jpg)
ProjectiveTexturing• AssignTextureCoordinates(s,t,r)toposition(x,y,z)
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 43
![Page 44: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/44.jpg)
ProjectiveTexturing• AssignTextureCoordinates(s,t,r)toposition(x,y,z)
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 44
![Page 45: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/45.jpg)
ProjectiveTexturing• AssignTextureCoordinates(s,t,r)toposition(x,y,z)
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 45
So much work just to say (s,t,r) = (x,y,z)Much easily done in newer OpenGL
![Page 46: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/46.jpg)
ProjectiveTexturing
• UseasimilarView(fromthelight’spointofview)andProjectionmatrixtotransformtexturecoordinatestoNDC(-1,1)
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 46
![Page 47: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/47.jpg)
ProjectiveTexturing
• MapNDC(-1,1)toTextureCoordinatespace(0-1)• ScaleandaddBias
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 47
![Page 48: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/48.jpg)
ProjectiveTexturing
• MapNDC(-1,1)toTextureCoordinatespace(0-1)• ScaleandaddBias
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 48
Finaltexturecoordinatesafterperspective-correctinterpolation of
![Page 49: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/49.jpg)
ProjectiveTexturing
• MapNDC(-1,1)toTextureCoordinatespace(0-1)• ScaleandaddBias
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 49
Finaltexturecoordinatesafterperspective-correctinterpolation of
Hardware does it for you :)
![Page 50: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/50.jpg)
HowToSetTextureMatrices?
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 50
![Page 51: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/51.jpg)
HowToSetTextureMatrices?
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 51
Much simpler in newer OpenGL(will discuss later)
![Page 52: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/52.jpg)
ProjectiveTexturing:Issues
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 52
![Page 53: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/53.jpg)
ProjectiveTexturing:Issues
CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 53
SevereAliasing
![Page 54: Textures - GitHub Pages · OpenGL Texturing Snippet CS 148: Introduction to Computer Graphics and Imaging (Summer 2016) – Zahid Hossain 4 § Then, for each pixel inside a triangle,](https://reader035.vdocuments.net/reader035/viewer/2022062414/5f1abd9a0323462506145705/html5/thumbnails/54.jpg)
CS 148: Summer 2016Introduction of Graphics and ImagingZahid Hossain
Textures
http://www.pling.org.uk/cs/cgv.html