gl_FragCoord.x, y, z being 1 for all pixels and w being the depth

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

w be representing depth information while gl_FragCoord.z is always 1.0 for all fragments? glsl three.js webgl shader zbuffer. 2022DeveloperSurveyisopen!Takesurvey. Home Public Questions Tags Users Companies Collectives ExploreCollectives Teams StackOverflowforTeams –Startcollaboratingandsharingorganizationalknowledge. CreateafreeTeam WhyTeams? Teams CreatefreeTeam Collectives™onStackOverflow Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost. Learnmore Teams Q&Aforwork Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch. Learnmore gl_FragCoord.x,y,zbeing1forallpixelsandwbeingthedepth AskQuestion Asked 9years,2monthsago Modified 9years,2monthsago Viewed 14ktimes 8 2 I'musingTHREE.jswithshader.I'mtryingtogetthezbufferinformation. Vertexshader: //switchonhighprecisionfloats #ifdefGL_ES precisionhighpfloat; #endif voidmain() { gl_Position=projectionMatrix*modelViewMatrix*vec4(position,1.0); } Fragmentshader: #ifdefGL_ES precisionhighpfloat; #endif voidmain() { gl_FragColor=vec4(gl_FragCoord.x,gl_FragCoord.y,gl_FragCoord.z,1.0); } Thereareobjectswithdifferentpositioninthescene,thusthevaluesinzbuffershouldvary. It'sstrangethatgl_FragCoord.x,gl_FragCoord.yandgl_FragCoord.zseemstobe1.0forallfragments,whilegl_FragCoord.wseemstovaryfordifferentfragments. IfIusegl_FragCoord.w: #ifdefGL_ES precisionhighpfloat; #endif voidmain() { floatzbuffer=gl_FragCoord.w*500.0; gl_FragColor=vec4(zbuffer,zbuffer,zbuffer,1.0); } Itseemstobethezbufferimage: Sowhywouldgl_FragCoord.wberepresentingdepthinformationwhilegl_FragCoord.zisalways1.0forallfragments? glslthree.jswebglshaderzbuffer Share Improvethisquestion Follow editedMar1,2013at5:28 NicolBolas 412k6161goldbadges709709silverbadges902902bronzebadges askedMar1,2013at5:22 OviliaOvilia 6,8511212goldbadges4444silverbadges6868bronzebadges Addacomment  |  1Answer 1 Sortedby: Resettodefault Highestscore(default) Datemodified(newestfirst) Datecreated(oldestfirst) 16 gl_FragCoordisinwindowspace.Andwindowspaceisinpixelcoordinatesofthewindow.Sovirtuallyallofyourfragmentsaregoingtohavevalues>1.0.Andsinceyou'realmostcertainlynotrenderingtoafloating-pointframebuffer,yourcolorswillbeclampedtothe[0,1]range. gl_FragCoord.zisprobablynot1.0,butitmaybecloseenoughtoit,dependingonyourdepthrangeandhowfartheobjectsarefromthecamera.Ifyouwanttogetarealideaofthedepth,youneedtolinearizeit. Share Improvethisanswer Follow answeredMar1,2013at5:32 NicolBolasNicolBolas 412k6161goldbadges709709silverbadges902902bronzebadges 4 1 HowcanIgetscreenwidthandheightinshader? – Ovilia Mar1,2013at5:38 Butwhyisgl_FragCoord.wvaryingfordifferentfragments? – Ovilia Mar1,2013at13:54 @Ovilia:Forthesamereasonthattheotherthreecomponentsdo.Thedifferenceisthatyoudon'tseeit. – NicolBolas Mar1,2013at16:46 2 Additionally,ifsomebodyaskswhywhasthedepth,inrealityithas"1/z"accordingtothestandard,butzismuchhigherthan1,sothatputsthewvalueinthe0-1range.Fardepthswillgivedarkerpixels,lowdepthsbrighterones,andthatswhytheOPgetsthoseresults. – DarkZeros May18,2015at10:43 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?Browseotherquestionstaggedglslthree.jswebglshaderzbufferoraskyourownquestion. TheOverflowBlog Makeyouropen-sourceprojectpublicbeforeyou’reready(Ep.444) Thescienceofinterviewingdevelopers FeaturedonMeta AnnouncingthearrivalofValuedAssociate#1214:Dalmarus Improvementstositestatusandincidentcommunication RetiringOurCommunity-SpecificClosureReasonsforServerFaultandSuperUser Temporarilypausingthesitesatisfactionsurvey StagingGround:ReviewerMotivation,Scaling,andOpenQuestions Related 2 InOpenGLvertexshader,gl_Positiondoesn'tgethomogenized 1 CreatingatrianglewithOpenGL&GLSL 2 TroublepassingattributestoGLSLusingLWJGL 0 PassingWebRTCvideointogeometrywithGLSLShader 10 HowdoIupdatenormalsafterpositioningverticesinvertexshader? 2 WebGLVertexSpaceCoordinates 1 HowcanImoveonlyspecificverticesfrommyvertexshader?(Andhowtochoosethem) HotNetworkQuestions Meaningandoriginoftheword"muist" Longestgeometricprogressionofprimes Tryingtouseacaralternatorforapowersource(notforcar) Provingarecursiveformulaisindeedafunction WhyisMIDIgainbasedonafactorof40? Isitdangeroustoconsume30mgofZinc(asZincPicolinate)perday? DifferencebetweenfirewallandACL Movingplayerinsideofmovingspaceship? Whoisthewomaninthepostcreditof"DoctorStrangeintheMultiverseofMadness"? SignalprocessinginPythonvsC++(Bandpassfilter) Softwareforcreatinghand-writtenslidesthatarerevealedgradually WhatproblemscouldE6introducewhenusedforDungeonsandDragonsFifthedition? Howtodetectchains(sequenceofdegree2vertices)inagraph? ProbleminNewton'sPrincipiamentionedbyV.I.Arnol'd Whatisthemostecologicallysustainablewaytohandleragscoveredinchaingrease? Howdoyougagafish-personwithouttape? Howtomodelasimpleshoe Doesgravitationreallyexistattheparticlelevel? Whatdisadvantagesaretheretoencryptinganentireharddriveorahomedirectory? WhydoesmyMOSFETalwaysburn? Audiosplitterwithoutbufferpossible? Ihaveanarmadaofteleportingskyfortresses.DoIstillneedanavy? Mathematica13.0simplifiestrigonometricintegralwrong Pleasehelpmeclarifythissentenceabout'microtones'onGroveMusic morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. lang-c Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings  



請為這篇文章評分?