The routine for outlining your objects is as follows:
1. Set the stencil func to GL_ALWAYS before drawing the (to be outlined) objects, updating the stencil buffer with 1s wherever the objects’ fragments are rendered.
2. Render the objects.
3. Disable stencil writing and depth testing.
4. Scale each of the objects by a small amount.
5. Use a different fragment shader that outputs a single (border) color.
6. Draw the objects again, but only if their fragments’ stencil values are not equal to 1. 7. Enable stencil writing and depth testing again.
总结:
1. 哪一些物体需要描边的,就利用 stencil func GL_ALWAYS 进行渲染那些物体,那么在 stencil buffer 里面,那些物体对应的stencil value 记录为 1.
2. 关闭 stencil write 和 depth testing
3. 把需要描边的物体进行放大,利用 stencil func GL_NOTEQUAL ,使用其他的shader来进行渲染 放大后的 物体.
(因为第一步的 stencil buffer 就有了 1 的值,那么这个时候由于GL_NOTEQUAL,就是把放大多出来的部分进行渲染)
4. Enable stencil write and depth