Original Post
Question: Is there a way to set the stencil buffer from a transparent texture or something similar (vs creating a silhouette object/vertexbuffer/etc.)? Is there a technique for setting the stencil better or faster than rendering triangles?
I'm new to playing with the stencil buffer, so I'm sure there are techniques and ways to do things I'm not aware of.
I have a transparent texture for a dashboard and windshield that I mask over the driver's view in a race car game at the end of every frame via a textured quad the size of the backbuffer. It works but is mildly expensive in render time. In addition, of course, it overwrites portions of the color buffer that I've just spent time rendering. At least the stencil would give me an early cull for the pixel.
To save a bit of rendering time, I want to stencil the silhouette of the dashboard/windshield/rearview-mirror. I'm in the process of creating the silhouette object to render for stenciling. It's a vertexbuffer (position only for now), rendered with color and depth turned off. It works but the silhouette isn't as smooth on the curves as I can get in a texture.
Is there such a thing as a "stencil texture?" I.e., a surface of some sort that I can create offline and "blit" to the stencil buffer.
Suggestions?
EDIT: MJP stated back in 2008, "You have to render something, otherwise you can't set any values in the stencil buffer. No way around that." Guess that answers the question about a "stencil texture."
That post did mention using an alpha texture which I'll have to give a try. Still requires a full-buffer quad but sounds like it might fill the bill.
In that same post, S1CA stated: "a pixel that fails alpha test won't be written to (or tested against) the stencil buffer or depth buffer."
In "The Direct3D Graphics Pipeline": If the pixel passes the alpha, depth and stencil tests,.. Is that always the fixed order of testing a pixel? FURTHER READING: Guess that should be rephrased: "Does alpha testing always precede depth/stencil testing?"
Just trying to confirm that alpha testing is the earliest cull for a pixel.
[Edited by - Buckeye on July 29, 2010 10:14:55 AM]
I'm new to playing with the stencil buffer, so I'm sure there are techniques and ways to do things I'm not aware of.
I have a transparent texture for a dashboard and windshield that I mask over the driver's view in a race car game at the end of every frame via a textured quad the size of the backbuffer. It works but is mildly expensive in render time. In addition, of course, it overwrites portions of the color buffer that I've just spent time rendering. At least the stencil would give me an early cull for the pixel.
To save a bit of rendering time, I want to stencil the silhouette of the dashboard/windshield/rearview-mirror. I'm in the process of creating the silhouette object to render for stenciling. It's a vertexbuffer (position only for now), rendered with color and depth turned off. It works but the silhouette isn't as smooth on the curves as I can get in a texture.
Is there such a thing as a "stencil texture?" I.e., a surface of some sort that I can create offline and "blit" to the stencil buffer.
Suggestions?
EDIT: MJP stated back in 2008, "You have to render something, otherwise you can't set any values in the stencil buffer. No way around that." Guess that answers the question about a "stencil texture."
That post did mention using an alpha texture which I'll have to give a try. Still requires a full-buffer quad but sounds like it might fill the bill.
In that same post, S1CA stated: "a pixel that fails alpha test won't be written to (or tested against) the stencil buffer or depth buffer."
In "The Direct3D Graphics Pipeline": If the pixel passes the alpha, depth and stencil tests,.. Is that always the fixed order of testing a pixel? FURTHER READING: Guess that should be rephrased: "Does alpha testing always precede depth/stencil testing?"
Just trying to confirm that alpha testing is the earliest cull for a pixel.
[Edited by - Buckeye on July 29, 2010 10:14:55 AM]