Unity
The aim of this section is to provide the reader with a complete understanding of how Ncam's integration works with the Unity Editor, how to install it, use it and to also serve as a reference manual for future use. It is recommended that users first follow the step-by-step instructions on how to install Ncam's plug-in (NcamAR) and read the section Using NcamAR before proceeding. Alternatively, eager users can skip to the Quick-Start Guide section to begin using the NcamAR plug-in immediately with the demonstration scenes.
- Windows 10
- Unity LTS 2019.4
- Latest graphics drivers
- Blackmagic 11.1
Before getting started with the NcamAR plug-in for Unity a couple of one-time steps need to be completed first:
NcamAR supports Blackmagic cards for SDI video I/O. It requires a specific Blackmagic driver (version 11.1). Please ensure that it has been correctly installed and tested.
The NcamAR package needs to be imported once per project as it is not persistent from one to another. This is straightforward and is achieved by:
- Launching Unity
- Click on the New button to create a new project
- Set the location and name of the project before clicking Create Project
- Once Unity has launched, select Assets/Import Package/Custom Package... from the toolbar
- Open select the package file NcamAR-Release-x.x.x.unitypackage
- You might get the following: error CS0227: Unsafe code may only appear if compiling with /unsafe.Enable "Allow 'unsafe' code" in Player Settings to fix this error. To do this:
- Navigate to: Edit / Project Settings / Player
- Tick the box for 'Allow "unsafe" Code'
- Once prompted with the contents of the package, click Import.
The NcamAR plugin is provided with several pre-made example scenes so that eager users can easily evaluate it. These scenes are included within the NcamAR package and can be located from within the Project Browser inside the Assets/Ncam/Maps folder. All of the scenes have been set up to use the Ncam Server Emulator as their data source and can be run easily by just clicking on the Play button on the toolbar above the main Unity viewport (once the Ncam server emulator is running). The following section describes how to set up the Ncam Server Emulator to provide simulated tracking data.
- Go to the Project Browser
- Navigate to Assets/Ncam/Maps and open an example scene by double-clicking it
- Click the Play button to run the scene using the Ncam Server Emulator
The purpose of the Ncam Server Emulator is to simulate a real Ncam system, allowing us to easily replicate the data that would normally be sent from a physical Ncam server. It also allows us to precisely control the information that is sent and test our Unity scenes using a controlled environment. Therefore, before continuing to investigate and run any of the example projects, first open up the Ncam Server Emulator and click on Start Server. This sets up the server on the local host (IP address 127.0.0.1) so that any Ncam clients including the NcCamera in the NcamAR plugin can connect to it.
Once any of the example projects are connected to the Ncam Server Emulator the position, rotation, lens parameters etc. of the camera inside Unity can be changed from inside the emulator.
In this example, we are going to recreate the NcamCubeAR example project which can be found in the Quick-Start section. It demonstrates the AR use case by rendering and compositing the Ncam cube over a video feed that is supplied by the Ncam Server Emulator.
We will be using the Ncam Server Emulator to simulate a real Ncam system. Therefore, before continuing to set up your scene first open the Ncam Server Emulator and click on Start Server. Once we have created our level we should now be able to connect to the Ncam Server Emulator and control the position and rotation of the camera within the Unity editor whilst the game is running.
For reference the completed scene (NcamCubeAR) can be found in the Project Browser in the Assets/Ncam/Maps folder.
To start, ensure that a new blank project has been created and the NcamAR package has been imported into the project (see Loading the NcamAR package into a new or existing Unity project). The next step is to set up the scene. This is quite simple, we just add our Ncam cube asset and an NcCamera:
- Go to the Project Browser and navigate to Assets/Ncam/Meshes
- Drag-and-drop an NcamCube object into the viewport to add it to the scene.
- Using the Inspector panel, set the cube's XYZ transform to 0 so that it is located at the world origin.
- In the Scene Hierarchy panel select and delete the Main Camera as it will be replaced by a NcCamera from the NcamAR plugin.
- Go to the Project Browser and navigate to Assets/Ncam/Prefabs
- Drag-and-drop an NcCamera object into the viewport to add it to the scene. It's position isn't of any consequence but for the purpose of being explicit, set its XYZ translation to 0,0,-10 respectively.
If you have done the above steps correctly then your scene should look like the image below.
The settings of the NcCamera are configured to use a local running instance of the Ncam Server Emulator by default and so providing it is running, all that is left to do is click the Play button!
If everything was set up correctly then the game will have started and you will be presented with a screen that shows a thumbnail or full screen rendering of the Ncam cube composited over a video test pattern. By playing with the position of the camera in the Ncam Server Emulator the view inside Unity should react accordingly.
In this section we will cover how a scene can be configured, what options are available and where to find them. We start by discussing how the NcamCubeAR scene that is supplied as part of the NcamAR package can be modified so that it can be used in a real-world demo with a connected Ncam Server and camera. We follow by describing how the virtual world can be offset or rotated relative to the Ncam datum point using the NcOrigin object.
In order to use the NcamAR plugin with real-world input such as with a physical Ncam Server and SDI video source the scene has to be changed from the default settings. Conveniently, all of the options for doing this can be found in a single place: on the NcCamera object.
The Server section of the NcCamera parameters relates to the connection of an Ncam Server and allows the data requested from it to be specified. The default parameter for the Ncam Server's IP address is the local host (127.0.0.1) as it expects an instance of the Ncam Server Emulator to be running locally but in real applications this should be set to the IP of the Ncam Server.
The settings that relate to the input and output video sources and how they are interpreted can be found under the Video tab of the NcCamera parameters. It is here that the I/O device or channel can be specified. By default the I/O Channel is set to SDK which indicates that the video should be received via the Ncam SDK. This is only useful when connecting to the Ncam Server Emulator as in most real scenarios the video will be sent and received via an SDI interface. To use the SDI input and output select the SDI channel to use (SDI).
The Output section of the NcCamera parameters governs what will be displayed to the user in the viewport and what will be output over the SDI device. Intuitively, the contents of the viewport are specified using the Display Output parameter and the SDI output using the SDI Output parameter. The available options are CG Only, Input Only and Comp. The functions of these options are fairly self evident although it's worth noting that in order to output a composite (comp) to either the viewport or SDI a compositing node needs to first be attached to the NcCamera. The controls to do this and to also specify the compositing mode are provided under the Compositing tab.
How the NcamAR plug-in is being used will dictate how the final composite should be drawn. For example, when rendering a virtual overlay scene the computer generated graphics should appear over the top of the input video. In the case of a virtual environment the subject being filmed is often in front of a green screen which requires the video to be keyed and then overlaid on top of the CG background. The NcamAR plug-in supports both of these compositing modes and is controlled using the settings under the Compositing tab. To select the method of composure a compositing object first needs to be added to the camera. This is done by simply clicking on the Add button. The compositing order can then be specified by changing the Order parameters. Valid combinations are Film + CG for compositing in virtual overlay mode or CG + Film for the virtual studio use case.
Often the origin of the virtual world and the selected location of the Ncam datum point (which is the centre of the tracking space) don't line up well. For example, the camera inside the Unity scene may be too far away from the asset of interest or facing in the wrong direction. One solution would be to move the datum point inside Ncam Reality to find the desired viewpoint. However this is not practical if there are multiple different levels in the world and the location of Ncam needs to be changed for each of them. A better solution is to always keep the Ncam datum point in the same place and use an NcOrigin object inside Unity instead. NcOrigin is a simple object that can be placed into the scene to define the location, rotation and scale of Ncam's datum point inside the virtual world. This means that the Ncam camera's position will always move relatively to it, allowing the camera to be repositioned easily by just moving the NcOrigin around.
In order for an NcOrigin to be used to transform the world it needs to be added to the scene and then linked to the NcCamera. This can be done by:
- Go to the Project Browser and navigate to Assets/Ncam/Prefabs
- Drag-and-drop an NcOrigin object into the viewport to add it to the scene. The location and rotation of this object will define where Ncam's datum point is relative to the virtual world inside Unity. If placed at the origin with no rotation it will have no affect.
- Inside the Scene Hierarchy select the NcCamera.
- In the Inspector panel for the NcCamera locate the Origin parameter under the Ncam Plugin/Origin tab.
- Assign the newly created NcOrigin.