Skip to main content
GameDev.net gamedev.net
🔒 Locked

Object Outlining

Started by RandomLogic Dec 16, 2002 at 8:53 AM 5 replies 300+ views
Original Post
RandomLogic
RandomLogic
I want to create object outlining (2D silhouette for a 3D object) using D3D. How do I go about this? Links to source/tutorials would be best cause by my reckoning it should be done with stencils (which I haven''t used so far) and it''s much easier to understand code (for me at least). If this is not the case (or if no source exists) guidlines would be most welcome as well. Thanks, RL
There aren't any stupid questions,Only stupid people.
mdias
mdias
I''m not sure but I guess you can do it with VertexShaders, but
I don''t know how...

Hope it helps a little

KaMiKaZe
RandomLogic
RandomLogic
Vertex shaders will work only on a programmable pipeline no?

Just for sports here''s what I had in mind using stencil buffers (I''m reminding you lot I so far haven''t used them ''at all'').

I. Scale the object so that it''s x% bigger than it actually is.
II. Render (project?) it to the stencil buffer setting a bit where I''m suppose to draw a pixel.
III. Scale the object back to normal size.
IV. Next 2 stages In a single or double pass (not sure if possible). Render a SOLID color where the stencil is set
V. Render the actual object on top.

This shold create the silhoutte effect. If transparency is to be used this method will not be sufficient and an additional stage should be inserted between IV and V which is to unset the stencil where the actual object (in normal size) should be drawn so that the Solid would be only where the object isn''t (a XORish operation).

Anybody out there tried this? (or something like...), Is it possible and Will it be fast enough anyways?

Cheers,
RL
There aren't any stupid questions,Only stupid people.
S1CA
S1CA
Easier method (adequate for most things, though not perfect):


1. Render object
2. Change cull mode so that the object goes inside out (e.g. to D3DCULL_CW)
3. Render object again slightly scaled up and in the outline colour.


Alternative with a vertex shader (BTW: you can still use the fixed function pixel processing pipeline even if you''re using programmable vertex processing) is to calculate V.N per vertex where V is the view (camera) vector and N is the vertex normal.

V.N tells you how "edge on" a polygon is with respect to the viewer, simply use this value to darken/lighten the polygons which are edge on (i.e. shove the value into the vertex colour). An alternative would be to put the V.N value into a 1D texture coordinate and use it to look up into a texture which is white on the left with a black stripe to the right - that''ll let you do some more interesting things.

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
RandomLogic
RandomLogic
Thanks for the reply... two questions though:

I. When you say "you can still use the fixed function pixel processing pipeline even if you''re using programmable vertex processing", Do you mean I can use vertex shaders as they work in the assembler-like procedural format? If I get this straight and that''s what you meant then I assume software emulation is required (D3DDEVTYPE_REF????). Else how do I use both at the same time? And if both work at the same time won''t the vertex shader part be very slow on the host CPU?

II. Regardless when I later thought about how to go about implementing what I stated before I came up with a question of how does one fill up the frame buffer where a stencil test of some sort passes with a specified color.. is that even possible?

Cheers,
RL
There aren't any stupid questions,Only stupid people.
S1CA
S1CA
1) The reference rasterizer (D3DDEVTYPE_REF) provides software emulation of pixel processing only and has nothing to do with vertex processing.

You can use software (CPU) based vertex processing (a.k.a. transformation & lighting) at the same time as hardware (graphics card) rasterization (a.k.a. plotting pixels, blending, texturing).

If you take a look at the documentation for IDirect3D8::CreateDevice(), you''ll notice that you can specify a device type parameter (e.g. D3DDEVTYPE_HAL, hardware rasterization) *AND* a vertex processing type (e.g. D3DCREATE_SOFTWARE_VERTEXPROCESSING).

You need to ensure that all vertex and index buffers also have the relevent software vertex processing usage flags set, but that''s it - you can use vertex shaders with that setup as desired.

On any non-hardware T&L graphics card (i.e. all those before GeForce256 or Wildcat), you''ll be using software vertex processing anyway since the hardware doesn''t provide any acceleration of vertex processing. Software vertex processing is certainly fast enough to use in commercial games running at framerates of over 60Hz


2) Take a look at the code in the SDK or documentation, that does it.
Two passes. First pass, set the renderstates to enable writing of pixels into the stencil buffer. Second pass, set states to exclude any bit not set in the stencil buffer, render a simple quad in the colour of the outline to the screen.
Stencil buffers would be pretty useless if you couldn''t do that!


--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
RandomLogic
RandomLogic
Enlightened on both counts.

Thank''s again,
RL
There aren't any stupid questions,Only stupid people.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.