AR场景无阴影

Vuforia SDK v5.5.9.

在项目中发现场景视口(Scene)观看,物体有阴影;游戏视口(Game)观看,物体无阴影。
经过在网上查找资料,找到问题所在。Vuforia自身的问题。投影矩阵出现问题。
解决方法:在ARCamera物体上(或场景其他地方)挂载如下脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
* Created by keefor on 6/13/2017.
*/
using UnityEngine;
using System.Collections;
using Vuforia;
public class FixProjectionMatrix : MonoBehaviour, IVideoBackgroundEventHandler
{
private Camera[] mCameras;
void Start()
{
mCameras = VuforiaBehaviour.Instance.GetComponentsInChildren<Camera>();
VuforiaBehaviour.Instance.RegisterVideoBgEventHandler(this);
}
public void OnVideoBackgroundConfigChanged()
{
foreach (var cam in mCameras)
{
var projMatrix = cam.projectionMatrix;
for (int i = 0; i < 16; i++)
{
if (System.Math.Abs(projMatrix[i]) < 1e-6)
{
projMatrix[i] = 0.0f;
}
}
cam.projectionMatrix = projMatrix;
}
}
}