How to use the stencil buffer - WebGL Fundamentals

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

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


請為這篇文章評分?