16
What does “linear” mean in a linear workflow Let’s start with the basics when talking about a linear workflow. We need to define what the word linear actually means. There is linear “light” and linear “data”. Linear light is the way that we want to represent images to our eyes. Linear data is how we want to store the image data. We store things with linear data in mind because we need to account for gamma in display devices. Most computer display devices have an inherent gamma of approximately 1/ 2.2 = 0.4545 . This is what’s called sRGB gamma. Video monitors have a gamma of rec709. They are close in values but not exactly the same. Having said that, a gamma of 0.4545 is not exactly sRGB or rec709 but we’re going to call that close enough for our purposes. Because our monitors darken images, we need to counteract that. Here is a bit of a graph of what monitors do to image data, the linear image data, and the sRGB curve that we use to correct for the monitor. The math that creates the curves is approximately as follows: Monitor Effect = pow(pixel value, 2.2) sRGB – pow(pixel value, (1/2.2)) Robert Nederhorst 3/12/09 10:47 PM Deleted: 2.2

What does “linear” mean in a linear workflo · monitors darken images, we need to counteract that. Here is a bit of a ... know that at around 4‐5pm you would see more bounce

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: What does “linear” mean in a linear workflo · monitors darken images, we need to counteract that. Here is a bit of a ... know that at around 4‐5pm you would see more bounce

Whatdoes“linear”meaninalinearworkflow

Let’sstartwiththebasicswhentalkingaboutalinearworkflow.Weneedtodefinewhatthewordlinearactuallymeans.Thereislinear“light”andlinear“data”.Linearlightisthewaythatwewanttorepresentimagestooureyes.Lineardataishowwewanttostoretheimagedata.Westorethingswithlineardatainmindbecauseweneedtoaccountforgammaindisplaydevices.Mostcomputerdisplaydeviceshaveaninherentgammaofapproximately1/2.2=0.4545.Thisiswhat’scalledsRGBgamma.Videomonitorshaveagammaofrec709.Theyarecloseinvaluesbutnotexactlythesame.Havingsaidthat,agammaof0.4545isnotexactlysRGBorrec709butwe’regoingtocallthatcloseenoughforourpurposes.Becauseourmonitorsdarkenimages,weneedtocounteractthat.Hereisabitofagraphofwhatmonitorsdotoimagedata,thelinearimagedata,andthesRGBcurvethatweusetocorrectforthemonitor.

Themaththatcreatesthecurvesisapproximatelyasfollows:

MonitorEffect=pow(pixelvalue,2.2)sRGB–pow(pixelvalue,(1/2.2))

Robert Nederhorst � 3/12/09 10:47 PMDeleted: 2.2

Page 2: What does “linear” mean in a linear workflo · monitors darken images, we need to counteract that. Here is a bit of a ... know that at around 4‐5pm you would see more bounce

Asyoucansee,yourmonitordoesaprettysignificantgammacorrectiontotheimagedatabeingdisplayedonit.Becausewecancorrectforthat,it’snotaproblem,aslongaswetakeafewthingsintoaccount.Let’stalkmoreaboutwhathappenstovaluesbecauseofthiscorrection.AsCGIartists,wehavebecomeaccustomedtoavalueof.5tobeexactly50%ofbrightness.However,that’snottechnicallycorrect,asyoucanseebythepreviouschart.

Lookingatthechartalittlemoreclosely,wecanseethatthehorizontalvalueof0.5isjustbelow0.25ontheverticalaxis.Technicallyit’s0.18.Doesthisseemfamiliar?Usingphotographicterms,that’s18percentgrey.Eighteenpercentgreyintermsoflineardatameans50%ofvisualbrightness.Whyisthisthecase?Well,oureyesareverysensitivetolowlightlevelsandweperceive0.18as0.5.Whenyougotobuya“greycard”ataphotographyshop,itwillbe18%greybutyoureyeswillseeitas50%.So,nowthatweknowthatoureyesturn0.18into0.5,andourmonitormakesthingsdarker,wecorrectforthatinsomethingcalledaLUT(lookuptable)thatmapsthevaluesweseeonthemonitortosomethingoureyesareusedto.ThatLUTgetsappliedinseveralplaces.Beforewegetintothethefullnittygrittyofwherealltheplacesshouldbe,let’slookatimagesthatcanhelptellthestoryalittlebetter.

