How to use the stencil buffer - WebGL Fundamentals
文章推薦指數: 80 %
I have read many different themes about it, but I not found a detailed guide about it. I want to cut out for hole each side in a created tetrahedron. enter ... English Français 日本語 한국어 Polski Portuguese Русский 简体中文 TableofContents WebGLFundamentals.org Fix,Fork,Contribute Howtousethestencilbuffer Question: HowIcanusetostencilbufferformyeasiestprogram? Ihavereadmanydifferentthemesaboutit,butInotfoundadetailedguideaboutit. Iwanttocutoutforholeeachsideinacreatedtetrahedron. Pleaseexplaintomestepbystepusestencilbuffer? Linkformyprogram Answer: Tousethestencilbufferyouhavetofirstrequestitwhenyoucreatethewebglcontext constgl=someCanvasElement.getContext('webgl',{stencil:true}); Thenyouturnonthestenciltest gl.enable(gl.STENCIL_TEST); Setupthetestsoitalwayspassesandsetthereferencevalueto1 gl.stencilFunc( gl.ALWAYS,//thetest 1,//referencevalue 0xFF,//mask ); Andsettheoperationsowe'llsetthestenciltothereferencevaluewhenboththestencilanddepthtestspass gl.stencilOp( gl.KEEP,//whattodoifthestenciltestfails gl.KEEP,//whattodoifthedepthtestfails gl.REPLACE,//whattodoifbothtestspass ); Wethendrawthefirstinnertriangle ...lotsofsetupforasingletriangle... gl.drawArrays(...)orgl.drawElements(...) Thenwechangethetestsoitonlypassesifthestenciliszero gl.stencilFunc( gl.EQUAL,//thetest 0,//referencevalue 0xFF,//mask ); gl.stencilOp( gl.KEEP,//whattodoifthestenciltestfails gl.KEEP,//whattodoifthedepthtestfails gl.KEEP,//whattodoifbothtestspass ); andnowwecandrawsomethingelse(thelargertriangle)anditwillonlydrawwherethereis0inthestencilbufferwhichiseverywhereexceptwherethefirsttrianglewasdrawn. Example: clickheretoopeninaseparatewindow Thequestionandquotedportionsthereofare CCBY-SA4.0by AnatoliyC from here English Français 日本語 한국어 Polski Portuguese Русский 简体中文 Fundamentals Fundamentals HowItWorks ShadersandGLSL WebGLStateDiagram ImageProcessing ImageProcessing ImageProcessingContinued 2Dtranslation,rotation,scale,matrixmath 2DTranslation 2DRotation 2DScale 2DMatrices 3D Orthographic3D 3DPerspective 3DCameras Lighting DirectionalLighting PointLighting SpotLighting StructureandOrganization LessCode,MoreFun DrawingMultipleThings SceneGraphs Geometry Geometry-Lathe Loading.objfiles Loading.objw.mtlfiles Textures Textures DataTextures Using2orMoreTextures CrossOriginImages PerspectiveCorrectTextureMapping PlanarandPerspectiveProjectionMapping RenderingToATexture RendertoTexture Shadows Shadows Techniques 2D 2D-DrawImage 2D-MatrixStack Sprites 3D Cubemaps Environmentmaps Skyboxes Skinning Fog Picking(clickingonstuff) Text Text-HTML Text-Canvas2D Text-UsingaTexture Text-UsingaGlyphTexture Textures RampTextures(ToonShading) GPGPU GPGPU Tips SmallestPrograms DrawingWithoutData Shadertoy PullingVertices Optimization IndexedVertices(gl.drawElements) InstancedDrawing Misc SetupAndInstallation Boilerplate ResizingtheCanvas Animation Points,Lines,andTriangles MultipleViews,MultipleCanvases VisualizingtheCamera WebGLandAlpha 2Dvs3Dlibraries Anti-Patterns WebGLMatricesvsMathMatrices PrecisionIssues Takingascreenshot PreventtheCanvasBeingCleared GetKeyboardInputFromaCanvas UseWebGLasBackgroundinHTML CrossPlatformIssues QuestionsandAnswers Reference Attributes TextureUnits Framebuffers readPixels References HelperAPIDocs TWGL,AtinyWebGLhelperlibrary github Questions?Askonstackoverflow. Issue/Bug?Createanissueongithub. Use
codegoeshere
forcodeblocks
commentspoweredbyDisqus
延伸文章資訊
- 1Depth and stencils - OpenGL
The drawing operation of the cube uses the values from the stencil buffer to only draw fragments ...
- 2Stencil testing - LearnOpenGL
Stencil buffer operations allow us to set the stencil buffer at specific values wherever we're re...
- 3Depth & Stencil Testing
When depth testing is enabled: OpenGL tests depth value of a ... them accordingly, but not update...
- 4OpenGL Programming/Stencil buffer - Wikibooks, open books ...
When you draw something with OpenGL, you see colors on the screen, but keep in mind that there ar...
- 5How to read stencil buffer in glsl? - OpenGL - Khronos Forums
I have two questions about using stencil buffer: (1) How can I read stencil buffer in glsl? (2) I...