Can this be done fast?

I’ve been doing some effects research and I’ve hit upon an effect that has the potential of looking great. Problem is, I can’t think of any way to do it fast in OpenGL. But maybe I’m overlooking something, so I’ll see if anybody can put me on track if I’m off track. Ok, the effect essentially requires a stencil reference value per pixel. I know I can get a similiar effect by using an alpha buffer, but I really want to use the alpha channel for alpha blending during effect. To actually do what I’m thinking of, I can only think of multipass solutions that may require up to 255 or more passes (typically a lot less, I don’t expect to need 8 bits of stencil) per poly (255 passes to get the effective “stencil channel” into (adding or decrementing) the stencil buffer, and any extra passes for the color buffer). Any clues? Or am I stuck in software renderer land?

Huh? As Im reading it, I dont even think you said what you want to do. Did I misunderstand you, or did all you say is “I want to do something”?

More details please?

Originally posted by DFrey:
255 passes to get the effective “stencil channel” into (adding or decrementing) the stencil buffer

You are indeed a bit vague on what you actually want to do, but from what I understand, you’re essentially trying to load an 8-bit image into your stencil buffer, right?

If so, I think you can use the buffer region extension. I just did a demo of this, the link is still on the title page. Look up the extension spec for more details.

  • Tom

I effectively need a “stencil channel”, that operates directly on the stencil buffer per pixel. The “stencil channel” source needs to be a texture. This would allow me to have effectively a stencil reference value per pixel. For example, you know how the GL_REPLACE stencil operation works, right? It replaces a pixel’s current stencil value with the constant stencil reference value. What I want is for that reference value to be derived from a texture. Giving me a stencil reference value per pixel. The only approach I can think of to get this functionality is a massively multipass solution which I’d like to avoid. I’m wondering if I’m overlooking a faster solution.

[This message has been edited by DFrey (edited 01-28-2001).]

The only way I can think of is DrawPixels( …, GL_STENCIL_INDEX, …). Not blazingly fast by any means, but probably faster than 255 passes. I don’t see why you need 255 passes though. You should be able to set one bit at a time and get away with 8 passes.

If you want to change it every frame you could use special textures with low red values, draw your scene with them, glReadPixels( …, GL_RED, …) and then DrawPixels it.

I don’t think there’s any way to copy data from color buffers to stencil or depth buffers directly, so as you can’t draw directly into stencil I guess this is the best you can do.

How can I set one bit at a time? If there was a GL_OR stencil operation I could see how to reduce it to 8 passes. Otherwise I’m stuck with up to 255 passes using GL_INCR, or directly writing into the buffer.

[This message has been edited by DFrey (edited 01-29-2001).]

Oh I think I can do it in 8 passes with clever use of the stencil mask. I’ll try it out.

What sort of effect are you trying to achieve? Perhaps we could collectively think of another way it could be done with even fewer passes?

Suffice it to say, it is an awesome real-time teleportation effect. Looks great, still a bit too slow though. I wouldn’t want more than a few models on screen using it at a time. To actually describe the visual efftect, imagine a transparent, light emitting model appearing from many expanding globules suspended in space (sort of like an organicly inspired jigsaw puzzle). I’m using the stencil buffer to make the globules expand, I would have used the alpha buffer, but I need the alpha channel for transparency.