For an RTS-like game I'm currently working on, I have to add outlines around units (and other entities), for a number of purposes:
* Units have to be made more visible against the background
* To show if units are friendly, neutral or enemy (different color outline)
* To show selected units (yet another color)
* To show units that are occluded by other units/buildings
Outlines will be shown for (pretty much) every entity (unit, building, etc.) in the scene. Even if a unit is in front of a building, or behind a building, (partial overlap) both the unit and building outline should still show.
I am NOT so much after an edge detection/rendering algorithm, since these can show edges inside the meshes as well. This is not intended as a cartoon rendering-effect of showing outlines, it's intended to just show the most outer edges of the mesh.
I am basically after this: http://www.flipcode....Outlining.shtml
However, I'm using a Direct3D-based engine, and the trick with wireframes doesn't work for me since I can't set their thickness like OpenGL allows.
Basically I want high-quality silhouettes, with a constant width (not depending on how far away an object is), that just go around the outsides of the object, not doing anything with inner edges.
I'm thinking a post-processor seems like the best choice. However, I'm not sure how to go about doing this. Maybe a sobel filter, but what should I then take as input? If I use a depth map, inner edges will also be draw. Maybe I could solve this by combining it with a stencil test, like in the article from Flipcode that I linked, but this might get very expensive for something as trivial as outlines. I'm also not sure if a stencil test could cope with the partial-overlap requirement.
Can anyone suggest a good approach to achieve the desired effect, taking into account mainly efficiency and outline quality? Support for relatively old hardware is a pre, but not the main focus. I'm using DirectX9.
RTS-style model outlines
You can achieve this by rendering the desired meshes-to-be-outlined to a buffer (maybe stencil buffer for DX9). Then do a full blur on that buffer. Then composite the blurred buffer onto the scene using the hard stencil from the first pass to discard pixels.
Here's a screen shot of that.
[attachment=1749:Glow_First_Pass.png]
If you don't want the fade around the edges you can simply do a step() function in the shader.
The only bad part about this algorithm is it is a screen space algorithm. This means the glow will be the same size on screen regardless of how close you get to the object.
Here's a screen shot of that.
[attachment=1749:Glow_First_Pass.png]
If you don't want the fade around the edges you can simply do a step() function in the shader.
The only bad part about this algorithm is it is a screen space algorithm. This means the glow will be the same size on screen regardless of how close you get to the object.
If you're looking for an input to do image processing on, you could render out an object id.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement