Questions tagged [stencil-buffer]

The stencil buffer is a concept implemented in various 3D graphics APIs used for performing "stencil" operations, used to minimize rasterization of hidden pixels or to implement various effects.

Resources:

202 questions
3
votes
0 answers

Can I prevent GPU fragment stalling with a stencil buffer?

I have some heavy duty calculations on the fragment shader, and this in multiple passes. But on some fragments, the result is ready after one pass only, and for other fragments, it takes more passes. Because of this, lots of fragments do discards…
scippie
  • 2,011
  • 1
  • 26
  • 42
3
votes
2 answers

LibGDX Stencil Buffers while using SpriteBatch

This is a continuation of my previous problem and post, seen here. Thanks to the answer I received there I feel I was able to get a little closer to my goal, as well as further my learning of OpenGL, but shortly after figuring out the basics of…
Synthetik
  • 219
  • 3
  • 11
3
votes
0 answers

Depth Stencil and Shadow resource empty

After Spending about 3 days trying to get shadow mapping to work I'm having some trouble getting the shadow mapped passed in to the shaders. First I initialize the depth stencil and the resource view, then i draw ( I believe ) to the depth stencil.…
Gribbles
  • 31
  • 1
3
votes
1 answer

glStencilFunc(GL_NEVER, 0, 0) still renders?

I have problems utilizing the stencil buffer, and it's seems to boil down to not work at all. Given the following code: glEnable(GL_STENCIL_TEST); glClearStencil(0); glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); …
Viktor Sehr
  • 12,825
  • 5
  • 58
  • 90
3
votes
2 answers

Using a semi transparent texture to "mask" out a part of the background

I am attempting to create a "hole in the fog" effect. I have a background grid image, overlapped onto that I have a "fog" texture that I use to show that certain areas are not in view. I am attempting to cut a chunk out of "fog" that will show the…
Zachar543
  • 311
  • 3
  • 13
2
votes
1 answer

OpenTK stencil buffer

I'm new to opengl and I'm struggling to get the stencilbuffer to work for a simple case; I have two textures, one being a bitmap and one being a "mask", with which I'm trying to hide some parts from the bitmap. I can't seem to get this to work, when…
Martijnh
  • 333
  • 2
  • 10
2
votes
1 answer

opengl stencil buffer - not quite got it working

currently im drawing a background, then a transparent triangle into the stencil buffer, then a blue square where the triangle isnt being drawn. i was hoping the effect would be a blue square with a trianglular hole exposing the background. but all…
cool mr croc
  • 725
  • 1
  • 13
  • 33
2
votes
0 answers

How to enable antialias/multisampling when rendering to framebuffer with stencil buffer for webgl2?

I add samples: 4 and change gl.RGBA to gl.RGBA4 to enable antialias of first framebuffer attachment: const framebufferInfo = twgl.createFramebufferInfo(gl, [ { format: gl.RGBA4, type: gl.UNSIGNED_BYTE, min: gl.LINEAR, wrap: gl.CLAMP_TO_EDGE,…
2
votes
1 answer

How to create a 2d clipping mask in webgpu?

I've been investigating a webgpu way to create a clipping mask. Here is what I tried: const pipeline1 = device.createRenderPipeline({ vertex: { module: basicShaderModule, entryPoint: 'vertex_main', buffers: [{ attributes: [{ …
plantain
  • 43
  • 1
  • 8
2
votes
1 answer

Affect depth, or stencil buffer from inside fragment shader?

I know it is possible to control what is written to the depth buffer in GLSL by writing to gl_FragDepth, but is it possible to write to the stencil buffer? Also, can I cancel a pixel write completely from within the fragment-shader, as if the pixel…
CuriousGeorge
  • 7,120
  • 6
  • 42
  • 74
2
votes
1 answer

How to mask multiple objects using stencil masking

I am drawing two different stencil masks at the same location and would want my mask 1 to only affect shape1 and Mask 2 to affect shape 2. This is the code. glClearStencil(0); glStencilMask(~0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT |…
Summit
  • 2,112
  • 2
  • 12
  • 36
2
votes
1 answer

Support for Stencil Buffer with WebGL

Initializing webgl with canvas.getContext("webgl", {stencil : true}) requests a stencil buffer, but not all browsers will actually give you one (for me, Firefox 79.0 on Ubuntu 20.04 LTS doesn't works but Chrome 84.0.4147.89 does. My graphics card is…
2
votes
1 answer

Outlining an object using a stencil buffer give wrong result

I'm trying to use the stencil buffer to draw outline border behind a model. I'm using 2 render passes, first rendering the model and using GL_ALWAYS to write 1 to the stencil buffer and then I render a slightly scaled up version of the model that…
Jorayen
  • 1,737
  • 2
  • 21
  • 52
2
votes
1 answer

Early-stencil culling without early-z culling

I already have an idea of the answer but I need to be sure. I render a scene in two pass. In the first pass, if depth test succeeds, I mark stencil bit as 1 : glEnable(GL_STENCIL_TEST); glStencilMask(GL_TRUE); glStencilOp(GL_KEEP, GL_KEEP,…
Kiord
  • 79
  • 7
2
votes
1 answer

openGL ES 2 - Is there a way to attach a stencil buffer with a different resolution than the target texture?

I have an input texture in a certain resolution, and a target texture (attached as GL_COLOR_ATTACHMENT0) which is in a bigger resolution. I am using glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) to upscale the input and draw some…
C Coder
  • 55
  • 5