示例#1
0
        /// <summary>
        /// Create the overlay buffers for this camera at the required size.
        /// </summary>
        public void CreateOverlays(Camera cam, WaveOverlayData overlay, OVERLAY_MAP_SIZE normalOverlaySize, OVERLAY_MAP_SIZE heightOverlaySize, OVERLAY_MAP_SIZE foamOverlaySize, OVERLAY_MAP_SIZE clipOverlaySize)
        {
            //If the manager has a overlay of this type then create the map it renders into
            if (HasNormalOverlay)
            {
                RenderTextureFormat format = RenderTextureFormat.ARGBHalf;

                //The mask will work but adding normals will not with this format. TODO - fix this
                if (!SystemInfo.SupportsRenderTextureFormat(format))
                {
                    format = RenderTextureFormat.ARGB32;
                }

                CreateBuffer("Normal", cam, normalOverlaySize, format, true, ref overlay.normal);
            }

            if (HasHeightOverlay)
            {
                RenderTextureFormat format = RenderTextureFormat.RGHalf;

                if (!SystemInfo.SupportsRenderTextureFormat(format))
                {
                    format = RenderTextureFormat.ARGBHalf;
                }

                if (!SystemInfo.SupportsRenderTextureFormat(format))
                {
                    format = RenderTextureFormat.ARGB32;
                }

                CreateBuffer("Height", cam, heightOverlaySize, format, true, ref overlay.height);
            }

            if (HasFoamOverlay)
            {
                RenderTextureFormat format = RenderTextureFormat.ARGB32;

                CreateBuffer("Foam", cam, foamOverlaySize, format, false, ref overlay.foam);
            }

            if (HasClipOverlay)
            {
                RenderTextureFormat format = RenderTextureFormat.R8;

                if (!SystemInfo.SupportsRenderTextureFormat(format))
                {
                    format = RenderTextureFormat.RHalf;
                }

                if (!SystemInfo.SupportsRenderTextureFormat(format))
                {
                    format = RenderTextureFormat.ARGB32;
                }

                CreateBuffer("Clip", cam, clipOverlaySize, format, true, ref overlay.clip);
            }
        }
