View Space From gl_FragCoord - Game Development Stack ...
文章推薦指數: 80 %
Space & Sound? Defying Physics? 1 · Why are normal maps in tangent space but not in normal space? 14 · Why is clip space always referred to as " ... 2022DeveloperSurveyisopen!Takesurvey. GameDevelopmentStackExchangeisaquestionandanswersiteforprofessionalandindependentgamedevelopers.Itonlytakesaminutetosignup. Signuptojointhiscommunity Anybodycanaskaquestion Anybodycananswer Thebestanswersarevotedupandrisetothetop Home Public Questions Tags Users Companies Unanswered Teams StackOverflowforTeams –Startcollaboratingandsharingorganizationalknowledge. CreateafreeTeam WhyTeams? Teams CreatefreeTeam Teams Q&Aforwork Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch. Learnmore ViewSpaceFromgl_FragCoord AskQuestion Asked 3yearsago Modified 3monthsago Viewed 227times 0 \$\begingroup\$ TryingtogettheexamplecodeforCalcEyeFromWindow()(firstoneonthepage)toworkinWebGL,buthavingnoluck. Paireddownthecodetothefollowingwithsomeexplicitvaluesjustincasesomethingisamisswithparameterpassing.Visualizingtheoutputonasphereofunitradius,centeredintheviewand3unitsfromthecamera.Usingstep()intheoutputtoprovidesharpcolortransitionsonthesphere. Thecurrentoutputisblack.IfIsetthestepto0forXandY,thetransitionsforXandYarecenteredonthesphere,soitwouldseemthattheproblemisatleastinpartduetothecalculationofclipPos.w. Vertexshader: precisionhighpfloat; attributevec3a_position; uniformmat4u_modelMatrix; uniformmat4u_viewMatrix; uniformmat4u_projectionMatrix; voidmain() { gl_Position=u_projectionMatrix*u_viewMatrix*u_modelMatrix*vec4(a_position,1.0); } Fragmentshader: precisionhighpfloat; uniformmat4u_inverseProjectionMatrix; uniformmat4u_projectionMatrix; vec3CalcEyeFromWindow(void) { vec3ndcPos; //Hardcodewindow-spacepositionatgl_FragCoord //Hardcodeviewportdimensions ndcPos.xy=(2.0*gl_FragCoord.xy)/vec2(1000,500)-1.; //Hardcodeclippingdepths ndcPos.z=(2.0*gl_FragCoord.z-1.-4.)/(4.-1.); vec4clipPos; clipPos.w=u_projectionMatrix[3][2]/ (ndcPos.z-(u_projectionMatrix[2][2]/u_projectionMatrix[2][3])); clipPos.xyz=ndcPos*clipPos.w; return(u_inverseProjectionMatrix*clipPos).xyz; } voidmain(){ //Steptoclarifyposition gl_FragColor=vec4(step(vec3(.5,.5,2.2),CalcEyeFromWindow()* vec3(1,1,-1)),1.); } webglspaces Share Improvethisquestion Follow askedMay16,2019at16:05 cageyocageyo 1 \$\endgroup\$ Addacomment | 1Answer 1 Sortedby: Resettodefault Highestscore(default) Datemodified(newestfirst) Datecreated(oldestfirst) 0 \$\begingroup\$ TheproblemwasthatIhadusedtheclipplanedepthswhereIshouldhaveusedthenearandfarvaluesaspassedtoglDepthRange,whichInowknoware0and1bydefault.So,sinceIusethesedefaultvalues,thecalculationofndcPos.zshouldbe: ndcPos.z=(2.0*gl_FragCoord.z-0.0-1.0)/(1.0-0.0); whichcanbesimplifiedto: ndcPos.z=2.0*gl_FragCoord.z-1.0; Share Improvethisanswer Follow answeredMay20,2019at20:34 cageyocageyo 1 \$\endgroup\$ Addacomment | Youmustlogintoanswerthisquestion. Nottheansweryou'relookingfor?Browseotherquestionstaggedwebglspaces. TheOverflowBlog Makeyouropen-sourceprojectpublicbeforeyou’reready(Ep.444) Thescienceofinterviewingdevelopers FeaturedonMeta AnnouncingthearrivalofValuedAssociate#1214:Dalmarus Improvementstositestatusandincidentcommunication Related 1 Space&Sound?DefyingPhysics? 1 Whyarenormalmapsintangentspacebutnotinnormalspace? 14 Whyisclipspacealwaysreferredtoas"homogeneousclipspace"? 2 Spacebetweenrandomlygeneratedobjects 0 Whydowesaythingsarerotatedaroundthez-axisinaspacegraph? 0 SpaceofTangentandBitangentVectors 4 Tangentspace-LengyelvsShaderX5-difference 2 Howtoremapworldspacetoscreenspace? 0 ConvertGlobalSpace3DLocationtoLocalobjectspace? HotNetworkQuestions Whatis"aerospacegrade"? Howtodetectchains(sequenceofdegree2vertices)inagraph? Can'tmultiplywidthin\newcommandforincludegraphics Isitdangeroustoconsume30mgofZinc(asZincPicolinate)perday? Waystomakeanalienatmospherebreathable,butuncomfortable? WhyisMIDIgainbasedonafactorof40? Canarunascendinglistbemade? Isthereanargumentagainstusingthe(reviewed)predictionsofamodelasgroundtruthtofurthertrainexactlythismodel? Howdoyougagafish-personwithouttape? Igotninety-nineproblems-sohere'sanotherone! Tryingtouseacaralternatorforapowersource(notforcar) WhattapeformatdidtheNintendoFamicomDataRecorderuse? FindthenthFibonaccinumber,wherenisthemthFibonaccinumber DifferencebetweenfirewallandACL WhatdoesGandalftheWhitemeanbyhisstrangespeechaboutBoromir? Isthissinkfaucetremovable? HowManyDaysAfterSkimCoatCanIPaint? Whatmakesaluminumaerospacegrade? Myboss:"Ifeeljealous" Using\textsc{}manuallyinsection Whyweremarijuanarestrictionsimplementedinthe1970smoresuccessfulinSouthKoreathanintheUnitedStates? Whatdoesthisyumpackageversionmean? Pleasehelpmeclarifythissentenceabout'microtones'onGroveMusic WhydoesmyMOSFETalwaysburn? morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. default Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings
延伸文章資訊
- 1(gl_FragCoord.z / gl_FragCoord.w) for quick depth calculation ...
You can refer to chapter 2.13 “Coordinate Transformations” of OpenGL specs, and to the fact, that...
- 2LearnOpenGL - Depth Testing
The gl_FragCoord variable also contains a z-component which contains the depth ... The depth test...
- 3View Space From gl_FragCoord - Game Development Stack ...
Space & Sound? Defying Physics? 1 · Why are normal maps in tangent space but not in normal space?...
- 4gl_FragCoord.x, y, z being 1 for all pixels and w being the depth
w be representing depth information while gl_FragCoord.z is always 1.0 for all fragments? glsl th...
- 5Getting the real fragment depth in GLSL - Game Development ...
Alternatively, you can get it recover it from gl_FragCoord... In a fragment shader, gl_FragCoord ...