コード例 #1
0
        void LateUpdateViewerHeight()
        {
            Vector3 pos = Viewpoint.position;
            float   waterHeight;

            if (CollisionProvider.SampleHeight(ref pos, out waterHeight))
            {
                ViewerHeightAboveWater = pos.y - waterHeight;
            }
        }
コード例 #2
0
        void LateUpdateViewerHeight()
        {
            var pos  = Viewpoint.position;
            var rect = new Rect(pos.x, pos.z, 0f, 0f);

            float waterHeight;

            if (CollisionProvider.GetSamplingData(ref rect, 0f, _samplingData) &&
                CollisionProvider.SampleHeight(ref pos, _samplingData, out waterHeight))
            {
                ViewerHeightAboveWater = pos.y - waterHeight;
            }

            CollisionProvider.ReturnSamplingData(_samplingData);
        }
コード例 #3
0
ファイル: OceanRenderer.cs プロジェクト: A-Productions/crest
        private void CleanUp()
        {
            foreach (var lodData in _lodDatas)
            {
                lodData.OnDisable();
            }
            _lodDatas.Clear();

#if UNITY_EDITOR
            if (!EditorApplication.isPlaying && Root != null)
            {
                DestroyImmediate(Root.gameObject);
            }
            else
#endif
            if (Root != null)
            {
                Destroy(Root.gameObject);
            }

            Root = null;

            _lodTransform       = null;
            _lodDataAnimWaves   = null;
            _lodDataClipSurface = null;
            _lodDataDynWaves    = null;
            _lodDataFlow        = null;
            _lodDataFoam        = null;
            _lodDataSeaDepths   = null;
            _lodDataShadow      = null;

            if (CollisionProvider != null)
            {
                CollisionProvider.CleanUp();
                CollisionProvider = null;
            }

            if (FlowProvider != null)
            {
                FlowProvider.CleanUp();
                FlowProvider = null;
            }

            _oceanChunkRenderers.Clear();
        }
コード例 #4
0
ファイル: OceanRenderer.cs プロジェクト: A-Productions/crest
        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

            _isFirstUpdate = false;
        }