GLSL. Can someone explain why gl_FragCoord.xy ...
文章推薦指數: 80 %
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
延伸文章資訊
- 1高级GLSL
其中两个我们已经打过交道了: gl_Position 和 gl_FragCoord ,前一个是顶点着色器的输出向量,后一个是片段着色器的变量。 我们会讨论几个有趣的GLSL内建变量,并向你解释 ...
- 2gl_FragCoord - OpenGL 4 Reference Pages - Khronos Group
Available only in the fragment language, gl_FragCoord is an input variable that contains the wind...
- 3关于gl_FragCoord的理解 - CSDN博客
记录一下在使用gl_FragCoord的一些知识点先上shader来看效果 ... void main() { vec2 uv = gl_FragCoord.xy/u_resolution; g...
- 4How to get coordinate of fragment shaders? gl_FragCoord not ...
gl_FragCoord is a built-in input variables, it isn't necessary to declared the input variable gl_...
- 5glsl gl FragCoord 與螢幕關係 - w3c學習教程
gl_fragcoord根據glsl language spec的解釋為: ... 由於是2d渲染,最終每個fragment的gl_fragcoord的z接近0.0, 而w 為1.0, 而它的x...