GLSL. Can someone explain why gl_FragCoord.xy ...

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

First, gl_FragCoord.xy are screen space coordinates of current pixel based on viewport size. So if viewport size is width=5 , height=4 then ... 2022DeveloperSurveyisopen!Takesurvey. ComputerGraphicsStackExchangeisaquestionandanswersiteforcomputergraphicsresearchersandprogrammers.Itonlytakesaminutetosignup. Signuptojointhiscommunity Anybodycanaskaquestion Anybodycananswer Thebestanswersarevotedupandrisetothetop Home Public Questions Tags Users Companies Unanswered Teams StackOverflowforTeams –Startcollaboratingandsharingorganizationalknowledge. CreateafreeTeam WhyTeams? Teams CreatefreeTeam Teams Q&Aforwork Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch. Learnmore GLSL.Cansomeoneexplainwhygl_FragCoord.xy/screenSizeisperformedandforwhatreason? AskQuestion Asked 4years,7monthsago Modified 2years,5monthsago Viewed 30ktimes 24 10 $\begingroup$ I'mnewtoshadersandknowthatyoucancolorpixelswithgl_FragColorbutsometimesthereisthisthing: vec2uv=gl_FragCoord.xy/screenSize;//orresolutionorsmthndependsontheimplementation Ifgl_FragCoordislikepixelcoordinates,whatdoesuvget? WhyisitoftendoneinGLSL? IfsomeonecouldevendrawanexampleofwhichpartofthescreenwillbeUVitwillbeveryhelpful! openglshaderglsl Share Improvethisquestion Follow editedFeb12,2019at19:19 Subtlebot 10333bronzebadges askedOct14,2017at11:30 idchlifeidchlife 34311goldbadge22silverbadges66bronzebadges $\endgroup$ 1 $\begingroup$ ItisimportanttonotethattheRasterizationstagebeforetheoptionalFragmentShaderperformsfragmentattributeinterpolationandviewporttransformationforthegl_FragCoordattribute. $\endgroup$ – Matthias Oct14,2017at16:29 Addacomment  |  2Answers 2 Sortedby: Resettodefault Highestscore(default) Datemodified(newestfirst) Datecreated(oldestfirst) 32 $\begingroup$ First,gl_FragCoord.xyarescreenspacecoordinatesofcurrentpixelbasedonviewportsize.Soifviewportsizeiswidth=5,height=4theneachfragmentcontains: Whyareuvsneeded?ForexampleIrenderedgeometrytoscreenquadandthenIneedtoapplysomepostprocessingonthisquadinanotherrenderingpass.TosamplefromthatquadIneedtexturecoordinatesinrange[0,1].SotocalculatethemIperformdivisiongl_FragCoord.xy/viewPortSize. Share Improvethisanswer Follow editedJun18,2020at8:32 CommunityBot 1 answeredOct14,2017at12:42 narthexnarthex 2,03711goldbadge99silverbadges1818bronzebadges $\endgroup$ 1 $\begingroup$ ItmightbeworthsayingthatGL_TEXTURE_RECTANGLE_ARBdoesn'tusenormalizedcoordinates,butthatGL_TEXTURE_*Dtexturesdo. $\endgroup$ – user1118321 Feb13,2019at5:42 Addacomment  |  4 $\begingroup$ Refertonarthex'sexcellentanswerfordetailsandexample,butsimplyput, Ifyouwanttomapthepixelcoordinatevaluestotherange0to1,youdividebyviewPortSize. Share Improvethisanswer Follow answeredDec8,2019at8:20 WizardOfRobotsWizardOfRobots 4122bronzebadges $\endgroup$ Addacomment  |  YourAnswer ThanksforcontributingananswertoComputerGraphicsStackExchange!Pleasebesuretoanswerthequestion.Providedetailsandshareyourresearch!Butavoid…Askingforhelp,clarification,orrespondingtootheranswers.Makingstatementsbasedonopinion;backthemupwithreferencesorpersonalexperience.UseMathJaxtoformatequations.MathJaxreference.Tolearnmore,seeourtipsonwritinggreatanswers. Draftsaved Draftdiscarded Signuporlogin SignupusingGoogle SignupusingFacebook SignupusingEmailandPassword Submit Postasaguest Name Email Required,butnevershown PostYourAnswer Discard Byclicking“PostYourAnswer”,youagreetoourtermsofservice,privacypolicyandcookiepolicy Nottheansweryou'relookingfor?Browseotherquestionstaggedopenglshaderglsloraskyourownquestion. TheOverflowBlog Makeyouropen-sourceprojectpublicbeforeyou’reready(Ep.444) Thescienceofinterviewingdevelopers FeaturedonMeta AnnouncingthearrivalofValuedAssociate#1214:Dalmarus Improvementstositestatusandincidentcommunication Linked 1 Understandingfragmentshadercoordinatesystem Related 6 HowtoconvertathreadIDintoScreenSpaceCoordinanOpenGLComputeShader? 8 Can(andhowso)shaderspaintscreenpixelsbeyondthosethatoccupiedbytheshadedmesh? 4 IdontunderstandhowaGPUcomputesandbranches,couldyoupleasehelpmefixthisshaderpreformance 3 WhatdotheOpenGLversionstringsfromglxinfoactuallymean? 1 Understandingfragmentshadercoordinatesystem HotNetworkQuestions Meaningandoriginoftheword"muist" Whyweremarijuanarestrictionsimplementedinthe1970smoresuccessfulinSouthKoreathanintheUnitedStates? Googlespreadsheets Isthisaninsectnest? Whyisacapacitortogroundalowfrequencypole,insteadofahighfrequencyzero? Mathematica13.0simplifiestrigonometricintegralwrong Howcanaprivatekeybeimportedtoadescriptorwallet? WhatpreventsmefrommakingonebigestimatedFederaltaxpaymentonJan15? Softwareforcreatinghand-writtenslidesthatarerevealedgradually Partitioningalistbasedonacriterionforsublists DifferentwaystocitereferencesinMathematics WhattapeformatdidtheNintendoFamicomDataRecorderuse? Whatis"aerospacegrade"? WhentochangeoilfornewgenerationMazda? Howtomodelasimpleshoe Myboss:"Ifeeljealous" StarWars:R2D2connectedtomainframe Waystomakeanalienatmospherebreathable,butuncomfortable? Audiosplitterwithoutbufferpossible? GameinJamesBondfilm"FromRussiawithlove" Canarunascendinglistbemade? Currentlyself-studyingQFTandTheStandardModelbySchwartzandI'mstuckatequation1.5inPart1regardingblackbodyradiation HowcanaverbalreasoningquestionbesolvedwithMathematica? Ihaveanarmadaofteleportingskyfortresses.DoIstillneedanavy? morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings  



請為這篇文章評分?