Re: Edge hiding

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Robert Dunlop [MS MVP] (rdunlop_at_mvps.org)
Date: 01/02/05


Date: Sat, 1 Jan 2005 17:09:45 -0800


"Eyal Teler" <et@nospam-et3d.com> wrote in message
news:u$RnIvF8EHA.3592@TK2MSFTNGP09.phx.gbl...
> Thanks for the clarification. If I understand correctly, what you're
> trying to do is allow both rendering as shaded (or textured) triangles and
> as lines, using the same dataset. (If not, then Robert's suggestion of
> using line lists is a good one.)

I think maybe I should clarify my post a bit. This is a technique that I've
used to do just that in a commercial engineering package, where my incoming
geometry is recieved as 3D qads that I converted to triangle pairs. The
customer wanted to have a wireframe drawn over the model showing the
original quads, after rendering the solid model.

When loading the geometry, the application fills an index buffer starting
from offset zero with the indices for the triangle list. At the same time,
indices were written to the same index buffer beyond where the triangle list
indices would end, containing the four edges from each pair of triangles
that would be rendered as lines. At render time I rendered using the first
portion of the index buffer as a indexed triangle list, then rendered using
the second set of indices as an indexed line list.

> I know no easy way to control this directly, but you may be able to use
> some of the interpolated vertex values (colours and texture coords) to
> mark to the pixel shader which edge you'd drawing, and kill the pixels in
> the pixel shader.
>
> For eliminating only one edge (or three, but not two), you could try alpha
> testing (assuming that you're not using the alpha in the vertex when
> drawing shaded triangles). Mark the vertices of the edge to be eliminated
> with alpha=0 and the other vertex with 1 (255). This will hopefully not
> eliminate much of the two remaining edges (a pixel shader could make sure
> any non-zero is not rounded to zero).
>
> For eliminating any number of edges, I can see using two alphas and
> multiplying them. For zero, one or three edges, using the same values for
> the alphas will work. For two edges, marking one edge with two vertices
> with zero alphas and the other using the other alphas should do it.

It would seem to me that you could deal with any combination of edges using
one alpha value, with a slight change. Set the alpha test reference value
(D3DRS_ALPHAREF) to a midrange value, say 127. To hide one edge, set values
of 126,126,255. To hide two edges, set values of 128,128,0. It might be
necessary to use values a bit further from the threshold (i.e. <126 and
>128) to get consistant results. Also, if an edge were to go much past 100
pixels then I would expect to see artifacts.

However, this scheme wouldn't work if the geometry shares vertices, because
it would require unique copies for each shared vertex. Generating indices
for rendering a line list would require no additional vertices and would not
require any changes to vertex components.

-- 
Robert Dunlop
The X-Zone
http://www.directxzone.org/
Microsoft DirectX MVP
-------------
The opinions expressed in this message are my own personal views and do not 
reflect the official views of the Microsoft Corporation.
The MVP program does not constitute employment or contractual obligation 
with Microsoft. 


Relevant Pages

  • Re: Alphablending
    ... "paint" into the alpha channel.. ... This is very useful for rendering FONTS for example: ... triangle with three coordinates. ... Barycentric coordinates, however, cannot. ...
    (alt.lang.asm)
  • Problem with glReadPixels and alpha value
    ... indeces this will result in an alpha value of zero (I'm working on an Intel ... say only points would be rendered, then the rendering in the back buffer ... while on ATI cards it is zero. ...
    (comp.graphics.api.opengl)
  • Re: Will video editing programs be ported to Linux?
    ... and licensing costs may be significant in some places. ... > Rendering was mentioned, but in the case studies I've read GNU/Linux ... > There are ample distributed queuing systems for GNU/Linux and Unix ... > In one case they used Alpha processors, so they had a choice of OS; ...
    (alt.linux)
  • Re: Skybox rendering
    ... >> Your opaque and transparent rendering should be in separate passes ... so the skybox drawn at the end of the opaque phase is ... BTW, if you have pixel shader hardware, I would very ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: Transparent Image Copy to Clipboard Adds Blue BG
    ... alpha transparency fine. ... > a bitmap with CreateDIBSection and then pre-multiply the alpha ... > for rendering. ... > a paste of an alpha channel bitmap must be aware that the alpha ...
    (microsoft.public.dotnet.framework.drawing)