private void CreateCamera() { if (_camera == null) { var camGo = new GameObject("ShadowMap Camera"); _camera = camGo.AddComponent <Camera>(); _cameraTrans = _camera.transform; // 如果改成专用的阴影的话,DC的耗时应该能降低,相对应的RT格式也得更改 _camera.SetReplacementShader(ShaderHelper.Find(ShaderHelper.DepthPass), ShaderHelper.RenderTypeTag); } _camera.backgroundColor = Color.white; _camera.clearFlags = CameraClearFlags.SolidColor; _camera.orthographic = true; _camera.targetTexture = _shadowMap; // 没必要额外生成阴影贴图 // _camera.depthTextureMode = DepthTextureMode.Depth; _camera.depthTextureMode = DepthTextureMode.None; _camera.orthographicSize = _cameraSize; _camera.nearClipPlane = _cameraNear; _camera.farClipPlane = _cameraFar; _camera.allowHDR = false; // 采用渲染物体的Layer,可能得更改 _camera.cullingMask = 1 << gameObject.layer; UpdateCameraPosition(); CheckUpdateCameraMatrix(true); }