示例#2
0
 public void RenderWaveOverlays(GameObject go)
 {
     try
     {
         if (base.enabled)
         {
             Camera current = Camera.current;
             if (!this.m_cameraData.ContainsKey(current))
             {
                 this.m_cameraData.Add(current, new CameraData());
             }
             CameraData cameraData = this.m_cameraData[current];
             if (cameraData.overlay == null)
             {
                 cameraData.overlay = new WaveOverlayData();
             }
             if (cameraData.projection == null)
             {
                 cameraData.projection = new ProjectionData();
             }
             if (!cameraData.overlay.updated)
             {
                 if (!cameraData.projection.updated)
                 {
                     this.Projection.UpdateProjection(current, cameraData, this.ProjectSceneView);
                     Shader.SetGlobalMatrix("Ceto_Interpolation", cameraData.projection.interpolation);
                     Shader.SetGlobalMatrix("Ceto_ProjectorVP", cameraData.projection.projectorVP);
                 }
                 if (this.GetDisableAllOverlays(cameraData.settings))
                 {
                     this.OverlayManager.DestroyBuffers(cameraData.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 overlay_MAP_SIZE  = (!(cameraData.settings != null)) ? this.normalOverlaySize : cameraData.settings.normalOverlaySize;
                     OVERLAY_MAP_SIZE overlay_MAP_SIZE2 = (!(cameraData.settings != null)) ? this.heightOverlaySize : cameraData.settings.heightOverlaySize;
                     OVERLAY_MAP_SIZE overlay_MAP_SIZE3 = (!(cameraData.settings != null)) ? this.foamOverlaySize : cameraData.settings.foamOverlaySize;
                     OVERLAY_MAP_SIZE overlay_MAP_SIZE4 = (!(cameraData.settings != null)) ? this.clipOverlaySize : cameraData.settings.clipOverlaySize;
                     this.OverlayManager.CreateOverlays(current, cameraData.overlay, overlay_MAP_SIZE, overlay_MAP_SIZE2, overlay_MAP_SIZE3, overlay_MAP_SIZE4);
                     this.OverlayManager.HeightOverlayBlendMode = this.heightBlendMode;
                     this.OverlayManager.FoamOverlayBlendMode   = this.foamBlendMode;
                     this.OverlayManager.RenderWaveOverlays(current, cameraData.overlay);
                 }
                 cameraData.overlay.updated = true;
             }
         }
     }
     catch (Exception ex)
     {
         Ocean.LogError(ex.ToString());
         this.DisableOcean();
     }
 }
示例#3
0
 public void CreateOverlays(Camera cam, WaveOverlayData overlay, OVERLAY_MAP_SIZE normalOverlaySize, OVERLAY_MAP_SIZE heightOverlaySize, OVERLAY_MAP_SIZE foamOverlaySize, OVERLAY_MAP_SIZE clipOverlaySize)
 {
     if (this.HasNormalOverlay)
     {
         RenderTextureFormat format = RenderTextureFormat.ARGBHalf;
         if (!SystemInfo.SupportsRenderTextureFormat(format))
         {
             format = RenderTextureFormat.ARGB32;
         }
         this.CreateBuffer("Normal", cam, normalOverlaySize, format, true, ref overlay.normal);
     }
     if (this.HasHeightOverlay)
     {
         RenderTextureFormat format2 = RenderTextureFormat.RGHalf;
         if (!SystemInfo.SupportsRenderTextureFormat(format2))
         {
             format2 = RenderTextureFormat.ARGBHalf;
         }
         if (!SystemInfo.SupportsRenderTextureFormat(format2))
         {
             format2 = RenderTextureFormat.ARGB32;
         }
         this.CreateBuffer("Height", cam, heightOverlaySize, format2, true, ref overlay.height);
     }
     if (this.HasFoamOverlay)
     {
         RenderTextureFormat format3 = RenderTextureFormat.ARGB32;
         this.CreateBuffer("Foam", cam, foamOverlaySize, format3, false, ref overlay.foam);
     }
     if (this.HasClipOverlay)
     {
         RenderTextureFormat format4 = RenderTextureFormat.R8;
         if (!SystemInfo.SupportsRenderTextureFormat(format4))
         {
             format4 = RenderTextureFormat.RHalf;
         }
         if (!SystemInfo.SupportsRenderTextureFormat(format4))
         {
             format4 = RenderTextureFormat.ARGB32;
         }
         this.CreateBuffer("Clip", cam, clipOverlaySize, format4, true, ref overlay.clip);
     }
 }
示例#4
0
        public void CreateBuffer(string name, Camera cam, OVERLAY_MAP_SIZE size, RenderTextureFormat format, bool isLinear, ref RenderTexture map)
        {
            float num  = this.SizeToValue(size);
            int   num2 = Mathf.Min(4096, (int)((float)cam.pixelWidth * num));
            int   num3 = Mathf.Min(4096, (int)((float)cam.pixelHeight * num));

            if (map == null || map.width != num2 || map.height != num3)
            {
                if (map != null)
                {
                    RTUtility.ReleaseAndDestroy(map);
                }
                RenderTextureReadWrite readWrite = (!isLinear) ? RenderTextureReadWrite.Default : RenderTextureReadWrite.Linear;
                map            = new RenderTexture(num2, num3, 0, format, readWrite);
                map.useMipMap  = false;
                map.filterMode = FilterMode.Bilinear;
                map.hideFlags  = HideFlags.DontSave;
                map.name       = "Ceto Overlay " + name + " Buffer: " + cam.name;
            }
        }
示例#5
0
        /// <summary>
        /// Convert enum to a size.
        /// </summary>
        float SizeToValue(OVERLAY_MAP_SIZE size)
        {
            switch ((int)size)
            {
            case (int)OVERLAY_MAP_SIZE.DOUBLE:
                return(2.0f);

            case (int)OVERLAY_MAP_SIZE.FULL_HALF:
                return(1.5f);

            case (int)OVERLAY_MAP_SIZE.FULL:
                return(1.0f);

            case (int)OVERLAY_MAP_SIZE.HALF:
                return(0.5f);

            case (int)OVERLAY_MAP_SIZE.QUARTER:
                return(0.25f);
            }

            return(1.0f);
        }
示例#6
0
        private float SizeToValue(OVERLAY_MAP_SIZE size)
        {
            switch (size)
            {
            case OVERLAY_MAP_SIZE.DOUBLE:
                return(2f);

            case OVERLAY_MAP_SIZE.FULL_HALF:
                return(1.5f);

            case OVERLAY_MAP_SIZE.FULL:
                return(1f);

            case OVERLAY_MAP_SIZE.HALF:
                return(0.5f);

            case OVERLAY_MAP_SIZE.QUARTER:
                return(0.25f);

            default:
                return(1f);
            }
        }
示例#7
0
        /// <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();
            }
        }
