/// <summary> /// Create the camera used for the ocean depths /// If it has already been created then just update it. /// Also create the render targets for the camera. /// </summary> void CreateDepthCameraFor(Camera cam, DepthData data) { if (data.cam == null) { GameObject go = new GameObject("Ceto Depth Camera: " + cam.name); go.hideFlags = HideFlags.HideAndDontSave; go.AddComponent <IgnoreOceanEvents>(); go.AddComponent <DisableFog>(); go.AddComponent <DisableShadows>(); data.cam = go.AddComponent <Camera>(); data.cam.clearFlags = CameraClearFlags.SolidColor; data.cam.backgroundColor = Color.white; data.cam.enabled = false; data.cam.renderingPath = RenderingPath.Forward; data.cam.targetTexture = null; data.cam.useOcclusionCulling = false; data.cam.RemoveAllCommandBuffers(); data.cam.targetTexture = null; } //Note - position rotation and projection set before rendering. //Update other settings here. data.cam.fieldOfView = cam.fieldOfView; data.cam.nearClipPlane = cam.nearClipPlane; data.cam.farClipPlane = cam.farClipPlane; data.cam.orthographic = cam.orthographic; data.cam.aspect = cam.aspect; data.cam.orthographicSize = cam.orthographicSize; data.cam.rect = new Rect(0, 0, 1, 1); data.cam.layerCullDistances = cam.layerCullDistances; data.cam.layerCullSpherical = cam.layerCullSpherical; if (data.target0 == null || data.target0.width != cam.pixelWidth || data.target0.height != cam.pixelHeight) { data.DestroyTargets(); int width = cam.pixelWidth; int height = cam.pixelHeight; int depth = 24; RenderTextureFormat format = RenderTextureFormat.RGFloat; if (!SystemInfo.SupportsRenderTextureFormat(format)) { format = RenderTextureFormat.RGHalf; } if (!SystemInfo.SupportsRenderTextureFormat(format)) { format = RenderTextureFormat.ARGBHalf; } data.target0 = new RenderTexture(width, height, depth, format, RenderTextureReadWrite.Linear); data.target0.filterMode = FilterMode.Point; data.target0.hideFlags = HideFlags.DontSave; data.target0.name = "Ceto Ocean Depths Render Target0: " + cam.name; if (cam.stereoEnabled) { data.target1 = new RenderTexture(width, height, depth, format, RenderTextureReadWrite.Linear); data.target1.filterMode = FilterMode.Point; data.target1.hideFlags = HideFlags.DontSave; data.target1.name = "Ceto Ocean Depths Render Target1: " + cam.name; } } }