Пример #1
0
        void RunUpdate()
        {
            // set global shader params
            Shader.SetGlobalFloat(sp_texelsPerWave, MinTexelsPerWave);
            Shader.SetGlobalFloat(sp_crestTime, CurrentTime);
            Shader.SetGlobalFloat(sp_sliceCount, CurrentLodCount);
            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();
            }

            CreateDestroyLodDatas();

            LateUpdateLods();

#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
        }
Пример #2
0
        void RunUpdate()
        {
            // Run queries *before* changing the ocean position, as it needs the current LOD positions to associate with the current queries
#if UNITY_EDITOR
            // Issue #630 - seems to be a terrible memory leak coming from creating async gpu readbacks. We don't rely on queries in edit mode AFAIK
            // so knock this out.
            if (EditorApplication.isPlaying)
#endif
            {
                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 && Application.isPlaying)
            {
                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
        }