Depth Test - OpenGL Wiki
文章推薦指數: 80 %
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); Thefuncmaybeoneofthefollowing: 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
延伸文章資訊
- 1Depth testing - LearnOpenGL
When depth testing is enabled, OpenGL tests the depth value of a fragment against the content of ...
- 2Depth Test - OpenGL Wiki
- 3Force depth test against a specific depth value, instead of ...
Not the answer you're looking for? Browse other questions tagged opengl glsl opengl-3 depth-testi...
- 4Depth testing - LearnOpenGL
- 5Overlap and Depth Buffering
Like the color buffer, the depth buffer for the main window is created automatically by OpenGL wh...