/// <summary> /// Remove and release this camera /// and its data from the ocean. /// </summary> public void RemoveCameraData(Camera cam) { if (!m_cameraData.ContainsKey(cam)) { return; } CameraData data = m_cameraData[cam]; if (data.overlay != null) { OverlayManager.DestroyBuffers(data.overlay); } if (data.reflection != null) { data.reflection.DestroyTargets(); data.reflection.DestroyCamera(); } if (data.depth != null) { data.depth.DestroyTargets(); data.depth.DestroyCamera(); } if (data.mask != null) { data.mask.DestroyTargets(); data.mask.DestroyCamera(); } m_cameraData.Remove(cam); }
/// <summary> /// Remove and release this camera /// and its data from the ocean. /// </summary> public void RemoveCameraData(Camera cam) { if (!m_cameraData.ContainsKey(cam)) { return; } CameraData data = m_cameraData[cam]; if (data.overlay != null) { OverlayManager.DestroyBuffers(data.overlay); } if (data.reflection != null) { RTUtility.ReleaseAndDestroy(data.reflection.tex); data.reflection.tex = null; if (data.reflection.cam != null) { RTUtility.ReleaseAndDestroy(data.reflection.cam.targetTexture); data.reflection.cam.targetTexture = null; Destroy(data.reflection.cam.gameObject); Destroy(data.reflection.cam); data.reflection.cam = null; } } if (data.depth != null) { if (data.depth.cam != null) { RTUtility.ReleaseAndDestroy(data.depth.cam.targetTexture); data.depth.cam.targetTexture = null; Destroy(data.depth.cam.gameObject); Destroy(data.depth.cam); data.depth.cam = null; } } if (data.mask != null) { if (data.mask.cam != null) { RTUtility.ReleaseAndDestroy(data.mask.cam.targetTexture); data.mask.cam.targetTexture = null; Destroy(data.mask.cam.gameObject); Destroy(data.mask.cam); data.mask.cam = null; } } m_cameraData.Remove(cam); }
/// <summary> /// This game object is about to be rendered /// and requires the wave overlays. /// Create them for the camera rendering the object /// if they have not already been updated this frame. /// </summary> public void RenderWaveOverlays(GameObject go) { try { if (!enabled) { return; } Camera cam = Camera.current; if (!m_cameraData.ContainsKey(cam)) { m_cameraData.Add(cam, new CameraData()); } CameraData data = m_cameraData[cam]; if (data.overlay == null) { data.overlay = new WaveOverlayData(); } if (data.projection == null) { data.projection = new ProjectionData(); } if (data.overlay.IsViewUpdated(cam)) { return; } //If the projection for this camera has not been updated this frame do it now. if (!data.projection.IsViewUpdated(cam)) { Projection.UpdateProjection(cam, data); Shader.SetGlobalMatrix("Ceto_Interpolation", data.projection.interpolation); Shader.SetGlobalMatrix("Ceto_ProjectorVP", data.projection.projectorVP); } //If overlays have been disabled for this camera //clear the buffers and return; if (GetDisableAllOverlays(data.settings)) { OverlayManager.DestroyBuffers(data.overlay); Shader.SetGlobalTexture("Ceto_Overlay_NormalMap", Texture2D.blackTexture); Shader.SetGlobalTexture("Ceto_Overlay_HeightMap", Texture2D.blackTexture); Shader.SetGlobalTexture("Ceto_Overlay_FoamMap", Texture2D.blackTexture); Shader.SetGlobalTexture("Ceto_Overlay_ClipMap", Texture2D.blackTexture); } else { OVERLAY_MAP_SIZE normalSize = (data.settings != null) ? data.settings.normalOverlaySize : normalOverlaySize; OVERLAY_MAP_SIZE heightSize = (data.settings != null) ? data.settings.heightOverlaySize : heightOverlaySize; OVERLAY_MAP_SIZE foamSize = (data.settings != null) ? data.settings.foamOverlaySize : foamOverlaySize; OVERLAY_MAP_SIZE clipSize = (data.settings != null) ? data.settings.clipOverlaySize : clipOverlaySize; //Create the overlay buffers. OverlayManager.CreateOverlays(cam, data.overlay, normalSize, heightSize, foamSize, clipSize); //Update blend modes. OverlayManager.HeightOverlayBlendMode = heightBlendMode; OverlayManager.FoamOverlayBlendMode = foamBlendMode; //Render the overlays OverlayManager.RenderWaveOverlays(cam, data.overlay); } data.overlay.SetViewAsUpdated(cam); } catch (Exception e) { LogError(e.ToString()); DisableOcean(); } }