void Start() { m_lastStaged = m_staged; m_waves = new WaveSpectrumCPU(m_fourierGridSize, m_windSpeed, m_waveAmp, m_inverseWaveAge, m_ansio, m_gridSizes); m_waves.SimulateWaves(Time.realtimeSinceStartup); CreateFresnelLookUp(); if (m_resolution * m_resolution >= 65000 || m_useMaxResolution) { m_resolution = (int)Mathf.Sqrt(65000); if (!m_useMaxResolution) { Debug.Log("Ocean::Start - Grid resolution set to high. Setting resolution to the maxium allowed(" + m_resolution.ToString() + ")"); } } if (m_bias < 1.0f) { m_bias = 1.0f; Debug.Log("Ocean::Start - bias must not be less than 1, changing to 1"); } Mesh mesh = CreateRadialGrid(m_resolution, m_resolution); float far = Camera.main.farClipPlane; m_grid = new GameObject("Ocean Grid"); m_grid.AddComponent <MeshFilter>(); m_grid.AddComponent <MeshRenderer>(); m_grid.renderer.material = m_oceanMat; m_grid.GetComponent <MeshFilter>().mesh = mesh; m_grid.transform.localScale = new Vector3(far, 1, far); //Make radial grid have a radius equal to far plane m_gridWireframe = new GameObject("Ocean Grid Wireframe"); m_gridWireframe.AddComponent <MeshFilter>(); m_gridWireframe.AddComponent <MeshRenderer>(); m_gridWireframe.renderer.material = m_wireframeMat; m_gridWireframe.GetComponent <MeshFilter>().mesh = mesh; m_gridWireframe.transform.localScale = new Vector3(far, 1, far); m_gridWireframe.layer = 8; m_oceanMat.SetTexture("_FresnelLookUp", m_fresnelLookUp); m_oceanMat.SetVector("_GridSizes", m_waves.GetGridSizes()); m_oceanMat.SetFloat("_MaxLod", m_waves.GetMipMapLevels()); m_wireframeMat.SetVector("_GridSizes", m_waves.GetGridSizes()); m_wireframeMat.SetFloat("_MaxLod", m_waves.GetMipMapLevels()); }
void Update() { //If the option to uses staging is enable when playing the current stage in the WavesSpectrumCPU object needs to be reset if (m_lastStaged != m_staged) { m_waves.ResetStage(); } if (m_staged) { m_waves.SimulateWavesStaged(Time.realtimeSinceStartup); } else { m_waves.SimulateWaves(Time.realtimeSinceStartup); } //Update shader values that may change every frame m_oceanMat.SetTexture("_Map0", m_waves.GetMap0()); m_oceanMat.SetTexture("_Map1", m_waves.GetMap1()); m_oceanMat.SetTexture("_Map2", m_waves.GetMap2()); m_oceanMat.SetVector("_SunDir", m_sun.transform.forward * -1.0f); m_oceanMat.SetVector("_SunColor", m_sun.GetComponent <Light>().light.color); m_oceanMat.SetFloat("_LodFadeDist", m_lodFadeDist); m_wireframeMat.SetTexture("_Map0", m_waves.GetMap0()); m_wireframeMat.SetFloat("_LodFadeDist", m_lodFadeDist); //This makes sure the grid is always centered were the player is Vector3 pos = Camera.main.transform.position; pos.y = m_seaLevel; m_grid.transform.localPosition = pos; m_gridWireframe.transform.localPosition = pos; }
void Start() { m_lastStaged = m_staged; m_waves = new WaveSpectrumCPU(m_fourierGridSize, m_windSpeed, m_waveAmp, m_inverseWaveAge, m_ansio, m_gridSizes); m_waves.SimulateWaves(Time.realtimeSinceStartup); CreateFresnelLookUp(); if(m_resolution*m_resolution >= 65000 || m_useMaxResolution) { m_resolution = (int)Mathf.Sqrt(65000); if(!m_useMaxResolution) Debug.Log("Ocean::Start - Grid resolution set to high. Setting resolution to the maxium allowed(" + m_resolution.ToString() + ")" ); } if(m_bias < 1.0f) { m_bias = 1.0f; Debug.Log("Ocean::Start - bias must not be less than 1, changing to 1"); } Mesh mesh = CreateRadialGrid(m_resolution, m_resolution); float far = Camera.main.farClipPlane; m_grid = new GameObject("Ocean Grid"); m_grid.AddComponent<MeshFilter>(); m_grid.AddComponent<MeshRenderer>(); m_grid.renderer.material = m_oceanMat; m_grid.GetComponent<MeshFilter>().mesh = mesh; m_grid.transform.localScale = new Vector3(far,1,far); //Make radial grid have a radius equal to far plane m_gridWireframe = new GameObject("Ocean Grid Wireframe"); m_gridWireframe.AddComponent<MeshFilter>(); m_gridWireframe.AddComponent<MeshRenderer>(); m_gridWireframe.renderer.material = m_wireframeMat; m_gridWireframe.GetComponent<MeshFilter>().mesh = mesh; m_gridWireframe.transform.localScale = new Vector3(far,1,far); m_gridWireframe.layer = 8; m_oceanMat.SetTexture("_FresnelLookUp", m_fresnelLookUp); m_oceanMat.SetVector("_GridSizes", m_waves.GetGridSizes()); m_oceanMat.SetFloat("_MaxLod", m_waves.GetMipMapLevels()); m_wireframeMat.SetVector("_GridSizes", m_waves.GetGridSizes()); m_wireframeMat.SetFloat("_MaxLod", m_waves.GetMipMapLevels()); }