How to use stencils with SCNTechnique?

Basically, I would like to make a diagram around a cube. For this I can use SCNTechnique, which has the following rendering passes:

  • Usually visualize cubes, as well as write their occupied pixels to the stencil buffer.
  • Rendering a little big cubes if they do not intersect with the stencil in the first pass.

The problem is that the documentation for stencils is SCNTechniquevery sparse, and I can’t determine exactly how to use it.

I have already successfully drawn outlines, first drawing larger outline cubes with the depth turned off, and then drawing normal cubes, and this works pretty well, however I would like to use stencils instead of other complications using this method.

In an attempt to get it to work using stencil buffers, my first pass stencilStateslooks like (how and why I think I need properties):

clear = YES  // To clear the buffer from last 
enable = YES // To write to the buffer
behavior:
    writeMask = 1     // Use bit 1
    function = always // Always write to stencil regardless?

The second pass is stencilStatesas follows:

clear = NO   // Keep the buffer from last step
enable = NO  // Don't write to the buffer (only read?)
behavior:
    readMask = 1      // Use bit 1
    fail     = keep   // Not sure if these...
    pass     = zero   // ...should be the other way round

There are quite a few other properties for stencil buffer behavior, but I'm not sure what I need and how to use them. I am also not sure if the stencil buffer should be specified as input or output for each pass?

Change 1: . Exactly what I am looking for for implementation is visualized by drawing a blue larger cube of the contour first without writing to the depth buffer:

Cube with blue outline

- , , , , , , , !

2: , , OpenGL ( C) . , ( ), , , .

, :

glStencilFunc(GL_ALWAYS, 1, 0xFF); // Set any stencil to 1
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
glStencilMask(0xFF); // Write to stencil buffer
glClear(GL_STENCIL_BUFFER_BIT); // Clear stencil buffer (0 by default)

, :

glStencilFunc(GL_EQUAL, 0, 0xFF); // Pass test if stencil value is 0
glStencilMask(0x00); // Don't write anything to stencil buffer

, , , SCNTechnique.

+4
1

SCNTechnique, . , , , . , .

, : https://github.com/laanlabs/SCNTechniqueGlow , .

0

Source: https://habr.com/ru/post/1665468/


All Articles