3
\$\begingroup\$

I am using SharpDX to create an application in Hololens and I'm trying to understand how to use DirectWrite to draw variable text in 3D stereoscopic view. I have gone through this question, but the answers rely on other libraries.

MVP Dwight Goins provided me with this Rendering-3D-Text tutorial to help me out which uses the DirectX ToolKit. The closest I've got to is the Holographic-Tag-Along sample for holographic applications given by Microsoft. These two samples pretty much cover what I'm looking for but it is in C++. However, due to some project constraints, I need this to be in C#.

I am pretty new to computer graphics and therefore I do not fully understand how to achieve the same thing that the above two samples I've mentioned does in C# using SharpDX. Any help that could be provided to achieve the same output in C# would be much appreciated.

\$\endgroup\$
1
\$\begingroup\$

The sample you provided is actually not using DirectWrite I think, which would not be your best bet in any case, because the DirectWrite feature is a strictly 2D one (it is part of the SharpDX.Direct2D API). While your application seems to need to render in 2D, you actually are rendering a flat 3D object in 3D space from various vantage points, multiple times, and ensuring that these are consistently facing in a set of pre-defined directions (see billboarding). Thus, you would need a 3D engine which incorporated 2D elements (i.e. billboarding), rather than a strictly 2D one that you would be using should you go the DirectWrite route. Plus, there's a good amount of overhead for rendering everything stereoscopically, and DirectWrite is notoriously slower than it's counterparts.

I'm not too versed in hololens, and I won't pretend know the specifics of how exactly such an effect would be achieved, but I imagine what you might do is have the 3d text sitting in 3d space, and billboard in the direction of the viewer. There's probably a slew of techniques for things such as stabilization and velocity estimation, but the underlying premise would be billboarding that image with respect to the viewer.

I hope this helps a bit. Again, hololens isn't necessarily something I'm familiar with, but I wanted to say mostly that if you try to do this with DirectWrite you're going to have a bad time.

EDIT:

It occurs to me that this might be slightly misleading, because I phrased it in such a way that implies DirectWrite is incompatible with 3D, which isn't really true. You can indeed use DirectWrite in conjunction with Direct3D to render to 3D space, but DirectWrite itself only writes to a 2D surface. I really should have said don't use DirectWrite by itself to write to 3D space.

In order to use DirectWrite to write to 3D space, you would need to create a flat quad in 3D space, and use the render to texture technique in order to render your DirectWrite text to a texture. This texture may then be wrapped on that quad, and the quad may then be placed in 3D space to be rendered in 3D.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ I was under the impression that DirectWrite could be incorporated when rendering text to the the 3D space. And yes, the examples I've provided does not use DirectWrite or SharpDX for that matter. But necessarily, they are doing exactly what I need to replicate in C#/SharpDX. I have also followed the billboarding tutorial in rastertek.com - rastertek.com/dx11tut34.html, again excellent material, but in C++. \$\endgroup\$ – Ashan Jan 18 '17 at 3:34
  • \$\begingroup\$ I could add billboarding, world anchoring and rest of the features to the text if I could get it to render to the 3D space in hololens. That is the part I'm struggling with. Thanks a lot for your helpful answer, it'll probably save a lot of my time. \$\endgroup\$ – Ashan Jan 18 '17 at 3:35
  • \$\begingroup\$ I realize I unintentionally was misleading. The answer has been edited to reflect this. In short, you "can" use DirectWrite, but because DirectWrite only renders to a 2D texture, you need a 3D item to wrap this texture onto and place into 3D space. \$\endgroup\$ – Scorch Jan 18 '17 at 4:30
  • \$\begingroup\$ I've come across your suggestion specially here, rastertek.com/dx11tut12.html and I do believe that it is the way to go as well. However, I was unable to come across any resources which shows how to do the same thing in SharpDX. If you could point me to such a resources, that would be much appreciated. \$\endgroup\$ – Ashan Jan 18 '17 at 4:55
  • 1
    \$\begingroup\$ Of course. there's actually a direct port of these tutorials into SharpDX here. The only thing not in this github are the hlsl files that are used for the shaders, because they're exact copies of the hlsl files of the c++ tutorials. Also, having gone through this myself when trying to figure out SharpDX, I can say the code is awfully structured. Code is all over the place and often difficult to read, so I'm just forewarning you. The information in the tutorials is the best I've found, but it'll take some patience to extract it. \$\endgroup\$ – Scorch Jan 18 '17 at 5:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.