Exemplo n.º 1
0
        //public bool HasAlpha => !(Min.Alpha == 1.0f && Max.Alpha == 1.0f);

        internal float GetStats(ITexture texture, LayerMipmapRange lm, StatisticsShader statShader, ReduceShader redShader, bool normalize)
        {
            Debug.Assert(lm.IsSingleMipmap);

            // obtain a buffer that is big enough
            int numElements = texture.Size.GetMip(lm.FirstMipmap).Product;

            if (lm.AllLayer)
            {
                numElements *= texture.LayerMipmap.Layers;
            }

            // allocate buffer that is big enough
            GetBuffer(numElements);

            // copy all values into buffer
            statShader.CopyToBuffer(texture, buffer, lm);

            // execute reduce
            redShader.Run(buffer, numElements);

            shared.Download.CopyFrom(buffer, sizeof(float));

            var res = shared.Download.GetData <float>();

            if (normalize)
            {
                res /= numElements;
            }
            return(res);
        }
Exemplo n.º 2
0
        //public bool HasAlpha => !(Min.Alpha == 1.0f && Max.Alpha == 1.0f);

        internal float GetStats(ITexture texture, int layer, int mipmap, StatisticsShader statShader, ReduceShader redShader, bool normalize)
        {
            // obtain a buffer that is big enough
            int numElements = texture.Size.GetMip(mipmap).Product;

            if (layer == -1)
            {
                numElements *= texture.NumLayers;
            }

            if (buffer == null || buffer.ElementCount < numElements)
            {
                buffer?.Dispose();
                buffer = new GpuBuffer(4, numElements);
            }

            // copy all values into buffer
            statShader.CopyToBuffer(texture, buffer, layer, mipmap);

            // execute reduce
            redShader.Run(buffer, numElements);

            shared.Download.CopyFrom(buffer);

            var res = shared.Download.GetData <float>();

            if (normalize)
            {
                res /= numElements;
            }
            return(res);
        }
Exemplo n.º 3
0
 internal DefaultStatisticsType(StatisticsShader shader, ITexture texture, StatisticsModel parent, LayerMipmapRange lm)
 {
     this.shader  = shader;
     this.texture = texture;
     this.parent  = parent;
     this.lm      = lm;
     minValue     = null;
     maxValue     = null;
     avgValue     = null;
 }
Exemplo n.º 4
0
 internal DefaultStatisticsType(StatisticsShader shader, ITexture texture, StatisticsModel parent, int layer, int mipmap)
 {
     this.shader  = shader;
     this.texture = texture;
     this.parent  = parent;
     this.layer   = layer;
     this.mipmap  = mipmap;
     minValue     = null;
     maxValue     = null;
     avgValue     = null;
 }
Exemplo n.º 5
0
 public SSIMModel(Models models)
 {
     this.models             = models;
     this.copyToBufferShader = new StatisticsShader(models.SharedModel.Upload, StatisticsShader.RedValue);
 }