Depth Test - OpenGL Wiki

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

The Depth Test is a per-sample processing operation performed after the Fragment Shader (and sometimes before). The Fragment's output depth ... DepthTest FromOpenGLWiki Jumptonavigation Jumptosearch OpenGLRenderingPipeline RenderingPipelineOverview VertexSpecification VertexRendering Primitive VertexProcessing VertexShader Tessellation GeometryShader VertexPost-Processing TransformFeedback PrimitiveAssembly FaceCulling Rasterization FragmentShader Per-SampleProcessing ScissorTest StencilTest DepthTest Blending LogicalOperation WriteMask TheDepthTestisaper-sampleprocessingoperationperformedaftertheFragmentShader(andsometimesbefore).TheFragment'soutputdepthvaluemaybetestedagainstthedepthofthesamplebeingwrittento.Ifthetestfails,thefragmentisdiscarded.Ifthetestpasses,thedepthbufferwillbeupdatedwiththefragment'soutputdepth,unlessasubsequentper-sampleoperationpreventsit(suchasturningoffdepthwrites). Contents 1Depthbuffer 2Fragmentdepthvalue 3Depthtest 4Earlytest 5Seealso Depthbuffer Inordertousethedepthtest,thecurrentFramebuffermusthaveadepthbuffer.Adepthbufferisanimagethatusesadepthimageformat.TheDefaultFramebuffermayhaveadepthbuffer,anduser-definedframebufferscanattachdepthformattedimages(eitherdepth/stencilordepth-only)totheGL_DEPTH_ATTACHMENTattachmentpoint. Ifthecurrentframebufferhasnodepthbuffer,thenthedepthtestbehavesasifitisalwaysdisabled. Fragmentdepthvalue EveryFragmenthasadepthvalue.ThisvalueiseithercomputedbytheFragmentShader(ifitwritestogl_FragDepth)oristhewindow-spaceZcoordinatecomputedastheoutputoftheVertexPost-Processingsteps. Depthtest Toenabledepthtesting,callglEnablewithGL_DEPTH_TEST.Whenrenderingtoaframebufferthathasnodepthbuffer,depthtestingalwaysbehavesasthoughthetestisdisabled. Whendepthtestingisdisabled,writestothedepthbufferarealsodisabled. Whendepthtestingisactive,thedepthvaluefromthefragmentiscomparedtothedepthvaluefromthematchingsamplecurrentlyintheframebuffer.Letuscallthefragment'sdepthN,whiletheframebuffer'sdepthP.Theconditionaltestisoftheform(NFUNCP),whereFUNCisspecifiedbythisfunction: voidglDepthFunc(GLenumfunc​); Thefunc​maybeoneofthefollowing: Enum Test Enum Test GL_NEVER Alwaysfails. GL_ALWAYS Alwayspasses GL_LESS < GL_LEQUAL ≤ GL_GREATER > GL_GEQUAL ≥ GL_EQUAL = GL_NOTEQUAL ≠ Earlytest Mainarticle:EarlyDepthTest ThedepthtestcantakeplacebeforetheFragmentShaderexecutes.ItcanonlydothisiftheFSdoesnotdiscardthefragmentanddoesnotmodifygl_FragDepth.Thisisdoneasanoptimization. Earlytestingcanalsobeenforced(withOpenGL4.2orARB_shader_image_load_store).Ifitisenforced,thenthefragmentshader'smodificationstogl_FragDepthwillbeignored,andiftheFSdiscardsthefragment,thedepthwillstillbewritten(unlessthecurrentWriteMaskpreventsit). Seealso StencilTest FragmentShader Retrievedfrom"http://www.khronos.org/opengl/wiki_opengl/index.php?title=Depth_Test&oldid=14331" Category:SampleWriting Navigationmenu Personaltools CreateaccountLogin Namespaces PageDiscussion Variants Views ReadViewsourceViewhistory More Search Navigation MainPageGettingStartedDownloadOpenGLRegistryReferencePagesReferenceGuideNewsCommunityForumsAboutOpenGL Help ContactUsPrivacyPolicyHelpEditingRecentchanges Tools WhatlinkshereRelatedchangesSpecialpagesPrintableversionPermanentlinkPageinformationCitethispage



請為這篇文章評分?