What is the fastest way to pass around values in GLSL?

文章推薦指數: 80 %
投票人數:10人

I can think of at least three ways to pass around such values for modification: Use inout parameters for every function. Pass the value as an in ... Home Public Questions Tags Users Companies Collectives ExploreCollectives Teams StackOverflowforTeams –Startcollaboratingandsharingorganizationalknowledge. CreateafreeTeam WhyTeams? Teams CreatefreeTeam Collectives™onStackOverflow Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost. LearnmoreaboutCollectives Teams Q&Aforwork Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch. LearnmoreaboutTeams WhatisthefastestwaytopassaroundvaluesinGLSL? AskQuestion Asked 10years,10monthsago Modified 8years,8monthsago Viewed 1ktimes 4 1 InGLSLshaders,Ioftenwantacoupleoffunctionstomodifyasinglevalue,forvariousreasons(e.g.afragmentshaderthatusesfourfunctionstoapplylighting,texture,specularsandfog,say).Icanthinkofatleastthreewaystopassaroundsuchvaluesformodification: Useinoutparametersforeveryfunction. Passthevalueasaninparameterandusethereturnvalue(whichhastheobviousdisadvantagethatIcanonlyuseonevalue). Useaglobalvariablethateachfunctionmodifies. ShouldIexpectanypracticaldifferencesbetweenthesemethods?Aresomemoreprobablyfasterthanothers?Aresomemorecompatiblethanothers?Arethereanyotherdifferences?Orothermethods,forthatmatter? OrcanIsimplychoosetheoneIlikebest,stylistically? glsl Share Improvethisquestion Follow askedOct31,2011at17:53 Dolda2000Dolda2000 24.5k22goldbadges4949silverbadges8989bronzebadges 3 4 Optimizeyouralgorithm.Thenoptimizeanyotherbottlenecksyoufind.Afterdoingallofthat,thenyoucanthinkaboutwhatmethodsofmodifyingparametersworkbestonagivencompiler(becauseitwillbecompiler-dependent).Ingeneral,youwillgetpreciselyzilchoutofthis. – NicolBolas Oct31,2011at18:45 1 Thethreemethodsyoudescribearelikelytoendupbeingthesameifyouhaveonlyasingleshaderinanygivenprogramstage.Ifyoulinkmultipleshadersintoasinglestage,thenusingaglobalmightbedifferent(betterorworse).Asalways,youneedtoprofiletofigureoutwhat(ifanything)isdifferentandwherethebottlenecksare. – ChrisDodd Oct31,2011at20:17 1 Also,for#2,youcanuseoutparameterstoget(effectively)extrareturnvalues. – ChrisDodd Oct31,2011at20:18 Addacomment  |  1Answer 1 Sortedby: Resettodefault Highestscore(default) Trending(recentvotescountmore) Datemodified(newestfirst) Datecreated(oldestfirst) 0 ThiskindofoptimizationdependsmostlyontheunderlyingGLSLcompiler.ProfileyourshaderondifferentGPUs:AMD,nVidia,Intelandselectthebestcodepath. Share Improvethisanswer Follow answeredDec8,2013at12:20 SergeyK.SergeyK. 24.3k1313goldbadges101101silverbadges173173bronzebadges Addacomment  |  YourAnswer ThanksforcontributingananswertoStackOverflow!Pleasebesuretoanswerthequestion.Providedetailsandshareyourresearch!Butavoid…Askingforhelp,clarification,orrespondingtootheranswers.Makingstatementsbasedonopinion;backthemupwithreferencesorpersonalexperience.Tolearnmore,seeourtipsonwritinggreatanswers. Draftsaved Draftdiscarded Signuporlogin SignupusingGoogle SignupusingFacebook SignupusingEmailandPassword Submit Postasaguest Name Email Required,butnevershown PostYourAnswer Discard Byclicking“PostYourAnswer”,youagreetoourtermsofservice,privacypolicyandcookiepolicy Nottheansweryou'relookingfor?Browseotherquestionstaggedglsloraskyourownquestion. TheOverflowBlog WhyAIishavinganon-premmoment(Ep.476) Opensourceandaccidentalinnovation FeaturedonMeta Recentsiteinstability,majoroutages–July/August2022 PleasewelcomeValuedAssociate#1301-Emerson StagingGroundWorkflow:QuestionLifecycle Whatshouldwedowithimproperlycitedposts? Related 2 HowtodrawaborderaroundatextureusingGLSL 32 DifferencesbetweenGLSLandGLSLES2 1 TheluminositydoesnotworkusingGLSLshaders 0 GLSL-Howtoavoidpolygonsoverlapping? 4 Possibletofindinternalformatoftextureinshader? 2 Passtexturewithfloatvaluestoshader 6 WhatarethekeydifferencesbetweenOpenShaderLanguageandGLSL 0 ShouldIusethelastGLSLversionwhereitispossible? HotNetworkQuestions Howdoesonemakesurethatthere[hkl]directioninab-initocalculationsisthesameasinexperimentalcalculations? Canaphotonorbitaroundagalaxy? AreVirtualBoxguestadditionshost-independent? CanIreplace'havenot'or'haven't'with'ain't'inoralEnglish? HowcanImonitormyrooftodetectroofleaksbeforetheycausedamage? WhatisthelowerlimitofNiCdcellvoltage? StartabatfileonremotePC Whatisthereasonforthe"backporch"currentrequirementonanSCRgatedriver? Avoidbreakingwordsbeforeorafterasterisk('*') DoesarangerwiththeLand'sStridefeatureignoredamagefromtheSpikeGrowthspell? Whatdoesthissymbolonavoltmeterrepresent? Thegrammarof死ぬ死ぬ言わないの Whydoes'onsteroids'suggestthemeaningofexaggerationorenhancement? Areairshipspracticalinaworldwithoutmuchmetal? IsJohn6:4authentic? WhydoeseveryoneinTheLordoftheRingsuse"vous"? Solveequationin2variables SQL&PHPGetproductdifferentlocations HowtodisableGNOMEScreenshotUI,selectionframe,necessitytoclicksomethingtomakeascreenshotofanareainUbuntu22.04? Whydopeoplegenerallydopostdoc? Howaboutastatementwithoutproof? WhatdoesFirebase"useexclusivelyforpurposesrelatedtomytrade,business,craftorprofession"mean? Whydon'tdeuteronsproduceahelium-4nucleuswhentheyfuse? Isitsafetodrillacableexitholeinaseatpost? morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. lang-c Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings  



請為這篇文章評分?