public WaveQueryTask(WaveSpectrumBase spectrum, float level, Vector3 offset, IEnumerable <WaveQuery> querys, Action <IEnumerable <WaveQuery> > callBack) : base(true)
        {
            IDisplacementBuffer buffer = spectrum.DisplacementBuffer;

            buffer.CopyAndCreateDisplacements(out m_displacements);

            m_querys   = querys;
            m_callBack = callBack;
            m_enabled  = buffer.EnabledBuffers();
            m_level    = level;

            Vector4 invGridSizes = new Vector4();

            invGridSizes.x = 1.0f / (spectrum.GridSizes.x * spectrum.GridScale);
            invGridSizes.y = 1.0f / (spectrum.GridSizes.y * spectrum.GridScale);
            invGridSizes.z = 1.0f / (spectrum.GridSizes.z * spectrum.GridScale);
            invGridSizes.w = 1.0f / (spectrum.GridSizes.w * spectrum.GridScale);

            m_scaling = new QueryGridScaling();
            m_scaling.invGridSizes = invGridSizes;
            m_scaling.choppyness   = spectrum.Choppyness * spectrum.GridScale;
            m_scaling.scaleY       = spectrum.GridScale;
            m_scaling.offset       = offset;
            //tmp buffer to reduce memory allocations.
            m_scaling.tmp = new float[QueryDisplacements.CHANNELS];
        }
Exemplo n.º 2
0
        public override void QueryWaves(WaveQuery query)
        {
            if (!base.enabled)
            {
                return;
            }
            IDisplacementBuffer displacementBuffer = this.DisplacementBuffer;

            if (displacementBuffer == null)
            {
                return;
            }
            if (this.disableReadBack && displacementBuffer.IsGPU)
            {
                return;
            }
            if (query.mode != QUERY_MODE.DISPLACEMENT && query.mode != QUERY_MODE.POSITION)
            {
                return;
            }
            if (!query.sampleSpectrum[0] && !query.sampleSpectrum[1] && !query.sampleSpectrum[2] && !query.sampleSpectrum[3])
            {
                return;
            }
            displacementBuffer.QueryWaves(query, this.m_queryScaling);
        }
Exemplo n.º 3
0
        public override void Reset()
        {
            base.Reset();
            this.m_choppyness = this.m_spectrum.Choppyness;
            this.m_gridScale  = new Vector2(this.m_spectrum.GridScale, this.m_spectrum.GridScale);
            IDisplacementBuffer displacementBuffer = this.m_spectrum.DisplacementBuffer;

            displacementBuffer.CopyDisplacements(this.m_displacements);
        }
Exemplo n.º 4
0
        public FindRangeTask(WaveSpectrumBase spectrum) : base(true)
        {
            this.m_spectrum   = spectrum;
            this.m_choppyness = spectrum.Choppyness;
            this.m_gridScale  = new Vector2(spectrum.GridScale, spectrum.GridScale);
            IDisplacementBuffer displacementBuffer = spectrum.DisplacementBuffer;

            displacementBuffer.CopyAndCreateDisplacements(out this.m_displacements);
        }
Exemplo n.º 5
0
        public FindRangeTask(WaveSpectrum spectrum) : base(true)
        {
            m_spectrum   = spectrum;
            m_choppyness = spectrum.Choppyness;
            m_gridScale  = new Vector2(spectrum.gridScale, spectrum.gridScale);

            IDisplacementBuffer buffer = spectrum.DisplacementBuffer;

            buffer.CopyAndCreateDisplacements(out m_displacements);
        }
Exemplo n.º 6
0
        public override void Reset()
        {
            base.Reset();

            m_choppyness = m_spectrum.Choppyness;
            m_gridScale  = new Vector2(m_spectrum.gridScale, m_spectrum.gridScale);

            IDisplacementBuffer buffer = m_spectrum.DisplacementBuffer;

            buffer.CopyDisplacements(m_displacements);
        }
Exemplo n.º 7
0
        public void QueryWavesAsync(IEnumerable <WaveQuery> querys, Action <IEnumerable <WaveQuery> > callBack)
        {
            IDisplacementBuffer displacementBuffer = this.Spectrum.DisplacementBuffer;

            if (base.enabled && this.Spectrum != null && displacementBuffer != null && (!displacementBuffer.IsGPU || !this.Spectrum.DisableReadBack))
            {
                WaveQueryTask task = new WaveQueryTask(this.Spectrum, this.level, this.PositionOffset, querys, callBack);
                this.m_scheduler.Run(task);
            }
            else
            {
                foreach (WaveQuery waveQuery in querys)
                {
                    waveQuery.result.Clear();
                    waveQuery.result.height = this.level;
                }
                callBack(querys);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// The task needs to be reset before being scheduled.
        /// This will update the settings in case wave conditions have changed.
        /// </summary>
        public void Reset(WaveSpectrum spectrum, Vector3 offset, float level)
        {
            //Dont forget to reset base.
            base.Reset();

            IsScheduled = false;

            //If the spectrum component is added and enabled then take a copy of the
            //displacement data and update scaling settings for the waves.
            if (spectrum != null && spectrum.DisplacementBuffer != null)
            {
                IDisplacementBuffer buffer = spectrum.DisplacementBuffer;

                if (Displacements == null || BufferSize != buffer.Size)
                {
                    buffer.CopyAndCreateDisplacements(out Displacements);
                    BufferSize = buffer.Size;
                }
                else
                {
                    buffer.CopyDisplacements(Displacements);
                }

                EnabledBuffers = buffer.EnabledBuffers();

                Vector4 invGridSizes = new Vector4();
                invGridSizes.x = 1.0f / (spectrum.GridSizes.x * spectrum.gridScale);
                invGridSizes.y = 1.0f / (spectrum.GridSizes.y * spectrum.gridScale);
                invGridSizes.z = 1.0f / (spectrum.GridSizes.z * spectrum.gridScale);
                invGridSizes.w = 1.0f / (spectrum.GridSizes.w * spectrum.gridScale);

                Scaling.invGridSizes = invGridSizes;
                Scaling.choppyness   = spectrum.Choppyness * spectrum.gridScale;
                Scaling.scaleY       = spectrum.gridScale;
                Scaling.offset       = offset;
                Scaling.numGrids     = spectrum.numberOfGrids;
            }
        }
        /// <summary>
        /// Query the waves at world position xz
        /// with a batch of querys.
        /// This will run the querys on a separate thread.
        /// The call back function will be called when the
        /// batch has finished.
        /// Make sure the batch has finished before resubmitting it.
        ///
        /// NOTE - Currently will not sample the wave overlays.
        ///
        /// </summary>
        public void QueryWavesAsync(IEnumerable <WaveQuery> querys, Action <IEnumerable <WaveQuery> > callBack)
        {
            IDisplacementBuffer buffer = Spectrum.DisplacementBuffer;

            if (enabled && Spectrum != null && buffer != null && !(buffer.IsGPU && Spectrum.DisableReadBack))
            {
                WaveQueryTask task = new WaveQueryTask(Spectrum, level, PositionOffset, querys, callBack);
                m_scheduler.Run(task);
            }
            else
            {
                //There is no spectrum to query or its displacement
                //buffer does not support querys.
                //Clear results and call callback.
                foreach (WaveQuery query in querys)
                {
                    query.result.Clear();
                    query.result.height = level;
                }

                callBack(querys);
            }
        }