Top Banner
PBR Basics A ten-minute Guide for Qt developers Dr Sean Harmer Managing Director – UK The KDAB Group April 2016 (Image courtesy of NVIDIA)
7

A ten-minute Guide for Qt developers - KDAB · implement the necessary physics equations in your shader. If you’re using Qt, PBR can be implemented with custom shaders in Qt3D.

Apr 21, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: A ten-minute Guide for Qt developers - KDAB · implement the necessary physics equations in your shader. If you’re using Qt, PBR can be implemented with custom shaders in Qt3D.

PBRBasicsAten-minuteGuideforQtdevelopers

DrSeanHarmerManagingDirector–UKTheKDABGroupApril2016

(ImagecourtesyofNVIDIA)

Page 2: A ten-minute Guide for Qt developers - KDAB · implement the necessary physics equations in your shader. If you’re using Qt, PBR can be implemented with custom shaders in Qt3D.

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

Page 3: A ten-minute Guide for Qt developers - KDAB · implement the necessary physics equations in your shader. If you’re using Qt, PBR can be implemented with custom shaders in Qt3D.

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

Page 4: A ten-minute Guide for Qt developers - KDAB · implement the necessary physics equations in your shader. If you’re using Qt, PBR can be implemented with custom shaders in Qt3D.

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)

Page 5: A ten-minute Guide for Qt developers - KDAB · implement the necessary physics equations in your shader. If you’re using Qt, PBR can be implemented with custom shaders in Qt3D.

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

Page 6: A ten-minute Guide for Qt developers - KDAB · implement the necessary physics equations in your shader. If you’re using Qt, PBR can be implemented with custom shaders in Qt3D.

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.

Page 7: A ten-minute Guide for Qt developers - KDAB · implement the necessary physics equations in your shader. If you’re using Qt, PBR can be implemented with custom shaders in Qt3D.

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.