Example #1
0
File: H.cs Project: wyyayy/FftUnity
        public H(H0 H0, W W)
        {
            this.H0 = H0;
            this.W  = W;

            N       = H0.N;
            this._h = new float[2 * N * N];
            _Jump(0f);
        }
Example #2
0
File: H.cs Project: wyyayy/FftUnity
        private void _Jump(float t)
        {
            _t = t;
            for (var y = 0; y < N; y++)
            {
                for (var x = 0; x < N; x++)
                {
                    var theta = W[x, y] * t;
                    var c     = Mathf.Cos(theta);
                    var s     = Mathf.Sin(theta);
                    var hp    = H0[x, y];
                    var hm    = H0.ConjMinusK(x, y);

                    var i = 2 * (x + y * N);
                    _h[i]     = (hp.x + hm.x) * c + (hm.y - hp.y) * s;
                    _h[i + 1] = (hp.y + hm.y) * c + (hp.x - hm.x) * s;
                }
            }
        }
Example #3
0
        void Start()
        {
            Random.seed = randomSeed;
            targetCam.depthTextureMode |= DepthTextureMode.Depth;
            if (view == null)
            {
                view = targetCam.transform;
            }
            var winSize = new Vector2(300f, 100f);

            _guiWindow = new Rect(Screen.width - winSize.x, Screen.height - winSize.y, winSize.x, winSize.y);

            _fft = new FFT(fft);

            var k        = new K(N, oceanSize);
            var phillips = new Phillips(k, windVelocity.magnitude, windVelocity.normalized);

            _h0 = new H0(phillips);
            _w  = new W(k);

            _nGroups = N / OceanConst.NTHREADS_IN_GROUP;

            var h0BufData = new Vector4[N * N];
            var wBufData  = new Vector4[N * N];

            for (var y = 0; y < N; y++)
            {
                for (var x = 0; x < N; x++)
                {
                    var i  = x + y * N;
                    var hp = _h0[x, y];
                    var hm = _h0.ConjMinusK(x, y);
                    h0BufData[i] = new Vector4(hp.x, hp.y, hm.x, hm.y);
                    wBufData[i]  = new Vector4(_w[x, y], 0f, 0f, 0f);
                }
            }
            _h0Buf = new ComputeBuffer(h0BufData.Length, Marshal.SizeOf(h0BufData[0]));
            _wBuf  = new ComputeBuffer(wBufData.Length, Marshal.SizeOf(wBufData[0]));
            _h0Buf.SetData(h0BufData);
            _wBuf.SetData(wBufData);

            _h0Tex                   = new RenderTexture(N, N, 0, RenderTextureFormat.ARGBFloat);
            _wTex                    = new RenderTexture(N, N, 0, RenderTextureFormat.ARGBFloat);
            _hTex                    = new RenderTexture(N, N, 0, RenderTextureFormat.RGFloat);
            _nTex                    = new RenderTexture(N, N, 0, RenderTextureFormat.ARGBFloat);
            _h0Tex.filterMode        = _wTex.filterMode = _hTex.filterMode = _nTex.filterMode = FilterMode.Bilinear;
            _h0Tex.wrapMode          = _wTex.wrapMode = _hTex.wrapMode = _nTex.wrapMode = TextureWrapMode.Repeat;
            _h0Tex.enableRandomWrite = _wTex.enableRandomWrite = _hTex.enableRandomWrite = _nTex.enableRandomWrite = true;
            _h0Tex.Create();
            _wTex.Create();
            _hTex.Create();
            _nTex.Create();

            ocean.SetInt(OceanConst.SHADER_N, N);

            ocean.SetBuffer(OceanConst.KERNEL_BUF2TEX, OceanConst.SHADER_COPY_BUF_IN, _h0Buf);
            ocean.SetTexture(OceanConst.KERNEL_BUF2TEX, OceanConst.SHADER_COPY_TEX_OUT, _h0Tex);
            _h0Tex.DiscardContents();
            ocean.Dispatch(OceanConst.KERNEL_BUF2TEX, _nGroups, _nGroups, 1);

            ocean.SetBuffer(OceanConst.KERNEL_BUF2TEX, OceanConst.SHADER_COPY_BUF_IN, _wBuf);
            ocean.SetTexture(OceanConst.KERNEL_BUF2TEX, OceanConst.SHADER_COPY_TEX_OUT, _wTex);
            _wTex.DiscardContents();
            ocean.Dispatch(OceanConst.KERNEL_BUF2TEX, _nGroups, _nGroups, 1);

            _renderers = GetComponentsInChildren <Renderer> ();
            _block     = new MaterialPropertyBlock();
        }