예제 #1
0
파일: NPFrame2.cs 프로젝트: miberen/P7-VGIS
    public void GenerateSynthesis(string name, RenderTexture customTexture, SynthesisMode synthMode = SynthesisMode.BiQuadBSpline, int targetLevel = 0)
    {
        // Check if a synthesis with the supplied name exists, if it does not make it and fill it out.
        if (!_synthDic.ContainsKey(name))
        {
            int size = NextHigherPow2(new Vector2(customTexture.width, customTexture.height));
            if (!_pow2S.Contains(customTexture.width) || !_pow2S.Contains(customTexture.height))
            {
                _synthDic.Add(name, new Synthesis(_pow2S.IndexOf(NextHigherPow2(new Vector2(Screen.width, Screen.height)) - _pow2S.IndexOf(size))));

                // Fill the list in synthesis.
                for (int i = 0; i < targetLevel; i++)
                {
                    _synthDic[name].Pyramid.Add(new RenderTexture(_pow2S[_pow2S.IndexOf(size) - i], _pow2S[_pow2S.IndexOf(size) - i], 0, _textureFormat, RenderTextureReadWrite.Linear));
                    _synthDic[name][i].enableRandomWrite = true;
                    _synthDic[name][i].filterMode = _filterMode;
                    _synthDic[name][i].Create();
                }

                MakePow2(customTexture, _synthDic[name][0]);
            }
            else
            {
                _synthDic.Add(name, new Synthesis(_pow2S.IndexOf(NextHigherPow2(new Vector2(Screen.width, Screen.height)) - _pow2S.IndexOf(size))));

                // Fill the list in synthesis.
                for (int i = 0; i < targetLevel; i++)
                {
                    //_synthDic[name].Pyramid.Add(new RenderTexture(_pow2S[_pow2S.IndexOf(size) - i], _pow2S[_pow2S.IndexOf(size) - i], 0, _textureFormat, RenderTextureReadWrite.Linear));
                    _synthDic[name][i].enableRandomWrite = true;
                    _synthDic[name][i].filterMode = _filterMode;
                    _synthDic[name][i].Create();
                }

            }

            _synthesiseIsInit = true;

            SynthesizeCall(_synthDic[name], targetLevel, synthMode);
        }
        // If it does exist but the size is different or if the screen size has changed, delete the old one and make a new one with the right size.
        else if (_synthDic.ContainsKey(name) && (targetLevel != _synthDic[name].SourceLevel || !_synthesiseIsInit))
        {
            foreach (RenderTexture rT in _synthDic[name].Pyramid)
            {
                if (rT.IsCreated())
                {
                    rT.Release();
                }
            }
            _synthDic[name].Pyramid.Clear();

            for (int i = 0; i < targetLevel; i++)
            {
                _synthDic[name].Pyramid.Add(new RenderTexture(_analyzeList[targetLevel - 1 - i].width, _analyzeList[targetLevel - 1 - i].height, 0, _textureFormat, RenderTextureReadWrite.Linear));
                _synthDic[name][i].enableRandomWrite = true;
                _synthDic[name][i].filterMode = _filterMode;
                _synthDic[name][i].Create();
            }

            _synthDic[name].SetSourceLevel = targetLevel;
            _synthesiseIsInit = true;

            SynthesizeCall(_synthDic[name], targetLevel, synthMode);
        }
        // if everything is good, just do the call to generate the synthesis in the list.
        else
        {
            SynthesizeCall(_synthDic[name], targetLevel, synthMode);
        }
    }
