Members - Reputation: 107
Posted 01 August 2012 - 10:10 AM
My game has just one character, and the camera is always fixed on them, and the character moves around the scene by themselves, but the player can swing the camera around (a bit like in The Sims).
I've seen games that have walls that dynamically drop or fade when a character moves behind them, but I have no idea where to begin with this.
I'm quite happy to try out a few ideas, I just thought I'd check whether there any commonly known techniques for this.
Crossbones+ - Reputation: 4532
Posted 01 August 2012 - 10:25 AM
You simply cast a ray from your camera position to your character position and hide all objects which intersect with your ray. I don't know whether this will be effective enough for what you want, but it's a start
I gets all your texture budgets!
Moderators - Reputation: 494
Posted 01 August 2012 - 11:14 AM
1. You can do as Radikalizm stated above. You can cast a ray or some kind of bounding volume into your scene that encompasses your character model. Any models or meshes that intersect this primitive can then be disabled during draw call, or drawn with a special alpha shader that causes it to be partially transparent.
2. If you want to avoid doing any kind of ray casting and/or collision detection a more naive method is to transform your on-screen objects into screen space. Then, any object which are within a certain radius from the center of the screen can be alpha blended. This can be done on a per-vertex basis (hiding certain primitives), or even on a per-pixel basis. In truth, since you know your character is always within the 1/4 middle of the screen, you can just add code to your pixel shader to return a fully transparent pixel if the pixel coordinate is in the inner circle of the screen.
3. And yet a third way is to leverage the stencil buffer. Either using a circular stencil, or the character model as a stencil itself, you can either prevent the drawing of pixels which are over the stencil, or instead draw a red shape where your stencil is. This has the effect of not hiding objects in the foreground, but instead making it obvious where your character is behind the object. If I recall correctly, this was done very well in Torchlight.
Cheers and Good Luck!
Sr. Tools & Engine Programmer | Software Engineer
Microsoft Windows Phone Team
Chronicles of Elyria (An In-development MMORPG)
GameDevelopedia.com - Blog & Tutorials
GDNet Mentoring: XNA Workshop | C# Workshop | C++ Workshop
"The question is not how far, the question is do you possess the constitution, the depth of faith, to go as far as is needed?" - Il Duche, Boondock Saints
Crossbones+ - Reputation: 12105
Posted 01 August 2012 - 06:41 PM
Another method may be to define a "frustum" (in quotes to make it clear that this isn't a vew frustum we're talking about here) from the corners of character's bounding box to the camera position, which makes it a frustum culling problem. Objects which intersect or are inside this frustum will block the character.
It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.