Beispiel #1
0
        private void LateUpdate()
        {
            // find which lod this object is overlapping
            var rect = new Rect(transform.position.x, transform.position.z, 0f, 0f);
            var idx  = LodDataAnimatedWaves.SuggestDataLOD(rect);

            if (idx > -1)
            {
                if (_mpb == null)
                {
                    _mpb = new MaterialPropertyBlock();
                }

                _rend.GetPropertyBlock(_mpb);

                var ldaws = OceanRenderer.Instance._lodDataAnimWaves;
                ldaws[idx].BindResultData(0, _mpb);
                int idx1 = Mathf.Min(idx + 1, ldaws.Length - 1);
                ldaws[idx1].BindResultData(1, _mpb);

                // blend LOD 0 shape in/out to avoid pop, if the ocean might scale up later (it is smaller than its maximum scale)
                bool  needToBlendOutShape = idx == 0 && OceanRenderer.Instance.ScaleCouldIncrease;
                float meshScaleLerp       = needToBlendOutShape ? OceanRenderer.Instance.ViewerAltitudeLevelAlpha : 0f;

                // blend furthest normals scale in/out to avoid pop, if scale could reduce
                bool  needToBlendOutNormals = idx == ldaws.Length - 1 && OceanRenderer.Instance.ScaleCouldDecrease;
                float farNormalsWeight      = needToBlendOutNormals ? OceanRenderer.Instance.ViewerAltitudeLevelAlpha : 1f;
                _mpb.SetVector("_InstanceData", new Vector4(meshScaleLerp, farNormalsWeight, idx));

                _rend.SetPropertyBlock(_mpb);
            }

            LateUpdateBounds();
        }
        public bool SampleDisplacement(ref Vector3 worldPos, ref Vector3 displacement)
        {
            int lod = LodDataAnimatedWaves.SuggestDataLOD(new Rect(worldPos.x, worldPos.z, 0f, 0f), 0f);

            if (lod == -1)
            {
                return(false);
            }
            return(OceanRenderer.Instance.Builder._lodDataAnimWaves[lod].SampleDisplacement(ref worldPos, ref displacement));
        }
        public bool SampleDisplacement(ref Vector3 in__worldPos, out Vector3 displacement)
        {
            int lod = LodDataAnimatedWaves.SuggestDataLOD(new Rect(in__worldPos.x, in__worldPos.z, 0f, 0f), 0f);

            if (lod == -1)
            {
                displacement = Vector3.zero;
                return(false);
            }
            return(OceanRenderer.Instance._lodDataAnimWaves[lod].SampleDisplacement(ref in__worldPos, out displacement));
        }
        public bool SampleHeight(ref Vector3 worldPos, ref float height)
        {
            int lod = LodDataAnimatedWaves.SuggestDataLOD(new Rect(worldPos.x, worldPos.z, 0f, 0f), 0f);

            if (lod == -1)
            {
                return(false);
            }
            height = OceanRenderer.Instance.Builder._lodDataAnimWaves[lod].GetHeight(ref worldPos);
            return(true);
        }
 public void PrewarmForSamplingArea(Rect areaXZ, float minSpatialLength)
 {
     _areaLod = LodDataAnimatedWaves.SuggestDataLOD(areaXZ, minSpatialLength);
 }
 public void PrewarmForSamplingArea(Rect areaXZ)
 {
     _areaLod = LodDataAnimatedWaves.SuggestDataLOD(areaXZ);
 }
 public bool PrewarmForSamplingArea(Rect areaXZ)
 {
     _areaLod = LodDataAnimatedWaves.SuggestDataLOD(areaXZ);
     return(_areaLod > -1);
 }