Topic locked

Suggested workaround when accessing Unity materials interferes with background texture updates

June 5, 2019 - 2:57pm #1

Vuforia Engine requires a specific setup for the material and its textures in order to ensure that the video background is rendered correctly each frame. Our workaround solution is to not directly use the VB material (which create a new instance), but create a new material and reference textures from a reference to the first one (i.e. sharedMaterial). Our example creates a shallow copy and does all the necessary setup required for rendering the camera feed.

Attached are sample scripts and a demo Unity project for a workaround solution with Vuforia Engine SDK 8.1. The provided Unity project was created with the following steps:

  1. Create an empty scene
  2. Add an ARCamera to the scene (GameObject->Vuforia Engine->ARCamera)
  3. Add a cube and rotate it, making sure the cube is visible in the ARCamera's view
  4. Copy provided MyVBMaterialBehaviour.cs and MyVideoShader81.shader (for SDK 8.1) into Assets/Vuforia/Shaders/
  5. Add MyVBMaterialBehaviour.cs to the cube
  6. Assign MyVideoShader81.shader or MyVideoShader83.shader to the "My VB Shader" property in the test script
  7. Run in PlayMode to test. You should see something similar to the attached screen shot (2019-06-04_11-33-30.jpg)

In the attached script MyVBMaterialBehaviour.cs, example code was also added to manage the lifecycle, and with other rendering formats. The script doesn't handle screen orientation, or texture format (texture size > camera image size, POT vs NPOT). This can be handled by developers - look for example code in our Occlusion Management Sample, available for free on the Unity Asset Store.

In a future release, we will provide a more convenient method to gain access to a VB material or texture.

Topic locked