コード例 #1
0
ファイル: CameraEffect.cs プロジェクト: hw233/mmoclient
    public void OnDisable()
    {
        if (null != Mat)
        {
            DestroyImmediate(Mat);
        }

        RenderTextureManager.Instance.Dispose();

#if DOFPRO_EFFECT
        DOFHelper.Instance().Dispose();
#endif

#if BLOOMPRO_EFFECT
        BloomHelper.Instance().Dispose();
#endif
    }
コード例 #2
0
ファイル: CameraEffect.cs プロジェクト: hw233/mmoclient
    void RenderEffects(RenderTexture source, RenderTexture destination)
    {
        source.filterMode = FilterMode.Bilinear;

        RenderTexture curRenderTex = source;
        RenderTexture srcProcessed = source;

        curRenderTex = DownsampleTex(srcProcessed, 2f);

        if (Quality == EffectsQuality.Fastest)
        {
            RenderTextureManager.Instance.SafeAssign(ref curRenderTex, DownsampleTex(curRenderTex, 2f));
        }

#if DOFPRO_EFFECT
        RenderTexture cocRenderTex = null, dofRenderTex = null;
        if (DOFEnabled)
        {
            if (null == DOFParams.EffectCamera)
            {
                Debug.LogError("null == DOFParams.camera");
                return;
            }

            cocRenderTex = RenderTextureManager.Instance.RequestRenderTexture(curRenderTex.width, curRenderTex.height, curRenderTex.depth, curRenderTex.format);

            DOFHelper.Instance().RenderCOCTexture(curRenderTex, cocRenderTex, BlurCOCTexture ? 1.5f : 0f);

            if (VisualizeCOC)
            {
                Graphics.Blit(cocRenderTex, destination, DOFHelper.Mat, 3);
                RenderTextureManager.Instance.ReleaseRenderTexture(cocRenderTex);
                RenderTextureManager.Instance.ReleaseRenderTexture(curRenderTex);
                return;
            }

            dofRenderTex = RenderTextureManager.Instance.RequestRenderTexture(curRenderTex.width, curRenderTex.height, curRenderTex.depth, curRenderTex.format);

            DOFHelper.Instance().RenderDOFBlur(curRenderTex, dofRenderTex, cocRenderTex);

            Mat.SetTexture("_DOFTex", dofRenderTex);
            Mat.SetTexture("_COCTex", cocRenderTex);

            //Make bloom DOF-based?
            //RenderTextureManager.Instance.SafeAssign(ref curRenderTex, dofRenderTex);

            //Graphics.Blit( dofRenderTex, destination );
        }
#endif

        //Render bloom
#if BLOOMPRO_EFFECT
        if (BloomEnabled)
        {
            RenderTexture bloomTexture = RenderTextureManager.Instance.RequestRenderTexture(curRenderTex.width, curRenderTex.height, curRenderTex.depth, curRenderTex.format);
            BloomHelper.Instance().RenderBloomTexture(curRenderTex, bloomTexture);

            Mat.SetTexture("_BloomTex", bloomTexture);

            if (VisualizeBloom)
            {
                Graphics.Blit(bloomTexture, destination);
                return;
            }
        }
#endif
        if (DeathEffectEnabled)
        {
            Mat.SetFloat("_luminAmount", luminAmount);
        }
        if (MotionBlurEnabled)
        {
            Mat.SetFloat("Strength", Intensity);
            Mat.SetFloat("SampleDist", SampleDist);
            Graphics.Blit(srcProcessed, destination, Mat, 2);
        }
        else
        {
            Graphics.Blit(srcProcessed, destination, Mat, 0);
        }

        RenderTextureManager.Instance.ReleaseRenderTexture(srcProcessed);

#if DOFPRO_EFFECT
        RenderTextureManager.Instance.ReleaseRenderTexture(cocRenderTex);
        RenderTextureManager.Instance.ReleaseRenderTexture(dofRenderTex);
#endif

        RenderTextureManager.Instance.ReleaseRenderTexture(curRenderTex);
    }
コード例 #3
0
ファイル: CameraEffect.cs プロジェクト: hw233/mmoclient
    public void Init(bool searchForNonDepthmapAlphaObjects = false)
    {
        if (HalfResolution)
        {
            Screen.SetResolution(Screen.currentResolution.width / 2, Screen.currentResolution.height / 2, Screen.fullScreen, Screen.currentResolution.refreshRate);
        }

        Mat.SetFloat("_DirtIntensity", Mathf.Exp(LensDirtIntensity) - 1f);

        if (!LensDirtEnabled || null == LensDirtTexture || LensDirtIntensity <= 0f)
        {
            Mat.DisableKeyword("LENS_DIRT_ON");
            Mat.EnableKeyword("LENS_DIRT_OFF");
        }
        else
        {
            Mat.SetTexture("_LensDirtTex", LensDirtTexture);
            Mat.EnableKeyword("LENS_DIRT_ON");
            Mat.DisableKeyword("LENS_DIRT_OFF");
        }

        if (EffectCamera.hdr)
        {
            Shader.EnableKeyword("FXPRO_HDR_ON");
            Shader.DisableKeyword("FXPRO_HDR_OFF");
        }
        else
        {
            Shader.EnableKeyword("FXPRO_HDR_OFF");
            Shader.DisableKeyword("FXPRO_HDR_ON");
        }


        //Enable depth texture
        if (DOFEnabled)
        {
            if (EffectCamera.depthTextureMode == DepthTextureMode.None)
            {
                EffectCamera.depthTextureMode = DepthTextureMode.Depth;
            }
        }

        //
        //Depth of Field
#if DOFPRO_EFFECT
        if (DOFEnabled)
        {
            if (null == DOFParams.EffectCamera)
            {
                DOFParams.EffectCamera = EffectCamera;
            }

            DOFParams.DepthCompression = Mathf.Clamp(DOFParams.DepthCompression, 2f, 8f);

            DOFHelper.Instance().SetParams(DOFParams);
            DOFHelper.Instance().Init(searchForNonDepthmapAlphaObjects);

            Mat.DisableKeyword("DOF_DISABLED");
            Mat.EnableKeyword("DOF_ENABLED");

            //Less blur when using fastest quality
            if (!DOFParams.DoubleIntensityBlur)
            {
                DOFHelper.Instance().SetBlurRadius((Quality == EffectsQuality.Fastest || Quality == EffectsQuality.Fast) ? 3 : 5);
            }
            else
            {
                DOFHelper.Instance().SetBlurRadius((Quality == EffectsQuality.Fastest || Quality == EffectsQuality.Fast) ? 5 : 10);
            }
        }
        else
        {
            Mat.EnableKeyword("DOF_DISABLED");
            Mat.DisableKeyword("DOF_ENABLED");
        }
#endif

        //
        //Bloom
#if BLOOMPRO_EFFECT
        if (BloomEnabled)
        {
            BloomParams.Quality = Quality;
            BloomHelper.Instance().SetParams(BloomParams);
            BloomHelper.Instance().Init();

            Mat.DisableKeyword("BLOOM_DISABLED");
            Mat.EnableKeyword("BLOOM_ENABLED");
        }
        else
        {
            Mat.EnableKeyword("BLOOM_DISABLED");
            Mat.DisableKeyword("BLOOM_ENABLED");
        }
#endif
        if (DeathEffectEnabled)
        {
            Mat.DisableKeyword("DEATH_GRAY_DISABLED");
            Mat.EnableKeyword("DEATH_GRAY");
        }
        else
        {
            Mat.EnableKeyword("DEATH_GRAY_DISABLED");
            Mat.DisableKeyword("DEATH_GRAY");
        }
    }