Stencil buffer in JME3

Hello. How can I manage the stencil buffer in jMonkey? If I need to render only certain parts (a stencil function), how can I configure that stencil test in jme3? Thank you!

Enter search term “stencil”



Get out the explanations:

http://hub.jmonkeyengine.org/javadoc/com/jme3/material/RenderState.StencilOperation.html

1 Like

Thank you! I had seen that pages, but I still don’t figure out how to draw the frame buffer. For example, in that page a method to ‘invert’ the stencil is explained, though I don’t understand how to load it.

The rendering happens every frame, you have to place the stencil calls inside any render() method of the things that should obey to this when rendering.

For example, I want to render only one part (in fact, some vertical stripes) and do not render the rest. I know I can set a clipping rectangle for the renderer, but how can I use a stencil with a custom shape?



What I want to do is to interleave vertical stripes from one scene as seen from two different cameras. I rendered the two cameras into textures and produced that result by using a shader. The problem is that I need to do that for a device that does not support frame buffers. There is an application that already does that by using the stencil buffer, written in plain opengl. I wanted to do that on jMonkey. I was trying to understand how stencils work in this engine or, otherwise, how I could call opengl functions to manipulate the buffer. What do you think?

Hm, sounds problematic, I don’t think you’ll be able to do this without extensive hacks. Depending on your application (can’t exactly imagine what you’re doing) multiple stencils / render operations?

@normen said:
Hm, sounds problematic, I don't think you'll be able to do this without extensive hacks. Depending on your application (can't exactly imagine what you're doing) multiple stencils / render operations?


From the description i guess he is trying to implement rendering of a picture ready for 3D-TV's. If yes, SideBySide instead of Interleaving might be easier to implement...

Yes, that’s right. I need interleaving though. Rendering to textures and using a shader was okay, but when trying to use it in a mobile device, rendering to textures does not work due to the lack of frame buffers support. I saw an implementation in raw opengl using a very simple stencil that, rendering twice and inverting, would produce the interleaving of the two cameras as expected. I face the problem that I don’t know how to implement stencils by using jME3. If I use raw opengl calls, where shoud I use them? Do you come into any other ideas to solve this? Thanks!