Beispiel #1
0
    void Setup()
    {
        IsSetup = true;

        m_waves = new WaveSpectrumGPU(m_fourierGridSize, m_windSpeed, m_waveAmp, m_inverseWaveAge, m_ansio, m_gridSizes);

        CreateFresnelLookUp();

        if (m_resolution * m_resolution >= 65000 || m_useMaxResolution)
        {
            m_resolution = (int)Mathf.Sqrt(65000);

            if (!m_useMaxResolution)
            {
                Debug.Log("Warning - Grid resolution set too 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 = MainCamera.farClipPlane;


        m_grid = new GameObject("Ocean Grid");
        m_grid.transform.localPosition = new Vector3(0, m_seaLevel / 2.0f, 0);
        m_grid.AddComponent <MeshFilter>();
        m_grid.AddComponent <MeshRenderer>();
        m_grid.GetComponent <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 Wireframe Grid");
        m_gridWireframe.AddComponent <MeshFilter>();
        MeshRenderer mr = m_gridWireframe.AddComponent <MeshRenderer>();

        mr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
        //m_gridWireframe.GetComponent<Renderer>().material = m_wireframeMat;
        m_gridWireframe.GetComponent <MeshFilter>().mesh = mesh;
        m_gridWireframe.transform.localScale             = new Vector3(far, 1, far);
        m_gridWireframe.layer = 8;
        m_gridWireframe.SetActive(false);

        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());
    }
Beispiel #2
0
	void Start () 
	{
		
		WaveSpectrumGPU.Param param = new WaveSpectrumGPU.Param();
		
		param.size = m_fourierGridSize;
		param.windSpeed = m_windSpeed;
		param.waveAmp = m_waveAmp;
		param.omega = m_inverseWaveAge;
		param.ansio = m_ansio;
		param.foamAnsio = m_foamAnsio;
		param.gridSizes = m_gridSizes;
		param.choppyness = m_choppyness;
		param.varianceShader = m_varianceShader;
		param.writeData = m_writeData;
		
		m_waves = new WaveSpectrumGPU(param);
		
		if(m_resolution*m_resolution >= 65000 || m_useMaxResolution)
		{
			m_resolution = (int)Mathf.Sqrt(65000);
			
			if(!m_useMaxResolution) 
				Debug.Log("Warning - 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 Wireframe Grid");
		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("_Variance", m_waves.GetVariance());
		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());
	}
Beispiel #3
0
 public Vector4 GetGridSizes()
 {
     return(m_waves.GetGridSizes());
 }