private void LateUpdate() { // find which lod this object is overlapping var rect = new Rect(transform.position.x, transform.position.z, 0f, 0f); var idx = WaveDataCam.SuggestCollisionLOD(rect); if (idx > -1) { if (_mpb == null) { _mpb = new MaterialPropertyBlock(); } _rend.GetPropertyBlock(_mpb); var wdcs = OceanRenderer.Instance.Builder._shapeWDCs; wdcs[idx].ApplyMaterialParams(0, _mpb); int idx1 = Mathf.Min(idx + 1, wdcs.Length - 1); wdcs[idx1].ApplyMaterialParams(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 == wdcs.Length - 1 && OceanRenderer.Instance.ScaleCouldDecrease; float farNormalsWeight = needToBlendOutNormals ? OceanRenderer.Instance.ViewerAltitudeLevelAlpha : 1f; _mpb.SetVector("_InstanceData", new Vector4(meshScaleLerp, farNormalsWeight, idx)); _rend.SetPropertyBlock(_mpb); } }
public bool SampleDisplacement(ref Vector3 worldPos, ref Vector3 displacement) { int lod = WaveDataCam.SuggestCollisionLOD(new Rect(worldPos.x, worldPos.z, 0f, 0f), 0f); if (lod == -1) { return(false); } return(OceanRenderer.Instance.Builder._shapeWDCs[lod].CollData.SampleDisplacement(ref worldPos, ref displacement)); }
public bool SampleHeight(ref Vector3 worldPos, ref float height) { int lod = WaveDataCam.SuggestCollisionLOD(new Rect(worldPos.x, worldPos.z, 0f, 0f), 0f); if (lod == -1) { return(false); } height = OceanRenderer.Instance.Builder._shapeWDCs[lod].CollData.GetHeight(ref worldPos); return(true); }
public void PrewarmForSamplingArea(Rect areaXZ, float minSpatialLength) { _areaLod = WaveDataCam.SuggestCollisionLOD(areaXZ, minSpatialLength); }
public void PrewarmForSamplingArea(Rect areaXZ) { _areaLod = WaveDataCam.SuggestCollisionLOD(areaXZ); }