Sign in to follow this  
Weny Sky

2D : Outline hide objects

Recommended Posts

How can I make effect like this : http://www.empires2.net/screeny/04a.jpg . The part of troop which has hidden by building is outlined by white color. I think, I should fill texture by D3DCOLOR_ARGB(0,0,0,0) render buldings and trees and then render the outline of troops by any blending methode. But I don't know witch set of blending use. Or is better way to do this? thx

Share this post


Link to post
Share on other sites
If the troops or whatever are 2D sprites, then you could create an outline sprite for every normal sprite you make. Then, when rendering, render from front to back, using a z-buffer to reject pixels that are behind pixels already rendered, just like normal. But each time you render an ordinary sprite, change your z function to only draw if the new pixel is hidden by another pixel:

pDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_GREATER);

Also, it might be wise to disable writing to the z-buffer, or these outlines might mess the buffer up a bit:

pDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);

Once you've rendered the outline, revert back to ordinary settings for the next sprite:

pDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
pDevice->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);

This was just my first thought. I don't actually know anything about any working implementation. But it sounds like it should hypothetically work. Might need to be modified a bit, but in general, it seems correct.

If your objects aren't just predrawn sprites, it might get a bit more complicated to make the outline, but the z-buffer usage would be the same.

Share this post


Link to post
Share on other sites
Agony I have implemented your solution, but it has one small mistake. The polygons with my 2D images(buildings, trees, etc.) is write whole to z-buffer. The transparent parts of image aren't leave out - in z-buffer are rectangles :(
Is possible draw to z-buffer image without transparent color?

Share this post


Link to post
Share on other sites
Quote:
Original post by Weny Sky
Agony I have implemented your solution, but it has one small mistake. The polygons with my 2D images(buildings, trees, etc.) is write whole to z-buffer. The transparent parts of image aren't leave out - in z-buffer are rectangles :(
Is possible draw to z-buffer image without transparent color?


Yes, Alphatesting. Any pixels clipped out by Alphatesting are not written to the Z-buffer. Anything that is alphablended (after passing the alphatest) is written to the Z-buffer.

Hope this helps.

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