In the stencil testing tutorial on Learn OpenGL, a stencil buffer is described like this:
A stencil buffer (usually) contains 8 bits per stencil value that amounts to a total of 256 different stencil values per pixel/fragment. We can then set these stencil values to values of our liking and then we can discard or keep fragments whenever a particular fragment has a certain stencil value.
A picture of the buffer is shown as 0s and 1s. Then the process is described like this:
The stencil buffer is first cleared with zeros and then an open rectangle of 1s is set in the stencil buffer. The fragments of the scene are then only rendered (the others are discarded) wherever the stencil value of that fragment contains a 1.
I’m a little confused about what a pixel/fragment in a stencil buffer can be changed to. With 256 different stencil values, can a zero be changed to something between 0 and 1 (like 0.5), or like can it be changed to 255?
So far, as I understand it, a stencil buffer starts where each pixel/fragment is represented as a 0:
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
Can a 0 be changed to something other then “1”, since there’s 256 different stencil values? Like this?
0 0 0 0
0 0 0 0
0 0 0.5 0.5
or this?
0 0 0 0
0 0 0 0
0 0 256 256