Thefirstsetofimagesisaverysimpleillustrationoflightattenuation.ThefirstimageiswithoutanysRGBapplied.Thesetuphereisa100wattlightinaroomthatis12’x15’x9’,withGIturnedonandaninfinitenumberofGIbounces.Twoproblemsareevidenthere.A100‐wattbulbcaneasilylightthisroom,butthisfirstimagedoesnotshowthatishappening:

Robert Nederhorst � 3/12/09 11:11 PM

Robert Nederhorst � 3/12/09 11:11 PM

Deleted: Usingthehorizontalaxisonthechart,wecanseethatavalueof0.5isvisuallyequaltoaround0.75.That’saprettysignificantdifference.

Deleted: around

Page 3: What does “linear” mean in a linear workflo · monitors darken images, we need to counteract that. Here is a bit of a ... know that at around 4‐5pm you would see more bounce

Inadditiontothelightnotfillingtheroom,thisnonlinearrepresentationofthelightfalloffiswildlyinaccurate.It’sjustugly.However,inthissecondimage,wecanseethatthelightiscertainlylightinguptheroomquitenicely,andthelightattenuationissignificantlymorepleasing:

Page 4: What does “linear” mean in a linear workflo · monitors darken images, we need to counteract that. Here is a bit of a ... know that at around 4‐5pm you would see more bounce

Thoseexamplesareverybasicbutgiveaquickideaofwhatistocomeintermsoflightingaccuracy.

