List of Open-Source Hololens code in C++/C#/DirectX

Publié le Publié dans Hololens



New addition from MS: Holographic Depth-Based Image Stabilization.
And an old-new addition: Mesh Processing Library « published at ACM SIGGRAPH in 1992–1998 ».


Creating a holographic DirectX project

A holographic app is a Universal Windows Platform app – just like apps that run on the desktop, phone, and/or tablet. The DirectX 11 holographic app template is much like the DirectX 11 UWP app template; it includes a program loop (or « game loop »), a DeviceResources class to manage the Direct3D device and context, and a simplified content renderer class. It also has an IFrameworkView, just like any other UWP app.

However the holographic app has some additional capabilities that aren’t present in a typical D3D11 UWP app. The holographic app template is able to:

  • Handle Direct3D device resources associated with holographic cameras.
  • Retrieve camera back buffers from the system.
  • Handle gaze input, and recognize a simple gesture.
  • Go into full-screen stereo rendering mode on the HoloLens.

How do I get started?

First install the tools and follow the instructions on downloading Visual Studio 2015 and the Microsoft HoloLens emulator. The holographic app templates are included in the same installer as the Microsoft HoloLens emulator. Also ensure that the option to install the templates is selected before installing.

Now you can create your DirectX 11 Windows Holographic App! Note, to remove the sample content, comment out the DRAW_SAMPLE_CONTENT preprocessor directive in pch.h.

Creating the project

Once the tools are installed you can then create a holographic DirectX project. To create a new project:

  1. Start Visual Studio.
  2. From the File menu, point to New and select Project from the context menu. The New Project dialog opens.
  3. Expand Templates and expand either the Visual C# or Visual C++ language node.
  4. Navigate to the Windows > Universal > Holographic node and select Holographic DirectX 11 App (Universal Windows).
  5. Fill in the Name and Location text boxes, and click or tap OK. The holographic app project is created.

Screenshot of the holographic app project template in Visual Studio

Review Using Visual Studio for information on how to build and deploy the sample to your HoloLens or an emulator.

The project template shows how to create a world-locked cube that’s placed two meters from the user. The user can air-tap to place the cube in a different position that’s specified by the user’s gaze. You can modify this project to create any holographic app.

Holographic app entry point

Your holographic app starts in the main function in AppView.cpp. The main function creates the app’s IFrameworkView and starts the CoreApplication with it.

// The main function is only used to initialize our IFrameworkView class.
// Under most circumstances, you should not need to modify this function.
int main(Platform::Array<Platform::String^>^)
    AppViewSource^ appViewSource = ref new ::AppViewSource();
    return 0;

From that point on, the AppView class handles interaction with Windows: basic input events, CoreWindow events and messaging, and so on. It will also create the HolographicSpace used by your app.

Render holographic content

The project’s Content folder contains classes for rendering holograms in the holographic space. The default hologram in the template is a spinning cube that’s placed two meters away from the user. Drawing this cube is implemented in SpinningCubeRenderer.cpp, which has these key methods:

Method Explanation
CreateDeviceDependentResources Loads shaders and creates the cube mesh.
PositionHologram Places the hologram at the location specified by the provided SpatialPointerPose.
Update Rotates the cube, and sets the model matrix.
Render Renders a frame using the vertex and pixel shaders.

The Shaders folder contains four default shader implementations:

Shader Explanation
GeometryShader.hlsl A pass-through that leaves the geometry unmodified.
PixelShader.hlsl Passes through the color data. The color data is interpolated and assigned to a pixel at the rasterization step.
VertexShader.hlsl Simple shader to do vertex processing on the GPU.
VPRTVertexShader.hlsl Simple shader to do vertex processing on the GPU, that is optimized for the Microsoft HoloLens.

The shaders are compiled when the project is built, and they’re loaded in the SpinningCubeRenderer::CreateDeviceDependentResources method.

Interact with your holograms

User input is processed in the SpatialInputHandler class, which gets a SpatialInteractionManager instance and subscribes to the SourcePressed event. This enables detecting the air tap gesture and other spatial input events.

Update holographic content

Your holographic app updates in a game loop, which by default is implemented in the Update method in Main.cpp. The Update method updates scene objects, like the spinning cube, and returns a HolographicFrame object that is used to get up-to-date view and projection matrices and to present the swap chain.

The Render method in Main.cpp takes the HolographicFrame and renders the current frame to each holographic camera, according to the current app and spatial positioning state.

See also

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *

This site uses Akismet to reduce spam. Learn how your comment data is processed.