/// <summary> /// Recalculates the geometry of every attached shadow and builds a batched mesh. /// </summary> /// <param name="frustumPlanes"> /// The frustum planes of camera that renders the scene. /// Ignored when recalculating static shadows. /// </param> /// <param name="skipRecalculate"> /// Whether to skip recalculation of shadow geometry. /// </param> private void RecalculateGeometry(Plane[] frustumPlanes, bool skipRecalculate) { // No need to rebuild static mesh when it hasn't changed bool mustRebuildMesh = !_isStatic || _isStaticDirty; int currentVisibleShadowsCount = 0; if (_isStatic) { frustumPlanes = null; } for (int i = 0, shadowCount = _shadowsList.Count; i < shadowCount; i++) { SwiftShadow shadow = _shadowsList.Items[i]; if (!skipRecalculate) { SwiftShadow.RecalculateShadowResult recalculateResult = shadow.RecalculateShadow(frustumPlanes, false); switch (recalculateResult) { case SwiftShadow.RecalculateShadowResult.ChangedManager: i--; shadowCount = _shadowsList.Count; continue; case SwiftShadow.RecalculateShadowResult.Recalculated: mustRebuildMesh = true; break; } } if (shadow.IsVisible) { currentVisibleShadowsCount++; } } if (!mustRebuildMesh || (_visibleShadowsCount == 0 && currentVisibleShadowsCount == 0)) { return; } _visibleShadowsCount = currentVisibleShadowsCount; if (_visibleShadowsCount != 0) { bool isMeshNull = _mesh == null; if (isMeshNull) { CreateMesh(); } RebuildMesh(isMeshNull || _isStatic || _isStaticDirty); _isStaticDirty = false; } _lastVisibleShadowsCount = _visibleShadowsCount; }
/// <summary> /// Registers the shadow in this manager. /// </summary> /// <param name="shadow"> /// The shadow to register. /// </param> public void RegisterShadow(SwiftShadow shadow) { if (_isStatic) { shadow.RecalculateShadow(null, true); } _shadowsList.Add(shadow); _isStaticDirty = true; }