示例#8
0
        /// <summary>
        /// Convert enum to a size.
        /// </summary>
        float SizeToValue(OVERLAY_MAP_SIZE size)
        {
            switch ((int)size)
            {

                case (int)OVERLAY_MAP_SIZE.DOUBLE:
                    return 2.0f;

                case (int)OVERLAY_MAP_SIZE.FULL_HALF:
                    return 1.5f;

                case (int)OVERLAY_MAP_SIZE.FULL:
                    return 1.0f;

                case (int)OVERLAY_MAP_SIZE.HALF:
                    return 0.5f;

                case (int)OVERLAY_MAP_SIZE.QUARTER:
                    return 0.25f;

            }

            return 1.0f;
        }
示例#9
0
        /// <summary>
        /// Create the overlay buffers for this camera at the required size.
        /// </summary>
        public void CreateOverlays(Camera cam, WaveOverlayData overlay, OVERLAY_MAP_SIZE normalOverlaySize, OVERLAY_MAP_SIZE heightOverlaySize, OVERLAY_MAP_SIZE foamOverlaySize, OVERLAY_MAP_SIZE clipOverlaySize)
        {
            //If the manager has a overlay of this type then create the map it renders into
            if (HasNormalOverlay)
            {
                RenderTextureFormat format = RenderTextureFormat.ARGBHalf;

                if (!SystemInfo.SupportsRenderTextureFormat(format))
                    format = RenderTextureFormat.ARGB32; //The mask will work but adding normals will not with this format.

                CreateBuffer("Normal", cam, normalOverlaySize, format, true, ref overlay.normal);
            }

            if (HasHeightOverlay)
            {
                RenderTextureFormat format = RenderTextureFormat.RGHalf;

                if (!SystemInfo.SupportsRenderTextureFormat(format))
                    format = RenderTextureFormat.ARGB32;

                CreateBuffer("Height", cam, heightOverlaySize, format, true, ref overlay.height);
            }

            if (HasFoamOverlay)
            {
                RenderTextureFormat format = RenderTextureFormat.ARGB32;

                CreateBuffer("Foam", cam, foamOverlaySize, format, false, ref overlay.foam);
            }

            if (HasClipOverlay)
            {
                RenderTextureFormat format = RenderTextureFormat.R8;

                if (!SystemInfo.SupportsRenderTextureFormat(format))
                    format = RenderTextureFormat.RHalf;

                if (!SystemInfo.SupportsRenderTextureFormat(format))
                    format = RenderTextureFormat.ARGB32;

                CreateBuffer("Clip", cam, clipOverlaySize, format, true, ref overlay.clip);
            }
        }
示例#10
0
        /// <summary>
        /// Create a overlay buffer with these settings.
        /// </summary>
        public void CreateBuffer(string name, Camera cam, OVERLAY_MAP_SIZE size, RenderTextureFormat format, bool isLinear, ref RenderTexture map)
        {
            float S = SizeToValue(size);

            int w = Mathf.Min(4096, (int)(cam.pixelWidth * S));
            int h = Mathf.Min(4096, (int)(cam.pixelHeight * S));

            if (map == null || map.width != w || map.height != h)
            {
                if (map != null)
                    RTUtility.ReleaseAndDestroy(map);

                RenderTextureReadWrite rw = (isLinear) ? RenderTextureReadWrite.Linear : RenderTextureReadWrite.Default;

                map = new RenderTexture(w, h, 0, format, rw);
                map.useMipMap = false;
                map.filterMode = FilterMode.Bilinear;
                map.hideFlags = HideFlags.DontSave;
                map.name = "Ceto Overlay " + name + " Buffer: " + cam.name;
            }
        }