コード例 #1
0
ファイル: Ocean.cs プロジェクト: OneYoungMean/Ceto
        /// <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);
        }
コード例 #2
0
ファイル: Ocean.cs プロジェクト: OneYoungMean/Ceto
        void OnDestroy()
        {
            try
            {
                Ocean.Instance = null;

                if (OverlayManager != null)
                {
                    OverlayManager.Release();
                }

                if (m_scheduler != null)
                {
                    m_scheduler.ShutingDown = true;
                    m_scheduler.CancelAllTasks();
                }

                List <Camera> tmp = new List <Camera>(m_cameraData.Keys);
                foreach (Camera cam in tmp)
                {
                    RemoveCameraData(cam);
                }
            }
            catch (Exception e)
            {
                LogError(e.ToString());
                DisableOcean();
            }
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
        void Awake()
        {
            try
            {
#if CETO_DEBUG_SCHEDULER
                LogInfo("Debug scheduler is on");
#endif

                //There can only be one ocean in a scene
                if (Instance != null)
                {
                    throw new InvalidOperationException("There can only be one ocean instance.");
                }
                else
                {
                    Instance = this;
                }

                WindDirVector = CalculateWindDirVector();

                if (doublePrecisionProjection)
                {
                    Projection = new Projection3d(this);
                }
                else
                {
                    Projection = new Projection3f(this);
                }

                OceanTime = new OceanTime();

                m_waveOverlayMat = new Material(waveOverlaySdr);

                OverlayManager = new OverlayManager(m_waveOverlayMat);

                m_scheduler = new Scheduler();
            }
            catch (Exception e)
            {
                LogError(e.ToString());
                DisableOcean();
            }
        }
コード例 #5
0
ファイル: Ocean.cs プロジェクト: OneYoungMean/Ceto
        /// <summary>
        /// Query the waves at world position xz.
        /// </summary>
        public void QueryWaves(WaveQuery query)
        {
            //Clear previous result in query.
            query.result.Clear();

            if (enabled)
            {
                if (Spectrum != null)
                {
                    Spectrum.QueryWaves(query);
                }

                if (OverlayManager != null)
                {
                    OverlayManager.QueryWaves(query);
                }
            }

            query.result.height += level;
        }
コード例 #6
0
ファイル: Ocean.cs プロジェクト: OneYoungMean/Ceto
        /// <summary>
        /// Query the waves at world position xz.
        /// </summary>
        public float QueryWaves(float x, float z)
        {
            m_query.result.Clear();
            m_query.posX = x;
            m_query.posZ = z;

            if (enabled)
            {
                if (Spectrum != null)
                {
                    Spectrum.QueryWaves(m_query);
                }

                if (OverlayManager != null)
                {
                    OverlayManager.QueryWaves(m_query);
                }
            }

            return(m_query.result.height + level);
        }
コード例 #7
0
ファイル: Ocean.cs プロジェクト: OneYoungMean/Ceto
        void Update()
        {
            try
            {
                WindDirVector = CalculateWindDirVector();

                Projection.TightFit = tightProjectionFit;

                UpdateOceanScheduler();

                OverlayManager.Update();

                specularRoughness = Mathf.Clamp01(specularRoughness);
                specularIntensity = Mathf.Max(0.0f, specularIntensity);
                minFresnel        = Mathf.Clamp01(minFresnel);
                fresnelPower      = Mathf.Max(0.0f, fresnelPower);
                foamIntensity     = Math.Max(0.0f, foamIntensity);

                float sr = Mathf.Lerp(2e-5f, 2e-2f, specularRoughness);

                Shader.SetGlobalColor("Ceto_DefaultSkyColor", defaultSkyColor);
                Shader.SetGlobalColor("Ceto_DefaultOceanColor", defaultOceanColor);
                Shader.SetGlobalFloat("Ceto_SpecularRoughness", sr);
                Shader.SetGlobalFloat("Ceto_FresnelPower", fresnelPower);
                Shader.SetGlobalFloat("Ceto_SpecularIntensity", specularIntensity);
                Shader.SetGlobalFloat("Ceto_MinFresnel", minFresnel);
                Shader.SetGlobalFloat("Ceto_OceanLevel", level);
                Shader.SetGlobalFloat("Ceto_MaxWaveHeight", MAX_SPECTRUM_WAVE_HEIGHT);
                Shader.SetGlobalColor("Ceto_FoamTint", foamTint * foamIntensity);
                Shader.SetGlobalVector("Ceto_SunDir", SunDir());
                Shader.SetGlobalVector("Ceto_SunColor", SunColor());

                Vector4 foamParam0 = new Vector4();
                foamParam0.x = (foamTexture0.scale.x != 0.0f) ? 1.0f / foamTexture0.scale.x : 1.0f;
                foamParam0.y = (foamTexture0.scale.y != 0.0f) ? 1.0f / foamTexture0.scale.y : 1.0f;
                foamParam0.z = foamTexture0.scrollSpeed * OceanTime.Now;
                foamParam0.w = 0.0f;

                Vector4 foamParam1 = new Vector4();
                foamParam1.x = (foamTexture1.scale.x != 0.0f) ? 1.0f / foamTexture1.scale.x : 1.0f;
                foamParam1.y = (foamTexture1.scale.y != 0.0f) ? 1.0f / foamTexture1.scale.y : 1.0f;
                foamParam1.z = foamTexture1.scrollSpeed * OceanTime.Now;
                foamParam1.w = 0.0f;

                Shader.SetGlobalTexture("Ceto_FoamTexture0", ((foamTexture0.tex != null) ? foamTexture0.tex : Texture2D.whiteTexture));
                Shader.SetGlobalVector("Ceto_FoamTextureScale0", foamParam0);

                Shader.SetGlobalTexture("Ceto_FoamTexture1", ((foamTexture1.tex != null) ? foamTexture1.tex : Texture2D.whiteTexture));
                Shader.SetGlobalVector("Ceto_FoamTextureScale1", foamParam1);

                //Rest each data element so they are updated this frame.
                var e = m_cameraData.GetEnumerator();
                while (e.MoveNext())
                {
                    CameraData data = e.Current.Value;

                    if (data.mask != null)
                    {
                        data.mask.ClearUpdatedViews();
                    }
                    if (data.depth != null)
                    {
                        data.depth.ClearUpdatedViews();
                    }
                    if (data.overlay != null)
                    {
                        data.overlay.ClearUpdatedViews();
                    }
                    if (data.reflection != null)
                    {
                        data.reflection.ClearUpdatedViews();
                    }

                    if (data.projection != null)
                    {
                        data.projection.ClearUpdatedViews();
                        data.projection.checkedForFlipping = false;
                    }
                }
            }
            catch (Exception e)
            {
                LogError(e.ToString());
                DisableOcean();
            }
        }
コード例 #8
0
ファイル: Ocean.cs プロジェクト: OneYoungMean/Ceto
        //OYM:  报错
        void Awake()
        {
            try
            {
                //There can only be one ocean in a scene
                if (Instance != null)
                {
                    throw new InvalidOperationException("There can only be one ocean instance.");
                }
                //OYM:  检测是否有多个实例的
                else
                {
                    Instance = this;
                }

                //This is so I dont forget to set these back to false when finished debugging.
                if (DISABLE_ALL_MULTITHREADING)
                {
                    LogInfo("Disabled multithreading is on");
                }
                if (DISABLE_FOURIER_MULTITHREADING)
                {
                    LogInfo("Disabled Fourier multithreading is on");
                }
                if (DISABLE_PROJECTED_GRID_BORDER)
                {
                    LogInfo("Disabled projection border is on");
                }
                if (DISABLE_PROJECTION_FLIPPING)
                {
                    LogInfo("Disabled flipping is on");
                }
                if (DISABLE_PROJECT_SCENE_VIEW)
                {
                    LogInfo("Disabled project scene is on");
                }
                //OYM:  报错

#if CETO_DEBUG_SCHEDULER
                LogInfo("Debug scheduler is on");
#endif

#if UNITY_WEBGL
                DISABLE_ALL_MULTITHREADING = true;
                LogInfo("Disabled multithreading for WebGL");
#endif

#if CETO_USE_STEAM_VR
                LogInfo("Ceto using StreamVR enabled");
                //OYM:  蛤?
#endif

                OceanVR.Initialize();

                WindDirVector = CalculateWindDirVector();//OYM:  计算风力

                if (doublePrecisionProjection)
                {
                    Projection = new Projection3d(this);//OYM:  双精度函数
                }
                else
                {
                    Projection = new Projection3f(this);
                }

                OceanTime = new OceanTime();                           //OYM:  获取时间,这个地方是考虑到可以改的地方吗

                m_waveOverlayMat = new Material(waveOverlaySdr);       //OYM:  创建material

                OverlayManager = new OverlayManager(m_waveOverlayMat); //OYM:  管理器

                m_scheduler = new Scheduler(100, 100, this);           //OYM:  线程设置
            }
            catch (Exception e)
            {
                LogError(e.ToString());
                DisableOcean();
            }
        }
コード例 #9
0
ファイル: Ocean.cs プロジェクト: OneYoungMean/Ceto
        /// <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();
            }
        }
