A Practical and Robust Bump-Mapping Technique for Today’S Gpus
Total Page:16
File Type:pdf, Size:1020Kb
GDCGDCGDC Tutorial:Tutorial:Tutorial: AdvancedAdvancedAdvanced OpenGLOpenGLOpenGL GameGameGame DevelopmentDevelopmentDevelopment A Practical and Robust Bump-mapping Technique for Today’s GPUs MarchMarchMarch 8,8,8, 200020002000 Mark J. Kilgard Graphics Software Engineer NVIDIA Corporation “Hardware Bump Mapping” mostly hype so far PreviousPreviousPrevious techniquestechniquestechniques •••ProneProne Prone tototo aliasingaliasingaliasing artifactsartifactsartifacts •••DoDo Do notnotnot correctlycorrectlycorrectly handlehandlehandle surfacesurfacesurface selfselfself-shadowing--shadowingshadowing •••CutCut Cut tootootoo manymanymany corners,corners,corners, i.e.i.e.i.e. failfailfail tototo renormalize,renormalize,renormalize, etc.etc.etc. •••TooToo Too expensive:expensive:expensive: manymanymany passespassespasses (OIM),(OIM),(OIM), needsneedsneeds accumulationaccumulationaccumulation bufferbufferbuffer ororor glCopyPixelsglCopyPixelsglCopyPixels •••OnlyOnly Only handlehandlehandle infinite,infinite,infinite, nonnonnon-attenuated,--attenuated,attenuated, nonnonnon-spotlight--spotlightspotlight lightslightslights •••AssumeAssume Assume locallocallocal viewerviewerviewer •••CorrectCorrect Correct onlyonlyonly forforfor essentiallyessentiallyessentially flatflatflat surfacessurfacessurfaces •••DifficultDifficult Difficult tototo implementimplementimplement andandand authorauthorauthor Demo! Overview of the Technique UsesUsesUses newnewnew NVIDIANVIDIANVIDIA GPUGPUGPU featuresfeaturesfeatures •••CubeCube Cube mapsmapsmaps ---forfor for perperper-pixel--pixelpixel normalizationnormalizationnormalization –––EXT_texture_cube_mapEXT_texture_cube_map EXT_texture_cube_map extensionextensionextension •••RegisterRegister Register combinerscombinerscombiners ---forfor for perperper-pixel--pixelpixel dotdotdot productsproductsproducts andandand additionaladditionaladditional mathmathmath –––NV_register_combinersNV_register_combiners NV_register_combiners •••AndAnd And dualdualdual-textured--texturedtextured ---forfor for normalizationnormalizationnormalization cubecubecube mapmapmap andandand 2D2D2D normalnormalnormal mapmapmap –––ARB_multitextureARB_multitexture ARB_multitexture Features of the technique CorrectlyCorrectlyCorrectly handleshandleshandles •••SurfaceSurface Surface selfselfself-shadowing--shadowingshadowing forforfor bothbothboth diffusediffusediffuse andandand specularspecularspecular contributionscontributionscontributions •••DiffuseDiffuse Diffuse minificationminificationminification sososo thatthatthat bumpedbumpedbumped objectsobjects inin thethe distancedistance looklooklook dimmerdimmerdimmer thanthanthan equivalentequivalentequivalent smoothsmoothsmooth distantdistantdistant objectsobjectsobjects •••MipmapMipmap Mipmap filteringfilteringfiltering ofofof normalnormalnormal mapsmapsmaps minimizesminimizesminimizes aliasingaliasingaliasing •••Local,Local, Local, attenuated,attenuated,attenuated, and/orand/orand/or spotspotspot-light--lightlight lightlightlight sourcessources withwithwith locallocallocal viewerviewerviewer •••AmbientAmbient Ambient andandand surfacesurfacesurface decalsdecalsdecals Anatomy of the technique ThreeThreeThree passespassespasses (or(or(or justjustjust twotwotwo ififif nonono specular)specular)specular) ××× +++ diffusediffusediffuse decaldecaldecal specularspecularspecular High-level view TangentTangentTangent spacespacespace perperper-pixel--pixelpixel lightinglightinglighting [Peercy[Peercy[Peercy 97]97]97] •••CPUCPU CPU suppliessuppliessupplies tangenttangenttangent spacespacespace lightlightlight vectorvectorvector ororor halfhalfhalf-angle--angleangle vectorvectorvector asasas (s,t,r)(s,t,r)(s,t,r) texturetexturetexture coordinatescoordinatescoordinates –––linearlylinearly linearly interpolatedinterpolatedinterpolated –––normalizednormalized normalized bybyby ananan RGB8RGB8RGB8 cubecubecube mapmapmap texturetexturetexture •••NormalNormal Normal mapmapmap isisis RGBA8RGBA8RGBA8 2D2D2D texturetexturetexture –––RGBRGB RGB containscontainscontains “compressed”“compressed”“compressed” normalizednormalizednormalized perturbedperturbed normalnormal –––AlphaAlpha Alpha containscontainscontains averagedaveragedaveraged normalnormalnormal shorteningshorteningshortening •••ButBut But nonono hardhardhard-wired--wiredwired perperper-pixel--pixelpixel “lighting“lighting“lighting engine”!engine”!engine”! Per-pixel lighting building blocks CubeCubeCube mapsmapsmaps enableenableenable perperper-pixel--pixelpixel vectorvectorvector normalizationnormalizationnormalization •••CubeCube Cube mapmapmap normalizesnormalizesnormalizes interpolatedinterpolatedinterpolated (s,t,r)(s,t,r)(s,t,r) intointointo RGBRGBRGB –––(s,t,r)(s,t,r) (s,t,r) isisis interpolatedinterpolatedinterpolated perperper-vertex--vertexvertex lightlightlight ororor halfhalfhalf-angle--angleangle vectorvectorvector •••CombinersCombiners Combiners expandexpandexpand RGBRGBRGB fromfromfrom [0,1][0,1][0,1] rangerangerange tototo [[[-1,1]--1,1]1,1] rangerangerange –––expansionexpansion expansion donedonedone bybyby registerregisterregister combinerscombinerscombiners ••• OptimizationOptimizationOptimization::: IfIfIf infiniteinfiniteinfinite viewerviewerviewer ororor infiniteinfiniteinfinite lightlightlight used,used,used, halfhalfhalf-angle--angleangle cancancan bebebe computedcomputedcomputed withinwithinwithin thethethe cubecubecube map!map!map! •••32x32x632x32x6 32x32x6 RGB8RGB8RGB8 cubecubecube mapmapmap texturetexturetexture isisis sufficientsufficientsufficient Per-pixel lighting building blocks RegisterRegisterRegister combinerscombinerscombiners performperformperform perperper-pixel--pixelpixel mathmathmath •••SignedSigned Signed mathmathmath forforfor dotdotdot productsproductsproducts –––LL L dotdotdot N’N’N’ forforfor diffuse,diffuse,diffuse, HHH dotdotdot N’N’N’ forforfor BlinnBlinnBlinn specularspecularspecular –––LL L andandand HHH properlyproperlyproperly normalizednormalizednormalized bybyby cubecubecube mapmapmap –––PrePre Pre-normalized--normalizednormalized N’N’N’ suppliedsuppliedsupplied bybyby normalnormalnormal mapmapmap •••UsesUses Uses tangenttangenttangent spacespacespace LLLzzz forforfor geometricgeometricgeometric surfacesurfacesurface selfselfself-shadowing--shadowingshadowing •••ConstantConstant Constant colorcolorcolor forforfor addingaddingadding ininin ambientambientambient contributioncontributioncontribution •••SuccessiveSuccessive Successive squaringsquaringsquaring forforfor specularspecularspecular exponentexponent Surface self-shadowing TwoTwoTwo kindskindskinds ofofof selfselfself-shadowing--shadowingshadowing •••max(0,max(0, max(0, LLL dotdotdot N’)N’)N’) basedbasedbased ononon thethethe perturbedperturbedperturbed normalnormalnormal •••AlsoAlso Also shouldshouldshould clampclampclamp whenwhenwhen LLL dotdotdot NNN goesgoesgoes negative!negative!negative! N’N’N’ NNN NNN N’N’N’ LLL LLL SurfaceSurface shouldshould selfself-shadow-shadow SurfaceSurface shouldshould selfself-shadow-shadow duedue toto perturbedperturbed normal,normal, duedue toto unperturbedunperturbed normal,normal, I.e.,I.e., LL dotdot N’<0N’<0 I.e.,I.e., LL dotdot N<0N<0 Surface self-shadowing SelfSelfSelf-shadowing--shadowingshadowing computationcomputationcomputation •••TechniqueTechnique Technique supportssupportssupports bumpedbumpedbumped selfselfself-shadowing--shadowingshadowing bybyby computingcomputingcomputing min(8*max(0,Lz),min(8*max(0,Lz),min(8*max(0,Lz), 1)1)1) *** max(0,max(0,max(0, LLL dotdotdot N’)N’)N’) •••AlsoAlso Also stashesstashesstashes thisthisthis selfselfself-shadowing--shadowingshadowing termtermterm ininin destinationdestinationdestination alphaalphaalpha min(8*max(0,Lz),min(8*max(0,Lz),min(8*max(0,Lz), 1)1)1) •••SpecularSpecular Specular passpasspass blendsblendsblends withwithwith DST_ALPHA,ONEDST_ALPHA,ONEDST_ALPHA,ONE computingcomputingcomputing min(8*max(0,Lz),min(8*max(0,Lz),min(8*max(0,Lz), 1)1)1) *** max(0,max(0,max(0, HHH dotdotdot N’)^8N’)^8N’)^8 •••IlluminationIllumination Illumination doesdoesdoes notnotnot appearappearappear ononon geometricgeometricgeometric “back“back“back side”side”side” –––SteepSteep Steep ramprampramp avoidsavoidsavoids winkingwinkingwinking andandand poppingpoppingpopping atatat selfselfself-shadow--shadowshadow boundaryboundaryboundary Complete lighting model MoreMoreMore perperper-pixel--pixelpixel mathmathmath thanthanthan youyouyou mightmightmight think!think!think! •••AmbientAmbient Ambient === constantconstantconstant •••DiffuseDiffuse Diffuse === min(8*max(0,Lz),min(8*max(0,Lz),min(8*max(0,Lz), 1)1)1) *** max(0,max(0,max(0, LLL dotdotdot N’)N’)N’) •••SpecularSpecular Specular === min(8*max(0,Lz),min(8*max(0,Lz),min(8*max(0,Lz), 1)1)1) *** max(0,max(0,max(0, HHH dotdotdot N’)^8N’)^8N’)^8 •••FinalFinal Final === (Diffuse(Diffuse(Diffuse +++ Ambient)Ambient)Ambient) *** DecalDecalDecal +++ SpecularSpecularSpecular AttenuationAttenuationAttenuation and/orand/orand/or spotlightspotlightspotlight •••FinalFinal Final === (Attenuate*Diffuse(Attenuate*Diffuse(Attenuate*Diffuse +++ Ambient)Ambient)Ambient) *** DecalDecalDecal +++ Attenuate*SpecularAttenuate*SpecularAttenuate*Specular Self-shadowing example LightLight leaksleaks ontoonto torustorus “back“back side”side” ProperProper geometricgeometric duedue toto badbad geometricgeometric selfself-shadowing-shadowing selfself-shadowing!-shadowing! Some CPU work required PerPerPer-vertex--vertexvertex workworkwork •••ModelModel Model requiresrequiresrequires perperper-vertex--vertexvertex tangenttangenttangent spacespacespace