protected override void SetAdditionalSimParams(int lodIdx, PropertyWrapperMaterial simMaterial) { base.SetAdditionalSimParams(lodIdx, simMaterial); simMaterial.SetFloat(sp_Damping, Settings._damping); simMaterial.SetFloat(sp_Gravity, OceanRenderer.Instance.Gravity); float laplacianKernelAngle = _rotateLaplacian ? Mathf.PI * 2f * Random.value : 0f; simMaterial.SetVector(sp_LaplacianAxisX, new Vector2(Mathf.Cos(laplacianKernelAngle), Mathf.Sin(laplacianKernelAngle))); // assign sea floor depth - to slot 1 current frame data. minor bug here - this depth will actually be from the previous frame, // because the depth is scheduled to render just before the animated waves, and this sim happens before animated waves. if (OceanRenderer.Instance._lodDataSeaDepths) { OceanRenderer.Instance._lodDataSeaDepths.BindResultData(lodIdx, 1, simMaterial); } else { LodDataMgrSeaFloorDepth.BindNull(1, simMaterial); } if (OceanRenderer.Instance._lodDataFlow) { OceanRenderer.Instance._lodDataFlow.BindResultData(lodIdx, 1, simMaterial); } else { LodDataMgrFlow.BindNull(1, simMaterial); } }
/// <summary> /// More complicated than one would hope - loops over each component and assigns to a Gerstner batch which will render to a LOD. /// the camera WL range does not always match the octave WL range (because the vertices per wave is not constrained to powers of /// 2, unfortunately), so i cant easily just loop over octaves. also any WLs that either go to the last WDC, or don't fit in the last /// WDC, are rendered into both the last and second-to-last WDCs, in order to transition them smoothly without pops in all scenarios. /// </summary> void LateUpdate() { if (OceanRenderer.Instance == null) { return; } int componentIdx = 0; // seek forward to first wavelength that is big enough to render into current LODs float minWl = OceanRenderer.Instance._lods[0].MaxWavelength() / 2f; while (_wavelengths[componentIdx] < minWl && componentIdx < _wavelengths.Length) { componentIdx++; } // batch together appropriate wavelengths for each lod, except the last lod, which are handled separately below for (int lod = 0; lod < OceanRenderer.Instance.CurrentLodCount - 1; lod++, minWl *= 2f) { int startCompIdx = componentIdx; while (componentIdx < _wavelengths.Length && _wavelengths[componentIdx] < 2f * minWl) { componentIdx++; } _drawLOD[lod] = UpdateBatch(lod, startCompIdx, componentIdx, _materials[lod]) > 0; } // the last batch handles waves for the last lod, and waves that did not fit in the last lod _drawLOD[OceanRenderer.Instance.CurrentLodCount - 1] = UpdateBatch(OceanRenderer.Instance.CurrentLodCount - 1, componentIdx, _wavelengths.Length, _materials[OceanRenderer.Instance.CurrentLodCount - 1]) > 0; _drawLODTransitionWaves = UpdateBatch(OceanRenderer.Instance.CurrentLodCount - 2, componentIdx, _wavelengths.Length, _materialBigWaveTransition) > 0; if (_directTowardsPoint) { for (int lod = 0; lod < OceanRenderer.Instance.CurrentLodCount; lod++) { _materials[lod].SetVector(sp_TargetPointData, new Vector4(_pointPositionXZ.x, _pointPositionXZ.y, _pointRadii.x, _pointRadii.y)); } _materialBigWaveTransition.SetVector(sp_TargetPointData, new Vector4(_pointPositionXZ.x, _pointPositionXZ.y, _pointRadii.x, _pointRadii.y)); } }
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) { var pwm = new PropertyWrapperMaterial(_mat); var wdcs = OceanRenderer.Instance.Builder._shapeWDCs; wdcs[idx].ApplyMaterialParams(0, pwm); int idx1 = Mathf.Min(idx + 1, wdcs.Length - 1); wdcs[idx1].ApplyMaterialParams(1, pwm); // 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; pwm.SetVector("_InstanceData", new Vector4(meshScaleLerp, farNormalsWeight, idx)); } }