a ten-minute guide for qt developers - kdab · implement the necessary physics equations in your...
TRANSCRIPT
PBRBasicsAten-minuteGuideforQtdevelopers
DrSeanHarmerManagingDirector–UKTheKDABGroupApril2016
(ImagecourtesyofNVIDIA)
KDAB—theQt,OpenGLandC++experts 2
Physicallybasedrendering(PBR)emulatestheinteractionbetweenlightandmaterialsandisatrendinreal-timerendering.Here’saten-minuteguidetotheessentials.
1
PBRBasicsforQtDevelopers
Whatexactlyisphysicallybasedrendering(PBR)?Itisthelatestinanever-endingpursuitofmorerealisticcomputergeneratedimagery,asystemthatreplacescommonshortcutsforrenderingsurfaceswithmethodologiesrootedinthephysicalworld.Fastbecomingastandardingamedevelopmentcircles,PBRisageneralsetofprinciplesratherthanahard-and-faststandard,meaningthatyoucanfindmultipleinterpretationsthatallrightfullycallthemselvesPBR.TheprimarydefiningfeatureofanyPBRsystemthough,isthatitmoreaccuratelysimulatesthebehavioroflightthroughthemethodicalapplicationofreflection,scattering,andabsorptionphysics.
Otherthanenhancedrealism,oneofthebiggestbenefitsofaPBRapproachisthatitismuchmorefoolproof.PBRrendersmaterialsthatlookcorrectregardlessofthelightingenvironment.Artistsnolongerneedtotinkerwithesotericparametersoftheirobjectstogetthingsto“lookright”becausetheshaderproperlyrendersanobject’slookbasedonitspropertiesandthegivenlighting.What’smore,PBR’sinherentabilitytocreategreat-lookinggraphicswithconsistentlydefinedpropertiesmakesiteasiertocollaborateandshareobjectlibraries.
Thewords“physical”and“physics”bothderivefromtheLatinwordfornature,soit’snotacoincidencethatphysicalrenderingthatmimicsnaturerequiresphysics.Butaren’twealreadyemulatingphysicsinhowwemimicthepathoflightinexistingnon-PBRrenderingmodels?Yesandno.Let’stakealookatthemainpropertiesthatdistinguishPBRfromearliermodels.
Material
Representinganobject’stexturewithphysicallyderivedpropertiesisprobablythemostdistinguishingfeatureofaPBRsystem.Whiletheremaybedifferencesinthepropertiesofanygivenimplementation,thesethreefundamentalattributesarecommontonearlyall.
KDABdemoofDodgeViperusingPBR
KDAB—theQt,OpenGLandC++experts 3
PBRdiffersfromolderrenderingmodelsinthattheGPUshaderscancreaterealisticrenderingwithoutneedingspecializedobjecthintsorlightingtricks.
2
Albedo
Thealbedoofanobjectisthecolorofitsdiffusereflectedlight.Thinkofthisasthecoloroftheobjectunderperfectlyeven,omni-directional,balancedwhitelight.Youmightbethinkingalbedoseemslikejustamorescientificnamefor“diffusecolor”—what’sthedifference?PBRdiffersfromolderrenderingmodelsinthatshadercomputationstaketheplaceoftexturehints(inlegacyOpenGL)ornon-energyconservingshaderformulations.PBRdoesnotneedtotweakcolorsorincludedirectionallighthighlightstoensuretheobjectdisplaysproperlyunderthegivenlightingconditions.Younolongerneedextra“artistsupplied”informationtotricktherenderingengineintodisplayingasdesired.WithPBR,yourepresentanobjectwithrealphysicalcharacteristicsandaPBRtexturemapofanobjectcontainsitsflat,unalteredcolor.
Conductivity
We’renotusedtothinkingabouttheconductivityofasurfacetounderstandhowtorenderit.Butrememberingthatlightisactuallyanelectromagneticphenomenon,itmakessensethataPBRsystemneedstoknowanobject’sconductivitytopredicthowlightwillinteractwithitssurface.Ameasureofconductivity—oftensimplifiedas“metalness”—specifieshowstronglylightwillreflect,aswellaswhetherreflectedlightwillshifttowardsanewhue.Insulatingsurfaces(likerubber,paint,orwood)absorbmostlighthittingthesurface,whileconductingsurfaces(mostmetals)reflectmostlightandpotentiallycolorit.SomePBRsystemsareabletoalsospecifymaterialslikerubies,emeralds,orsapphiresassemi-conductors—somethingbetweenaconductorandaninsulator—allowingpartialreflection,absorption,andcolorationoflight.
Aconductivitymapallowsthe“metalness”propertytovaryacrossanobject.Conductivitytexturescanrealisticallydepictpaintedmetalbyindicatingwherethesurfaceispainted(anddiffuselyreflectinglight),andwheretheunderlyingmetalisvisiblethroughwearorscratches(andreflectinglightinaspecularmanner).
“Bymodelingphysicalphenomena
ratherthanapproximating
observation,wecanachievemore
mathematicallystableand
photorealisticvisualfidelity”
KorayHagen,Sony
KDAB—theQt,OpenGLandC++experts 4
OnewayinwhichthemicrofacettheorycomesintoPBRsystemsisintheselectionoftheshaderalgorithmsusedtocalculatethespecularreflection.
3
Microfacets
Understandingamaterial’sappearancerequiresanunderstandingofthemicroscopicpropertiesofthesurface.Ifthesurfaceisbrokenintomanytinyrandomlyorientedfacets,itwillspreadreflectedlightacrossawiderangeofangles,blurringreflectionsandspreadingouthighlights.Ifthesurfaceisverysmooth,reflectedlightwillbouncebackinapreciseanglefromthesurface,resultinginsharpreflectionsandnarrowhighlights.Ofcourseit’scompletelyimpracticaltospecifymicroscopicsurfacecharacteristicswithatremendousarrayofpolygons,sogenerallya“roughness”mapisusedtospecifythemicroscopicnatureofasurface.
Aroughnessmapmayalsobepairedwithacavitymap,whichcapturesfeaturesthatarelargerthanthesurfaceroughnessbutalsomuchsmallerthantheobject’spolygonmesh.Thosesmallsurfacefeatureshavethepropertyoftrappingandabsorbinglight.Acavitymapallowstherenderertomoreaccuratelyrepresentfeatureslikepits,nicks,groovesorotherfeaturesthatareimpracticaltorepresentintriangles.Inpractice,thisisoftenrepresentedbythecombinationofaheightmapandanormalmap,andusedinconjunctionwithoneofanumberofpossibleocclusionmappingalgorithms.
Inadditiontotheroughnessmap,theotherwayinwhichthemicrofacettheorycomesintoPBRsystemsisintheselectionoftheshaderalgorithmsusedtocalculatethespecularreflection.Manysuchalgorithmsexist;eachspecializedtobesthandlecertainlightingconditionsormaterials.Usingdifferentalgorithmsallowsthenumberandorientationofasurface’smicrofacetstoreactdifferentlytolightdependingonanobject’sdesiredappearance.Forexample,theGGXdistributiongivesawiderfalloffforthespecularhighlightsthanthetraditionalBlinn-Phongmodel,providingabetter-lookingappearanceforrealworldsurfaces.Therearealsoshaderstailoredforspecificusecases,suchashandlingroughmattesurfaceslikeclaypotsordealingwithtransparentmaterials.Generallyyou’llwanttominimizethetotalnumberofshadersemployed,aseachshaderchangerequiresacostlycontextshiftontheGPU.
Nowthatwe’redonetalkingaboutmaterials,whatotherfeaturesdistinguishaphysicallybasedrenderer?TherearetwomainbehaviorsoflightthatchangewithinaPBRsystem.
Microfacetscontrolreflectionsfromroughness
ofthecarpettosmoothnessofthechairs
(ImagecourtesyofNVIDIA)
KDAB—theQt,OpenGLandC++experts 5
PBR’semulationoftheFresneleffectshowslightataveryshallowanglecreatingbrightreflectionsfor“shiny”objects…andforflatandmatteobjects.
4
Conservationofenergy
Thisisn’tjustalawfromyourundergraduatephysicsclass.It’sanobservationthattheamountoflightanobjectreflectscanneverbemorethantheamountoflighthittingthatobject.Althoughthismightseemobvious,earliermodelstoemulatespecularhighlights(suchastheBlinn-Phongreflectionmodel)oftenresultedinproducingmorelightthanwhatactuallyhitthesurface.Whileitmostlyworks,italsodoesn’tlooknatural.
ObeyingconservationofenergyinPBRmeansthattheamountoflightreflectedbydiffuseandspecularsourcesshouldneverexceed100%.(Ofcoursethisruledoesn’tapplyiftheobjectrenderedisalightemitter,likeaneonsignorfluorescenttube.)Conservationofenergyandsurfaceroughnesscombinetocontrolanobject’shighlightsandoverallappearance.Anobjectwitharoughsurfacereflectsmorediffuselight,whileasmoothsurfacereflectsmorehighlights.Butduetoconservationofenergy,switchinganobject’stexturebetweenroughandsmoothdoesnotchangethetotalamountoflightreflected.
Fresneleffect
Haveyounoticedthatifyoulookstraightdownintoapoolyoucanseethebottombutifyoulookacrossitssurfaceyou’llseeareflectionofthesky?ThatisduetotheFresneleffect,whichinplainEnglishmeansthemoreglancinganangleoflightthathitsasurface,themorethatsurfacewillreflectthelight.ThecriticalthingthatmakesPBRdifferentfromotherrenderingmethodsisanacknowledgementthattheFresneleffectdoesn’tjustapplyto“shiny”objects(likethesurfaceofapool),itappliestoeveryobject.Yes,evenseeminglydrabsurfaceslikebricksandcardboardexhibittheFresneleffect.
SimulatingtheFresneleffectwithprecisionrequiresaconsiderableamountofcomplicatedmath,asignificantspeedconcerninareal-timerenderingsystem.InPBRsystemsthatneedrapidrendering,aroughandreadyapproximationfortheFresneleffectcomputesaninterpolatedreflectedcolorusingtheangleoflight,theconductorcolor,andthemetalnessmap.
“Physicallybasedrenderingisgreat
becauseitsimplifiestheassetcreation
processandmakesitdifficultfor
artiststocreateunrealisticresults”
MartinThomas,
Extremeistan
KDAB—theQt,OpenGLandC++experts 6
ShinyslatetilesshowaninstanceoftheFresneleffect
(ImagecourtesyofNVIDIA)
GettinggraphicstodisplaywithaPBRrenderingmodelcomesdowntousingaPBR-awareengineandprovidingmaterialinformationinyourtextures.
5
UsingPBR
GettingyourgraphicstodisplaywithaPBRrenderingmodelcomesdowntousingaPBR-awareengineandprovidingappropriatematerialinformationinyourtextures.Manyexistingrenderingengines(UnrealEngine4,Unity5,Frostbite)andtools(Marmoset,Sketchfab)havealreadymadethemovetoPBRforyou.However,ifyouaren’tusinganexistingengine,you’llneedtoimplementthenecessaryphysicsequationsinyourshader.
Ifyou’reusingQt,PBRcanbeimplementedwithcustomshadersinQt3D.Foranexampleofthisinaction,seeourDodgeViperdemo.ThisdemoshowsamixofstandardQtcontrolsmixedwithPBR-based3Drendering,andismadepossiblethroughanewPBRlayerthatKDABisdevelopingontopofQt3D.WeareupstreamingthisQtPBRcomponentintoQtAutomotiveasafirsttestdeploymentofthetechnology.TheeventualgoalistomakeitpartofafutureQt3Drelease,makingQtjustascapableandcurrentastherestofthegraphicsworld.
KDAB—theQt,OpenGLandC++experts 7
6
AbouttheKDABGroup
TheKDABGroupistheworld'sleadingsoftwareconsultancyforarchitecture,developmentanddesignofQt,C++andOpenGLapplicationsacrossdesktop,embeddedandmobileplatforms.KDABisthebiggestindependentcontributortoQt.Ourexpertsbuildrun-times,mixnativeandwebtechnologies,solvehardwarestackperformanceissuesandportingproblemsforhundredsofcustomers,manyamongtheFortune500.KDAB’stoolsandextensiveexperienceincreating,debugging,profilingandportingcomplexapplicationshelpdevelopersworldwidetodeliversuccessfulprojects.KDAB’strainers,allfull-timedevelopers,providemarketleading,hands-on,trainingforQt,OpenGLandmodernC++inmultiplelanguages.Foundedin1999,KDABhasofficesthroughoutNorthAmericaandEurope.
www.kdab.com
©2016theKDABGroup.KDABisaregisteredtrademarkoftheKDABGroup.Allothertrademarksbelongtotheirrespectiveowners.