public Texture Apply(Texture2D fogtexture, Vector2Int resolution, int amount, int iterations, FogOfWarBlurType type)
        {
            if (amount <= 0 || iterations <= 0)
            {
                return(fogtexture);
            }

            if (_blurMaterial == null)
            {
                _blurMaterial = new Material(FogOfWarUtils.FindShader("Hidden/FogOfWarBlurShader"));
            }

            _blurMaterial.SetFloat("_BlurAmount", amount);
            _blurMaterial.SetKeywordEnabled("GAUSSIAN3", type == FogOfWarBlurType.Gaussian3);
            _blurMaterial.SetKeywordEnabled("GAUSSIAN5", type == FogOfWarBlurType.Gaussian5);
            _blurMaterial.SetKeywordEnabled("ANTIALIAS", type == FogOfWarBlurType.Antialias);

            SetupRenderTarget(resolution, ref _target);
            if (iterations > 1)
            {
                SetupRenderTarget(resolution, ref _source);
            }

            _target.MarkRestoreExpected();
            Graphics.Blit(fogtexture, _target, _blurMaterial);

            for (int i = 1; i < iterations; ++i)
            {
                FogOfWarUtils.Swap(ref _target, ref _source);
                _target.MarkRestoreExpected();
                Graphics.Blit(_source, _target, _blurMaterial);
            }

            return(_target);
        }
Example #2
0
 public void Setup(PostProcessRenderContext context)
 {
     _context = context;
     if (_shader == null)
     {
         _shader = FogOfWarUtils.FindShader("Hidden/FogOfWarPPSv2");
     }
     _sheet = _context.propertySheets.Get(_shader);
 }
        protected override void OnInitialise()
        {
            if (_material == null)
            {
                _material = new Material(FogOfWarUtils.FindShader("Hidden/FogOfWarHardware"));
            }

            if (_renderTexture != null)
            {
                _renderTexture.Release();
                Object.Destroy(_renderTexture);
                _renderTexture = null;

                Object.Destroy(_outputTexture);
                _outputTexture = null;
            }

            _renderTexture = new RenderTexture(_map.resolution.x, _map.resolution.y, 16, RenderTextureFormat.ARGB32);
            _outputTexture = new Texture2D(_map.resolution.x, _map.resolution.y, TextureFormat.ARGB32, false);
        }
 public FogOfWarLegacyManager()
 {
     _material      = new Material(FogOfWarUtils.FindShader("Hidden/FogOfWarLegacy"));
     _material.name = "FogOfWarLegacy";
 }