Sign in to follow this  

I need help with the Stencil buffer..

This topic is 4533 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, i am JojoII. I am coding a 2D MMORPG which i formerly coded with SDL. I switched to Direct3d a few months ago, though its still a 2D environment. Its a 2d environment like the original NES and SNES Zelda,FF3/6, Terranigma, ect.. I have successfully replaced my code's core functions with Direct3D API and things are working much better. I love Direct3d's effects, as they run much better and faster then SDL. However, i have a small problem. I am trying to create a cool lighting effect using the Stencil buffer, and searching google relentlessly, i was unable to find any stencil buffer tutorials using Orthographic projection only. I've found stencil buffers that are for 3D environments but i have very little concept of how 3D works and i've been unable to make 2D sense out of it. What i need is very simple, and is maybe 8 lines of code to pull the effect off but i cannot find any tutorials. I understand exactly how the stencil buffer works, i just dont have a tutorial to show me how to do it in direct3d, but all i need is the following. First i would have all my graphics drawn out to the backbuffer already. A line of code to tell direct3d that its ready to do stuff to the stencil buffer The stencil buffers alphabytes (all of them) would need to be set to 255, (full opaqueness) so that when i blit a rectangle the size of the screen, which is the color of nitetime (somthing like 30,30,40, dark, with a touch of blue), all of it is set to draw. Next, for any objects causing an area to be lit, depending on what their "lightmap" graphic is which is loaded into a Read-only hardware Direct3dsurface, the alpha channel bits of that image would need to be copied onto the stencil buffer, parallel to where the lit area is on the screen (or backbuffer, at this point), with the rest of the image (RGB channels) ignored, since i dont think stencil buffers can directly support color-tinting-operations. Any alpha-bytes that arent 255 on the stencilbuffer would be the areas that are either ignored(byte = 0) when drawing the color-of-day rectangle, or transparent(byte < 255 but > 0). The non 0 yet non 255 bytes would be for areas of the lightmap that gradually fade the lighting darker and darker away from the center. And finally, i would need to draw my color-of-day rectangle, somehow intertwined to the stencilbuffer so that the lit areas dont get raped with darkness. I appreciate that you've read up to this point. If somebody could help me with this very simple problem, i would be infinately grateful. Also, i dont know if this is the most efficient method to do this effect, if anyone knows of a better method, please let me know. screenshots of my RPG can be viewed at http://roe.teathree.net/ss.html for an idea of what kind of 2D environment im talking about. Again, it is using an orthographic projection matrix set to the dimensions of 640x480. If you wish to contact me, my AIM screenname is shad0ws386 and my email address is JojoII123@yahoo.com. Thank you for your time, -JojoII

Share this post


Link to post
Share on other sites

This topic is 4533 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this