0
\$\begingroup\$

I want to draw shapes (arcs, circles, lines) on a table, which is in 3D space. The table top is at Y=0 level and oriented so it points to (0, 1, 0). There are some other 3D objects on the table, so depth buffer has to be used. What is the best way to do this?

I do it now by drawing triangles or flat models on top of it. But for this I have to draw them at - for example - y = 0.05 This causes problems, because too small value makes z-fighting, especially on Android, and I'm going to have more of these drawings, so I would need to use different Y levels. I want the object to be perceived that they are exactly at the table level.

Some texturing? Some other way? Performance is of course important.

\$\endgroup\$

2 Answers 2

0
\$\begingroup\$

A possible way to solve this problem is to draw your shapes on the table texture, and then apply that modified texture to the table geometry. This would allow you to keep the shapes at the exact same level as the table, and removes the need for extra geometry to handle them.

\$\endgroup\$
4
  • \$\begingroup\$ Can I draw a texture on a table in render function, or do I need to modify my shader to achive this? And also, are there any functions to draw lines, arcs on a texture or do I need to use triangles? \$\endgroup\$
    – Arek
    Jan 20, 2016 at 21:02
  • \$\begingroup\$ It's been a while since I've done anything 3D in XNA, so I'm not sure of the entire process. But you could draw to a RenderTarget2D for the texture \$\endgroup\$
    – JonBee
    Jan 21, 2016 at 15:30
  • \$\begingroup\$ As for shapes, that'll have to be done via geometry, unless you don't update the shapes very often, in which case you could use the Windows drawing library. \$\endgroup\$
    – JonBee
    Jan 21, 2016 at 15:30
  • \$\begingroup\$ I solved the problem other way. I'm going to post my own answer, and I upvoted this one. \$\endgroup\$
    – Arek
    Feb 1, 2016 at 22:42
0
\$\begingroup\$

This is the best solution I found to this problem:

  • I splitted the table model to two separate models. One contains only the table "bed" (not sure if the name is right - I mean the table top / plate). The other model has all the rest, which includes some geometry drawn over the table top (this is a kind of a billiard table actually, so it has some cushions).
  • Now I start scene rendering from drawing the "table bed" object normally.
  • Then I disable the depth buffer and draw all the geometry which should be drawn on the table. Some if it are flat objects made of triangles, some of it are textures (especially if arcs are needed). Geometry is drawn at the same height level as the table top (y=0 in my case). I also draw some simple shadows this way, as I don't need full blown shadow mapping or other kind solutions. No Z-fighting, because the depth buffer is off.
  • Then I enabled the depth buffer, draw the rest of the table (separate model) and all the rest of geometry, including room walls, 3d objects on the table etc.

Additional bonus of this solution is that all 2D geometry drawn on the table is automatically clipped to the table bed shape (which is not 100% rectangular in my case and would be hard to clip otherwise). This is because 2d geometry doesn't write to depth buffer, so gets erased as soon as anything else is drawn in this place (ie. room walls).

The solution seems to work great.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .