Example #1
0
        public override void Init(ProlandManager manager)
        {
            base.Init(manager);

            m_initSpectrumMat     = new Material(ShaderReplacer.Instance.LoadedShaders[("Proland/Ocean/InitSpectrum")]);
            m_initDisplacementMat = new Material(ShaderReplacer.Instance.LoadedShaders[("Proland/Ocean/InitDisplacement")]);

            m_fourierGridSize = Scatterer.Instance.mainSettings.m_fourierGridSize;

            if (m_fourierGridSize > 256)
            {
                Utils.LogDebug("Proland::OceanFFT::Start	- fourier grid size must not be greater than 256, changing to 256");
                m_fourierGridSize = 256;
            }

            if (!Mathf.IsPowerOfTwo(m_fourierGridSize))
            {
                Utils.LogDebug("Proland::OceanFFT::Start	- fourier grid size must be pow2 number, changing to nearest pow2 number");
                m_fourierGridSize = Mathf.NextPowerOfTwo(m_fourierGridSize);
            }

            m_fsize  = (float)m_fourierGridSize;
            m_offset = new Vector4(1.0f + 0.5f / m_fsize, 1.0f + 0.5f / m_fsize, 0, 0);


            float factor = 2.0f * Mathf.PI * m_fsize;

            m_inverseGridSizes = new Vector4(factor / m_gridSizes.x, factor / m_gridSizes.y, factor / m_gridSizes.z, factor / m_gridSizes.w);


            m_fourier = new FourierGPU(m_fourierGridSize);

            m_writeFloat = new WriteFloat(m_fourierGridSize, m_fourierGridSize);

            //Create the data needed to make the waves each frame
            CreateRenderTextures();
            GenerateWavesSpectrum();
            CreateWTable();

            m_initSpectrumMat.SetTexture(ShaderProperties._Spectrum01_PROPERTY, m_spectrum01);
            m_initSpectrumMat.SetTexture(ShaderProperties._Spectrum23_PROPERTY, m_spectrum23);
            m_initSpectrumMat.SetTexture(ShaderProperties._WTable_PROPERTY, m_WTable);
            m_initSpectrumMat.SetVector(ShaderProperties._Offset_PROPERTY, m_offset);
            m_initSpectrumMat.SetVector(ShaderProperties._InverseGridSizes_PROPERTY, m_inverseGridSizes);

            m_initDisplacementMat.SetVector(ShaderProperties._InverseGridSizes_PROPERTY, m_inverseGridSizes);
        }
Example #2
0
		// Use this for initialization
		public override void Start()
			//		public void Start () 
		{
			base.Start();
			
			
			m_initSpectrumMat = new Material(ShaderTool.GetMatFromShader2("CompiledInitSpectrum.shader"));;
			m_initDisplacementMat = new Material(ShaderTool.GetMatFromShader2("CompiledInitDisplacement.shader"));;
			
			
			if (m_fourierGridSize > 256) {
				Debug.Log("Proland::OceanFFT::Start	- fourier grid size must not be greater than 256, changing to 256");
				m_fourierGridSize = 256;
			}
			
			if (!Mathf.IsPowerOfTwo(m_fourierGridSize)) {
				Debug.Log("Proland::OceanFFT::Start	- fourier grid size must be pow2 number, changing to nearest pow2 number");
				m_fourierGridSize = Mathf.NextPowerOfTwo(m_fourierGridSize);
			}
			
			m_fsize = (float) m_fourierGridSize;
			m_offset = new Vector4(1.0f + 0.5f / m_fsize, 1.0f + 0.5f / m_fsize, 0, 0);
			
			
			float factor = 2.0f * Mathf.PI * m_fsize;
			m_inverseGridSizes = new Vector4(factor / m_gridSizes.x, factor / m_gridSizes.y, factor / m_gridSizes.z, factor / m_gridSizes.w);
			
			
			m_fourier = new FourierGPU(m_fourierGridSize);
			
			m_writeFloat = new WriteFloat(m_fourierGridSize, m_fourierGridSize);


//#if CPUmode
			if (m_manager.GetCore ().craft_WaveInteractions)
			{
				m_CPUfourier = new FourierCPU (m_fourierGridSize);
				
				m_passes = (int)(Mathf.Log (m_fsize) / Mathf.Log (2.0f));
				ComputeButterflyLookupTable ();
				
				m_CPUfourier.m_butterflyLookupTable = m_butterflyLookupTable;
				
				m_fourierBuffer0vector = new Vector4[2, m_fourierGridSize * m_fourierGridSize];
				m_fourierBuffer0vectorResults = new Vector4[2, m_fourierGridSize * m_fourierGridSize];
				
				
				m_fourierBuffer1vector = new Vector4[2, m_fourierGridSize * m_fourierGridSize];
				m_fourierBuffer2vector = new Vector4[2, m_fourierGridSize * m_fourierGridSize];
				
				m_fourierBuffer3vector = new Vector4[2, m_fourierGridSize * m_fourierGridSize];
				m_fourierBuffer4vector = new Vector4[2, m_fourierGridSize * m_fourierGridSize];
				m_fourierBuffer3vectorResults = new Vector4[2, m_fourierGridSize * m_fourierGridSize];
				m_fourierBuffer4vectorResults = new Vector4[2, m_fourierGridSize * m_fourierGridSize];
			}
//#endif			


			//Create the data needed to make the waves each frame
			CreateRenderTextures();
			GenerateWavesSpectrum();
			CreateWTable();
			
			m_initSpectrumMat.SetTexture("_Spectrum01", m_spectrum01);
			m_initSpectrumMat.SetTexture("_Spectrum23", m_spectrum23);
			m_initSpectrumMat.SetTexture("_WTable", m_WTable);
			m_initSpectrumMat.SetVector("_Offset", m_offset);
			m_initSpectrumMat.SetVector("_InverseGridSizes", m_inverseGridSizes);
			
			m_initDisplacementMat.SetVector("_InverseGridSizes", m_inverseGridSizes);

//#if CPUmode
			if (m_manager.GetCore ().craft_WaveInteractions)
			{
				CreateWTableForCPU ();
			}
			
//#endif
			
		}
Example #3
0
        //        public void Start ()
        // Use this for initialization
        public override void Start()
        {
            base.Start();

            m_initSpectrumMat=new Material(ShaderTool.GetMatFromShader2("CompiledInitSpectrum.shader"));;
            m_initDisplacementMat=new Material(ShaderTool.GetMatFromShader2("CompiledinitDisplacement.shader"));;

            if(m_fourierGridSize > 256)
            {
                Debug.Log("Proland::OceanFFT::Start	- fourier grid size must not be greater than 256, changing to 256");
                m_fourierGridSize = 256;
            }

            if(!Mathf.IsPowerOfTwo(m_fourierGridSize))
            {
                Debug.Log("Proland::OceanFFT::Start	- fourier grid size must be pow2 number, changing to nearest pow2 number");
                m_fourierGridSize = Mathf.NextPowerOfTwo(m_fourierGridSize);
            }

            m_fsize = (float)m_fourierGridSize;
            m_offset = new Vector4(1.0f + 0.5f / m_fsize, 1.0f + 0.5f / m_fsize, 0, 0);

            float factor = 2.0f * Mathf.PI * m_fsize;
            m_inverseGridSizes = new Vector4(factor/m_gridSizes.x, factor/m_gridSizes.y, factor/m_gridSizes.z, factor/m_gridSizes.w);

            m_fourier = new FourierGPU(m_fourierGridSize);

            m_writeFloat = new WriteFloat(m_fourierGridSize, m_fourierGridSize);

            //Create the data needed to make the waves each frame
            CreateRenderTextures();
            GenerateWavesSpectrum();
            CreateWTable();

            m_initSpectrumMat.SetTexture("_Spectrum01", m_spectrum01);
            m_initSpectrumMat.SetTexture("_Spectrum23", m_spectrum23);
            m_initSpectrumMat.SetTexture("_WTable", m_WTable);
            m_initSpectrumMat.SetVector("_Offset", m_offset);
            m_initSpectrumMat.SetVector("_InverseGridSizes", m_inverseGridSizes);

            m_initDisplacementMat.SetVector("_InverseGridSizes", m_inverseGridSizes);
        }