• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Rothgo Wooft

Depth Stencil Buffer

5 posts in this topic

It appears my question is too basic to be in the FAQ, so here it is.. In XNA, how do I "merge" the depth and stencil buffers? eg, so that a sprite appears to have a depth in the 3D scene, obscured by things on top? The 3D depth buffer has a proper Z position, but the stencil buffer is just from 0 to 1. I've tried scaling the stencil Z position in to the 0 to 1 range, but this doesn't help. The two buffers work as separate things... I want to copy the data from the depth buffer to make up a stencil buffer before drawing my 2d sprites... Surely there is a function already in place to do this? Several hours looking haven't found it yet. Any nudge in the right direction is appriechiated. cheers, Dave.
0

Share this post


Link to post
Share on other sites
This might help:

http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series2/Point_sprites.php

EDIT: Not sure how to get links to work right on these forums.
0

Share this post


Link to post
Share on other sites
Is there way without using point sprites?

I have a awful lot of them on the screen at once, and am guessing its quicker render using a normal 2D sprite batch? I could well be wrong...

If there's not much in it, I guess "Point Sprite" would be the magic word I was after, cheers!

I'll test it both ways and see what the effect is...
0

Share this post


Link to post
Share on other sites
Point sprites are a nice optimization when the hardware supports them, and when you can work within their limitations. The main benefit is that since you only need one vertex per sprite you can use a much smaller vertex buffer (with no index buffer necessary), which saves on memory, vertex processing load, and bandwidth. SpriteBatch just renders quads with a vertex buffer + index buffer, but is generally easier to use and gives you some more flexibility if you need it. Plus it doesn't require hardware support for point sprites, of course. If you're going to be rendering many many sprites (for something like a particle system), point sprites are a good choice if they're available.

Anyway your original question is unrelated to point sprites vs. SpriteBatch, it's simply an issue of using the depth buffer correctly. First of all, what you want is basic z-buffering behavior: you want to render all of your 3D geometry with z-writes and z-buffering enabled (RenderState.DepthBufferEnable = true and RenderState.DepthBufferWriteEnabled = true), and then render your sprites also with z-buffering enabled. As long as...

1. z-buffering is enabled
2. the depth buffer hasn't been cleared
3. you're setting a proper depth value for your sprites

...they should be tested for visibility just like 3D geometry. If you're not getting this behavior, I would suggest checking those 3 things.

Also on a side note, the stencil buffer doesn't hold "Z position"...it just holds an integer value. This value is typically 8-bits, can be 1-bit (or no bits) depending on the format of your DepthStencilBuffer. Either way it's just a value that's set depending on the values of RenderState.StencilFail and RenderState.StencilPass. If an incoming pixel passes the stencil test (specified by RenderState.StencilFunc) then StencilPass gets used, otherwise if it fails StencilFail gets used. At that point the stencil value doesn't get set to Z-position or anything like that...instead a simple operation is performed. It's either incremented, decremented, inverted, zeroed, or set to a value. See the documentation for StencilOperation for more details.

You also can't copy stencil data to Z or vice-versa. In fact you can't really directly manipulate the contents of the DepthStencilBuffer aside from clearing it...everything has to be done through render states and drawing geometry.
0

Share this post


Link to post
Share on other sites
It all makes a lot more sense now I've slept on it. Point sprites is probably the way to go, what with the lower bandwidth. But..

Are you saying that I should have seen my non-point sprites working with the stencil buffer automatically, if all was well? I'd like to get my head around it, even if I end up using point sprites. So, as the depth buffer is modified by 3D objects, it also updates the stencil buffer when altered (at lower depth resolution depending on bits used), or do they only work as separate things? If it should work, how does the stencil buffer scale itself from the depth buffer?

cheers,
Dave
0

Share this post


Link to post
Share on other sites

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  
Followers 0