Nextisarenderthatisnotcorrectedforthedarknessthatmonitorsapplytoimages.AspecialthankstothetalentedarchitectsatMarch(http://www.marchmade.com),whoprovideddesignedandmodeledthisenvironment.Thisimagewasrenderedwithasun/skysystem,andusesGItogetdiffusebounces.Thesunisaround20degreesoffthehorizonsothereisaprettygoodamountoflightbutcertainlynothighnoonstylelighting.

Page 5: What does “linear” mean in a linear workflo · monitors darken images, we need to counteract that. Here is a bit of a ... know that at around 4‐5pm you would see more bounce

Thisimageseemsverydark.It’stoodarkhonestlybecauseifwethinklogicallyweknowthatataround4‐5pmyouwouldseemorebouncelightaroundtherestofthisstructure.Weknowthatbecausewe’reusedtoseeingthingsat4‐5pmallthetime.However,thecomputerandmonitorhavenoidea.Theyarebutdumbdisplaypresentationdevices.Let’sputansRGBgammacorrectioncurveontheimagetoshowwhathappenswhenwecorrectforwhatoureyessee.

Thisisofcoursemuchmorerepresentativeofwhatyouthinkyouseeataround4‐5pm.EventhoughthesRGBseemstoremovesignificantamountsofcontrast,thisimagecertainlyhasplentyofthat.However,it’simportanttonotethatthisimagewasgeneratedwithsRGB(linear)workflowinmind.Thatmeansthetextures,shadercolors,andvalueswereadjustedbasedonthatsRGBcurve.

LinearWorkflowina3DApplicationSo,whatdoesastandardworkflowlooklikeinthe3Dprocess?Let’sfirsttakealookatPhotoshop’scolorsettings.Sincenearlyeverytexturepaintedisfrom

Page 6: What does “linear” mean in a linear workflo · monitors darken images, we need to counteract that. Here is a bit of a ... know that at around 4‐5pm you would see more bounce

Photoshop,weneedtomakesureoursettingsaresetofforalinearworkflow.Photoshopbakesinagammatoits8bitoutput,sowhenwesaveanimage,it’sbeengammaencoded.Thisisnotidealbutweneedtofindawayaroundit.Alternatively,wecanuseopenEXRimagesfortexturesasthereisnogammaencodingonthoseimagesoranyotherfloatingpointformat.

MakesuretousesRGBfortheRGBpartoftheworkingspacesarea.Nowthatthepaintingtoolissetup,weneedtotakealookatthe3Dapp.However,let’slookattheidealpaththatimagedatatravelsthroughthe3Dapplicationbeforeanythingelse.

Page 7: What does “linear” mean in a linear workflo · monitors darken images, we need to counteract that. Here is a bit of a ... know that at around 4‐5pm you would see more bounce

Weneedtoassumethatthedatagoingintotherenderislinear.Thismeansweneedtoremoveanygammaencodingthatimageshave,iftheyare8bitdata.However,32or16bitfloatingpointimagesareassumedtoalreadybelinear,it’simportantthatwedonotcorrectthem.Intheend,ourrenderergenerateslinearfloatingpointdatathatweneedtopreviewinanimageviewing.Sinceit’sdatalinear,weneedtoaddthesRGBLUT,whichwillmakeitvisuallylinear.

Let’stakealookatafewexamplesofwhathappenstothetexturedatawhenlinearworkflowisproperlyappliedandwhenit’snot.HerewehaveasimplegradientcreatedinNuke,asafloatingpointopenEXR.Thetopimageislinear,andthebottomimageisanon‐linearimage.Inthisinstance,thenon‐linearmeansansRGBlut/gammaisbakedintotheimage.Wewillcallthisagamma‐encodedimage.

Page 8: What does “linear” mean in a linear workflo · monitors darken images, we need to counteract that. Here is a bit of a ... know that at around 4‐5pm you would see more bounce

Noticethedifferencewithrespecttothemidtonesandtheblacksoftheimages.Sincethetopimageislinear(nosRGBlutbakedin)thisshouldgiveuscorrectresultsintherenderer.

Now,let’sseewhathappenswhenthelinearandthenon‐linearimagegetsusedasareflectionmap.Thisrenderwassetupwithawhitebackgroundsoanyreflectionwouldbepure1.0.Thegroundplaneisblackandthereflectiontexturechanneloftheplanewassetwiththeaboveimages.Theimageshavebeentaggedwithluminancevaluestoshowwhere50%brightnessis.

Hereisthelinearresult:

Hereisthenon‐linear(gammaencoded)result:

Robert Nederhorst � 3/21/09 9:17 AM

Robert Nederhorst � 3/21/09 9:17 AM

Robert Nederhorst � 3/21/09 9:24 AM

Deleted: (akait’sencodedwith

Deleted: sRGBencoded

Deleted:

Page 9: What does “linear” mean in a linear workflo · monitors darken images, we need to counteract that. Here is a bit of a ... know that at around 4‐5pm you would see more bounce

Usingtheframebuffer’sabilitytosample,wegetavalueofaround.7onthe50%markwhenweexaminethenon‐linearimage.However,whenwesamplethelinearresult,thevalueis.5.Thisisdata‐linearcorrect.

Now,let’stakethatonestepfurthertodisplacementmaps.Thetopimageisgeneratedfromalinearfile.Thebottomimageisusingagammaencodedfile.

Hereitshouldbeevenmoreclearthatmakingsurethatweputlineardataintotherenderer.Wecanseewhatresultsfromnottakingtheextracaretoensureaccuracy

Robert Nederhorst � 3/21/09 9:24 AM

Robert Nederhorst � 3/21/09 9:25 AM

Robert Nederhorst � 3/21/09 10:22 AM

Robert Nederhorst � 3/21/09 10:23 AM

Robert Nederhorst � 3/21/09 10:24 AM

Robert Nederhorst � 3/21/09 10:24 AM

Deleted:

Deleted: .

Deleted: Wecanevenseethatthe3Dappisremovingpixeldata,andinthiscasevaluesbelow.01!

Deleted: notgammaencoded

Deleted: gammaencodedtobelinear

Deleted:

Page 10: What does “linear” mean in a linear workflo · monitors darken images, we need to counteract that. Here is a bit of a ... know that at around 4‐5pm you would see more bounce

inthesesteps.Thisisthestartofit,sincetexturesmakeour3Dworldgoround.Thereismoregroundtocoverthatwillhelpshedtheproverbiallightonthesubject.

Whyisworkinginlinearspaceimportant?Wehavealreadyseensomeearlyexampleofwhyusingalinear,orgammacorrectedworkflowisimportant.Wecanseethatrendersthatareproperlytransformedandwhenourlinearlightisaccountedfor,thatourrenderslookmoreaccurate.Achievingthislightinglevelwithoutusingagammacorrectedworkflowispossible.However,weneedtopushwaymorelightenergyintotherenderssothattheGIcanbouncetheraysaroundmore.Whenthathappenswehavelongerrendertimes.Generallyspeaking,rendertimesare3‐4xlongerwhenmakingadjustmentstolightingscenariosinordertoaccountforwhatwe“want”toseewhennotworkinginalinear,orgammacorrectedmanner.Goingevenfurtherdowntheoutputpipeline,compositingandcolorcorrectingisaffectedbyusingalinearworkflow.Thisisbecauseifwedon’tworklinearly,wecolorcorrectourdatainanon‐linearmanner.Thiswillresultinwildlyinaccuratevaluesforsomethinglikebrightness(orgain/multiplyincompositingterms).Hereisaflowchartofwhattheprocessshouldlooklike.

Manypiecesofsoftwaremakeafewassumptionsbasedonthefileformatandthebitdepthoftheimage.AcompositingapplikeNukeassumesthatifyouhavesavedyourdataasaformatlikeopenEXR,thatyouareworkingwithlineardataandthatanygammaisonlybeingcorrectedbythedisplay,whichNukedoesinitsframebuffer.Italsoassumesthatifweworkwith8bitdata(jpg,png,tga,etc)thatwehave(ortheapplicationhas,rather)bakedinthesRGBgammaandneedstotakeoutthegammatomaketheimagelinearagain.

Page 11: What does “linear” mean in a linear workflo · monitors darken images, we need to counteract that. Here is a bit of a ... know that at around 4‐5pm you would see more bounce

Hereistheresultoftakingourcorrectimageandturningupthebrightness(gain)by3x.

Wecanseethatthebrightsarereallybrightandthemidtonesaremuchbrighteralso.Thatimagehadnogammaappliedtoitwhenitwassavedoutonlytheviewingsystemappliedthegamma.Now,let’ssaythattheimagedidhavegammabakedintoit.Thesame3xbrightnesswouldlooksomethinglikethis:

Visually,wecantellthatthisimageisnotright.Everythingismuchtoobrightandthevalueswehadbeforearenot3xbrighter.Theyaremuchbrighterbecausewe’renowdoinganon‐linearcolorcorrection.Wealwayswanttodolinearcolorcorrectionbecauseit’smuchmoreaccuratetowhathappenstovaluesintherealworld(linearlight,remember?)versuswhathappenstodataintheCGIworld(nonlinear).So,nowthepointcomeswhereweneedtosaveoutourimagery.Hereisthecompletedflowchartofhowa3Drendergetshandledbycompositingsoftwarethatisawareandmanagesgammaandlinearworkflow:

Page 12: What does “linear” mean in a linear workflo · monitors darken images, we need to counteract that. Here is a bit of a ... know that at around 4‐5pm you would see more bounce

Hereit’sevidentthatwritingoutto,andreadingfromanonfloatingpointformatisthebigdifferentiatortotheworkflow.However,whilethesekindsoffilesaregamma(sRGB)encoded,thesoftwaremakesaccountsforthemontheinputandtheoutput.Evenontheweb,thebrowsersassumethatimageshavebakedinsRGBcurvestothem.It’sfunnytothinkofwebbrowsersbeingcompliantwithcolorstandards,buttheyare.

Howtoworklinearlyin3DSMaxusingbuilt‐inrenderersHerewehavethestandard3DSMaxpreferencespanelattheirdefaultsettings:

Page 13: What does “linear” mean in a linear workflo · monitors darken images, we need to counteract that. Here is a bit of a ... know that at around 4‐5pm you would see more bounce

Weneedtomakeafewchangestoittoworklinearly.Remember,weneedtohaveaviewingLUTandalsocorrectinputdataforthesRGBgamma.Hereisthemodifiedpreferencespanel:

Page 14: What does “linear” mean in a linear workflo · monitors darken images, we need to counteract that. Here is a bit of a ... know that at around 4‐5pm you would see more bounce

Firstthing’sfirst,weneedtoenablethegammacorrectionandmakesureourgammaissetto2.2.ThisnumberiscloseenoughtosRGBthatwe’rejustgoingtogowithit.NextofcoursewewanttoseethatthegammachangeshaveeffectintheMaterialEditor(fortheshaderballswatches)aswellasthecolorselectors.Thiswaywecanvisuallyseehowourchoicesaffecttheresultingcolors,becauseasweknow,avalueof0.18isactually0.5.Weneedtobeabletoseethatorelsesettingupvalueswillbeverydifficult.Finally,weneedtosettheinputgammaofbitmapsto2.2.Why?Well,rememberweareassumingthat8bitdatahasabakedingammaof2.2.Bysettingtheinputgammato2.2andtheoutputgammato1.0,welinearizetheimagesothatdiffusecolorsgettransformedproperlysotheylookhowweexpectthemtofromoursessioninPhotoshop.

Howtoworklinearlyin3DSMaxusingVRayWe’regoingtoswitchovertoVRaybecauseitoffersreallygreatsupportforlinearworkflows.HereisthebasicVRaycolormappingrollout:

Page 15: What does “linear” mean in a linear workflo · monitors darken images, we need to counteract that. Here is a bit of a ... know that at around 4‐5pm you would see more bounce

You’llnoticesomegammasetting,andafewcheckboxes.Hereistheresultingpanelafterit’sallsetup.

What’simportanttonoteisofcoursethegammasettingof2.2butalsothecheckboxfor“adaptationonly”.ThisisbecauseofcoursewewanttolettherendererworklinearlybutitbecameapparentthatifwewerenotsamplingatsRGBgammathatalotofnoisewouldgounnoticedbytherenderer.Why?Well,it’stimetobreakoutthecalculatorsagain.Let’ssayweputanoisethresholdof0.005.Thatisaprettyacceptablenoisefloortolookfor.However,theproblemisthatbecausewhilevisuallywe’relookingfor0.005therendererseeslineardata.Thisisonceagainduetothe0.5reallybeing0.18duetothelineargamma.Whenwerun0.005throughthepow(0.005,2.2)wegetavalueof:8.664310539439e‐06.Thisvalueisalotlowerthan.005,sothesamplerwon’tcatchit.Weneedtofigureoutwhatnumber0.005isinthelineargammaworld.Byusingthepowerfunctionpow(0.005,(1/2.2))tolookuppixelvaluesfordecidingonwhentosample,weknowwe’relookingfor0.009.Ofcoursethisisallforeducation’ssake.SinceVRaytakesitallintoaccountwiththesimple“adaptationonly”checkbox,wecansimplyignorethemathifwewantto.

ConclusionsLinearworkflowandunderstandinggammaisaverytrickyproposition.Itactuallyhelpstosometimesgoonfaiththatthenumbersworkaslongaswefollowtheformula.Theshorthandoftheformulaisasfollows:

• Transformalldatagoingintotherenderersothatwehanditlineardata• RenderlinearlyandgammacorrecttheviewingsystemwithaLUT• Outputtofloatingpointfiles(openEXR)forcompositing• Compositingsoftwareshouldaccountforlinearworkflowwithaviewing

LUTthatmatchestheoneintherenderer

Robert Nederhorst � 3/22/09 7:50 AM

Robert Nederhorst � 3/22/09 7:56 AM

Robert Nederhorst � 3/22/09 7:56 AM

Deleted: checkboxlabeled“Linearworkflow”.

Deleted: Seemseasyright?Yep!

Deleted:

Page 16: What does “linear” mean in a linear workflo · monitors darken images, we need to counteract that. Here is a bit of a ... know that at around 4‐5pm you would see more bounce

• Outputfromcompositingif8bitshouldhavesRGBgammabakedin.Iftherenderisfloatingpoint(openEXR)thenit’simportantnottobakethegammain.

Oncealinearworkflowisstarted,artistsnoticethattheimagerylooksmorephotographicandit’seasiertogettheresultsdesired.Ultimately,that’sthegoalisn’tit?