예제 #2
0
파일: NPFrame2.cs 프로젝트: miberen/P7-VGIS
    /// <summary>
    /// Create synthesis in specified synthesis object.
    /// </summary>
    /// <param name="synth">The syntesis object to work on.</param>
    /// <param name="levels">From what level to generate the synthesis from.</param>
    /// <param name="synthMode">What kernel to use for synthesis.</param>
    private void SynthesizeCall(Synthesis synth, int levels = 0, SynthesisMode synthMode = SynthesisMode.BiQuadBSpline)
    {
        // Use default value if no value is set ( To be changed later to just synthesize all the way up if nothing else is specific)
        if (levels == 0) levels = _levels;

        int sampleCompensation = !_UseHigherPoT ? 1 : 0;
        //Debug.Log(sampleCompensation);

        // If it is the first level just copy over the top level analysis. (This could be optimized slightly by just directly using it from the analysis list)
        if (levels == 1)
        {
            _cSMain.SetTexture(_cSMain.FindKernel(GetEnumDescription(synthMode)), "source", _analyzeList[synth.SourceLevel - sampleCompensation]);
            _cSMain.SetTexture(_cSMain.FindKernel(GetEnumDescription(synthMode)), "dest", synth.Pyramid[0]);

            if (synth.Pyramid[0].width > 32 || synth.Pyramid[0].height > 32)
                _cSMain.Dispatch(_cSMain.FindKernel(GetEnumDescription(synthMode)), (int)Mathf.Ceil(_analyzeList[synth.SourceLevel - sampleCompensation].width / 32), (int)Mathf.Ceil(_analyzeList[synth.SourceLevel - sampleCompensation].height / 32), 1);
            else
                _cSMain.Dispatch(_cSMain.FindKernel(GetEnumDescription(synthMode)), 1, 1, 1);
        }
        else
        {
            for (int i = 0; i < levels; i++)
            {
                if (i == 0)
                {
                    _cSMain.SetTexture(_cSMain.FindKernel(GetEnumDescription(synthMode)), "source", _analyzeList[synth.SourceLevel - sampleCompensation]);
                    _cSMain.SetTexture(_cSMain.FindKernel(GetEnumDescription(synthMode)), "dest", synth.Pyramid[i]);

                    //Debug.Log("Source: " + _analyzeList[synth.SourceLevel - sampleCompensation].width + " Destination: " + synth.Pyramid[i].width);

                    _cSMain.Dispatch(_cSMain.FindKernel(GetEnumDescription(synthMode)), (int)Mathf.Ceil(_analyzeList[synth.SourceLevel - sampleCompensation].width / 32), (int)Mathf.Ceil(_analyzeList[synth.SourceLevel - sampleCompensation].height / 32), 1);
                }
                else
                {
                    _cSMain.SetTexture(_cSMain.FindKernel(GetEnumDescription(synthMode)), "source", synth.Pyramid[i-1]);
                    _cSMain.SetTexture(_cSMain.FindKernel(GetEnumDescription(synthMode)), "dest", synth.Pyramid[i]);

                    if (synth.Pyramid[i-1].width > 32 || synth.Pyramid[i-1].height > 32)
                        _cSMain.Dispatch(_cSMain.FindKernel(GetEnumDescription(synthMode)), (int)Mathf.Ceil(synth.Pyramid[i-1].width / 32), (int)Mathf.Ceil(synth.Pyramid[i-1].height / 32), 1);
                    else
                        _cSMain.Dispatch(_cSMain.FindKernel(GetEnumDescription(synthMode)), 1, 1, 1);
                }
            }
        }
    }
예제 #3
0
파일: NPFrame2.cs 프로젝트: miberen/P7-VGIS
    /// <summary>
    /// Generates a synthesis from a specified non-zero based source level of the analyzation pyramid. 
    /// </summary>
    /// <param name="sourceLevel"> The non-zero based analyzation level to synthesise from. ( This is also the amount of textures generated. If left empty, will synthesize from lowest level.</param>
    /// <param name="name"> Name of the synthesis, used to access it later.</param>
    /// <param name="synthMode">The filter to use for synthesising.</param>
    public void GenerateSynthesis(string name, SynthesisMode synthMode = SynthesisMode.BiQuadBSpline, int sourceLevel = 0)
    {
        if (sourceLevel == 0)
            sourceLevel = AnalyzeList.Count;

        int sampleCompensation = !_UseHigherPoT ? 1 : 0;

        // Check if a synthesis with the supplied name exists, if it does not make it and fill it out.
        if (!_synthDic.ContainsKey(name))
        {
            // Add the new synthesis in the dictionary.
            _synthDic.Add(name, new Synthesis(sourceLevel));
            // Fill the list in synthesis.
            for (int i = 0; i < sourceLevel; i++)
            {
                _synthDic[name].Pyramid.Add(new RenderTexture(_pow2S[_pow2S.IndexOf(_analyzeList[sourceLevel - sampleCompensation].width) + 1 + i], _pow2S[_pow2S.IndexOf(_analyzeList[sourceLevel - sampleCompensation].width) + 1 + i], 0, _textureFormat, RenderTextureReadWrite.Linear));
                _synthDic[name][i].enableRandomWrite = true;
                _synthDic[name][i].filterMode = _filterMode;
                _synthDic[name][i].Create();
            }

            _synthesiseIsInit = true;

            SynthesizeCall(_synthDic[name], sourceLevel, synthMode);
        }
        // If it does exist but the size is different or if the screen size has changed, delete the old one and make a new one with the right size.
        else if (_synthDic.ContainsKey(name) && (sourceLevel != _synthDic[name].SourceLevel || !_synthesiseIsInit))
        {
            foreach (RenderTexture rT in _synthDic[name].Pyramid)
            {
                if (rT.IsCreated())
                {
                    rT.Release();
                }
            }
            _synthDic[name].Pyramid.Clear();

            for (int i = 0; i < sourceLevel; i++)
            {
                _synthDic[name].Pyramid.Add(new RenderTexture(_pow2S[_pow2S.IndexOf(_analyzeList[sourceLevel - sampleCompensation].width) + 1 + i], _pow2S[_pow2S.IndexOf(_analyzeList[sourceLevel - sampleCompensation].width) + 1 + i], 0, _textureFormat, RenderTextureReadWrite.Linear));
                _synthDic[name][i].enableRandomWrite = true;
                _synthDic[name][i].filterMode = _filterMode;
                _synthDic[name][i].Create();
            }

            _synthDic[name].SetSourceLevel = sourceLevel;
            _synthesiseIsInit = true;

            SynthesizeCall(_synthDic[name], sourceLevel, synthMode);
        }
        // if everything is good, just do the call to generate the synthesis in the list.
        else
        {
            SynthesizeCall(_synthDic[name], sourceLevel, synthMode);
        }
    }