コード例 #10
0
ファイル: Ocean.cs プロジェクト: BenjaminLovegrove/ATR
		void Awake()
		{

            try
            {

#if CETO_DEBUG_SCHEDULER
				LogInfo("Debug scheduler is on");
#endif

                //There can only be one ocean in a scene
                if (Instance != null)
				{
					throw new InvalidOperationException("There can only be one ocean instance.");
				}
				else
				{
					Instance = this;
				}

                WindDirVector = CalculateWindDirVector();

				if(doublePrecisionProjection)
					Projection = new Projection3d(this);
				else
					Projection = new Projection3f(this);
				
				OceanTime = new OceanTime();
				
				m_waveOverlayMat = new Material(waveOverlaySdr);

				OverlayManager = new OverlayManager( m_waveOverlayMat);
			
				m_scheduler = new Scheduler();

			}
			catch(Exception e)
			{
				LogError(e.ToString());
				DisableOcean();
			}

		}
コード例 #11
0
        void Update()
        {
            // ####################################################### Modificação #######################################################################
            int    indice = 0;
            string line;

            System.IO.StreamReader file =
                new System.IO.StreamReader(@"\\VISUALIZADOR_04\server\ultimo_oceano.txt");
            while (((line = file.ReadLine()) != null) && (indice < 30))
            {
                dados [indice] = line;
                indice++;
            }
            file.Close();
            pegaDados();
            // ##############################################################################################################################################
            try
            {
                WindDirVector = CalculateWindDirVector();

                Projection.TightFit = tightProjectionFit;

                UpdateOceanScheduler();

                OverlayManager.Update();

                specularRoughness = Mathf.Clamp01(specularRoughness);
                specularIntensity = Mathf.Max(0.0f, specularIntensity);
                minFresnel        = Mathf.Clamp01(minFresnel);
                fresnelPower      = Mathf.Max(0.0f, fresnelPower);
                foamIntensity     = Math.Max(0.0f, foamIntensity);

                float sr = Mathf.Lerp(2e-5f, 2e-2f, specularRoughness);

                Shader.SetGlobalColor("Ceto_DefaultSkyColor", defaultSkyColor);
                Shader.SetGlobalColor("Ceto_DefaultOceanColor", defaultOceanColor);
                Shader.SetGlobalFloat("Ceto_SpecularRoughness", sr);
                Shader.SetGlobalFloat("Ceto_FresnelPower", fresnelPower);
                Shader.SetGlobalFloat("Ceto_SpecularIntensity", specularIntensity);
                Shader.SetGlobalFloat("Ceto_MinFresnel", minFresnel);
                Shader.SetGlobalFloat("Ceto_OceanLevel", level);
                Shader.SetGlobalFloat("Ceto_MaxWaveHeight", MAX_SPECTRUM_WAVE_HEIGHT);
                Shader.SetGlobalColor("Ceto_FoamTint", foamTint * foamIntensity); //Brian here: THIS line might give me something(duplicate it for OilTint, change shader?...Like you know how to work a shader)
                Shader.SetGlobalColor("Ceto_OilTint", oilTint);                   //proto mod
                Shader.SetGlobalVector("Ceto_SunDir", SunDir());
                Shader.SetGlobalVector("Ceto_SunColor", SunColor());

                Vector4 foamParam0 = new Vector4();
                foamParam0.x = (foamTexture0.scale.x != 0.0f) ? 1.0f / foamTexture0.scale.x : 1.0f;
                foamParam0.y = (foamTexture0.scale.y != 0.0f) ? 1.0f / foamTexture0.scale.y : 1.0f;
                foamParam0.z = foamTexture0.scrollSpeed * OceanTime.Now;
                foamParam0.w = 0.0f;

                Vector4 foamParam1 = new Vector4();
                foamParam1.x = (foamTexture1.scale.x != 0.0f) ? 1.0f / foamTexture1.scale.x : 1.0f;
                foamParam1.y = (foamTexture1.scale.y != 0.0f) ? 1.0f / foamTexture1.scale.y : 1.0f;
                foamParam1.z = foamTexture1.scrollSpeed * OceanTime.Now;
                foamParam1.w = 0.0f;

                Shader.SetGlobalTexture("Ceto_FoamTexture0", ((foamTexture0.tex != null) ? foamTexture0.tex : Texture2D.whiteTexture));
                Shader.SetGlobalVector("Ceto_FoamTextureScale0", foamParam0);

                Shader.SetGlobalTexture("Ceto_FoamTexture1", ((foamTexture1.tex != null) ? foamTexture1.tex : Texture2D.whiteTexture));
                Shader.SetGlobalVector("Ceto_FoamTextureScale1", foamParam1);

                //Rest each data element so they are updated this frame.
                var e = m_cameraData.GetEnumerator();
                while (e.MoveNext())
                {
                    CameraData data = e.Current.Value;

                    if (data.mask != null)
                    {
                        data.mask.ClearUpdatedViews();
                    }
                    if (data.depth != null)
                    {
                        data.depth.ClearUpdatedViews();
                    }
                    if (data.overlay != null)
                    {
                        data.overlay.ClearUpdatedViews();
                    }
                    if (data.reflection != null)
                    {
                        data.reflection.ClearUpdatedViews();
                    }

                    if (data.projection != null)
                    {
                        data.projection.ClearUpdatedViews();
                        data.projection.checkedForFlipping = false;
                    }
                }
            }
            catch (Exception e)
            {
                LogError(e.ToString());
                DisableOcean();
            }
        }