Example #1
0
        void CreateDestroySubSystems()
        {
            {
                if (_lodDataAnimWaves == null)
                {
                    _lodDataAnimWaves = new LodDataMgrAnimWaves(this);
                    _lodDatas.Add(_lodDataAnimWaves);
                }
            }

            if (CreateClipSurfaceData)
            {
                if (_lodDataClipSurface == null)
                {
                    _lodDataClipSurface = new LodDataMgrClipSurface(this);
                    _lodDatas.Add(_lodDataClipSurface);
                }
            }
            else
            {
                if (_lodDataClipSurface != null)
                {
                    _lodDataClipSurface.OnDisable();
                    _lodDatas.Remove(_lodDataClipSurface);
                    _lodDataClipSurface = null;
                }
            }

            if (CreateDynamicWaveSim)
            {
                if (_lodDataDynWaves == null)
                {
                    _lodDataDynWaves = new LodDataMgrDynWaves(this);
                    _lodDatas.Add(_lodDataDynWaves);
                }
            }
            else
            {
                if (_lodDataDynWaves != null)
                {
                    _lodDataDynWaves.OnDisable();
                    _lodDatas.Remove(_lodDataDynWaves);
                    _lodDataDynWaves = null;
                }
            }

            if (CreateFlowSim)
            {
                if (_lodDataFlow == null)
                {
                    _lodDataFlow = new LodDataMgrFlow(this);
                    _lodDatas.Add(_lodDataFlow);
                }

                if (FlowProvider != null && !(FlowProvider is QueryFlow))
                {
                    FlowProvider.CleanUp();
                    FlowProvider = null;
                }
            }
            else
            {
                if (_lodDataFlow != null)
                {
                    _lodDataFlow.OnDisable();
                    _lodDatas.Remove(_lodDataFlow);
                    _lodDataFlow = null;
                }

                if (FlowProvider != null && FlowProvider is QueryFlow)
                {
                    FlowProvider.CleanUp();
                    FlowProvider = null;
                }
            }
            if (FlowProvider == null)
            {
                FlowProvider = _lodDataAnimWaves.Settings.CreateFlowProvider(this);
            }

            if (CreateFoamSim)
            {
                if (_lodDataFoam == null)
                {
                    _lodDataFoam = new LodDataMgrFoam(this);
                    _lodDatas.Add(_lodDataFoam);
                }
            }
            else
            {
                if (_lodDataFoam != null)
                {
                    _lodDataFoam.OnDisable();
                    _lodDatas.Remove(_lodDataFoam);
                    _lodDataFoam = null;
                }
            }

            if (CreateSeaFloorDepthData)
            {
                if (_lodDataSeaDepths == null)
                {
                    _lodDataSeaDepths = new LodDataMgrSeaFloorDepth(this);
                    _lodDatas.Add(_lodDataSeaDepths);
                }
            }
            else
            {
                if (_lodDataSeaDepths != null)
                {
                    _lodDataSeaDepths.OnDisable();
                    _lodDatas.Remove(_lodDataSeaDepths);
                    _lodDataSeaDepths = null;
                }
            }

            if (CreateShadowData)
            {
                if (_lodDataShadow == null)
                {
                    _lodDataShadow = new LodDataMgrShadow(this);
                    _lodDatas.Add(_lodDataShadow);
                }
            }
            else
            {
                if (_lodDataShadow != null)
                {
                    _lodDataShadow.OnDisable();
                    _lodDatas.Remove(_lodDataShadow);
                    _lodDataShadow = null;
                }
            }

            // Potential extension - add 'type' field to collprovider and change provider if settings have changed - this would support runtime changes.
            if (CollisionProvider == null)
            {
                CollisionProvider = _lodDataAnimWaves.Settings.CreateCollisionProvider();
            }
        }
Example #2
0
        void RunUpdate()
        {
            // Do this *before* changing the ocean position, as it needs the current LOD positions to associate with the current queries
            CollisionProvider.UpdateQueries();
            FlowProvider.UpdateQueries();

            // set global shader params
            Shader.SetGlobalFloat(sp_texelsPerWave, MinTexelsPerWave);
            Shader.SetGlobalFloat(sp_crestTime, CurrentTime);
            Shader.SetGlobalFloat(sp_sliceCount, CurrentLodCount);
            Shader.SetGlobalFloat(sp_clipByDefault, _defaultClippingState == DefaultClippingState.EverythingClipped ? 1f : 0f);
            Shader.SetGlobalFloat(sp_lodAlphaBlackPointFade, _lodAlphaBlackPointFade);
            Shader.SetGlobalFloat(sp_lodAlphaBlackPointWhitePointFade, _lodAlphaBlackPointWhitePointFade);

            // LOD 0 is blended in/out when scale changes, to eliminate pops. Here we set it as a global, whereas in OceanChunkRenderer it
            // is applied to LOD0 tiles only through _InstanceData. This global can be used in compute, where we only apply this factor for slice 0.
            var needToBlendOutShape = ScaleCouldIncrease;
            var meshScaleLerp       = needToBlendOutShape ? ViewerAltitudeLevelAlpha : 0f;

            Shader.SetGlobalFloat(sp_meshScaleLerp, meshScaleLerp);

            if (Viewpoint == null
                )
            {
#if UNITY_EDITOR
                if (EditorApplication.isPlaying)
#endif
                {
                    Debug.LogError("Viewpoint is null, ocean update will fail.", this);
                }
            }

            if (_followViewpoint && Viewpoint != null)
            {
                LateUpdatePosition();
                LateUpdateScale();
                LateUpdateViewerHeight();
            }

            CreateDestroySubSystems();

            LateUpdateLods();

            if (Viewpoint != null)
            {
                LateUpdateTiles();
            }

            LateUpdateResetMaxDisplacementFromShape();

#if UNITY_EDITOR
            if (EditorApplication.isPlaying || !_showOceanProxyPlane)
#endif
            {
                _commandbufferBuilder.BuildAndExecute();
            }
#if UNITY_EDITOR
            else
            {
                // If we're not running, reset the frame data to avoid validation warnings
                for (int i = 0; i < _lodTransform._renderData.Length; i++)
                {
                    _lodTransform._renderData[i]._frame = -1;
                }
                for (int i = 0; i < _lodTransform._renderDataSource.Length; i++)
                {
                    _lodTransform._renderDataSource[i]._frame = -1;
                }
            }
#endif
        }