Пример #1
0
        public void RemovePostEffects(Camera mainCam)
        {
            Debug.Log("Clearing existing post effects");
            Camera[] cams = Camera.allCameras;

            foreach (Camera c in cams)
            {
                if (c != mainCam)
                {
                    if (UseCrease)
                    {
                        Crease creaseEffect = c.GetComponent <Crease>();
                        if (creaseEffect)
                        {
                            Component.Destroy(creaseEffect);
                        }
                    }

                    if (UseSSAO)
                    {
                        SSAOEffect ssaoEffect = c.GetComponent <SSAOEffect>();
                        if (ssaoEffect)
                        {
                            Component.Destroy(ssaoEffect);
                        }
                    }

                    if (UseColorCorrection)
                    {
                        ColorCorrectionLUT ccEffect = c.GetComponent <ColorCorrectionLUT>();
                        if (ccEffect)
                        {
                            Component.DestroyImmediate(ccEffect);
                        }
                    }
                    if (UseDOF)
                    {
                        DepthOfFieldScatter dofEffect = c.GetComponent <DepthOfFieldScatter>();
                        if (dofEffect)
                        {
                            Component.Destroy(dofEffect);
                        }
                    }

                    if (UseAA)
                    {
                        AntialiasingAsPostEffect AAeffect = c.GetComponent <AntialiasingAsPostEffect>();
                        if (AAeffect)
                        {
                            Component.Destroy(AAeffect);
                        }
                    }

                    if (UseEdgeDetect)
                    {
                        EdgeDetectEffectNormal Edgeeffect = c.GetComponent <EdgeDetectEffectNormal>();
                        if (Edgeeffect)
                        {
                            Component.Destroy(Edgeeffect);
                        }
                    }

                    if (UseBloom)
                    {
                        Bloom bloomEffect = c.GetComponent <Bloom>();
                        if (bloomEffect)
                        {
                            Component.Destroy(bloomEffect);
                        }
                    }

                    if (UseTonemap)
                    {
                        ToneMapping toneEffect = c.GetComponent <ToneMapping>();
                        if (toneEffect)
                        {
                            Component.Destroy(toneEffect);
                        }
                    }

                    if (UseVignette)
                    {
                        Vignetting vigEffect = c.GetComponent <Vignetting>();
                        if (vigEffect)
                        {
                            Component.Destroy(vigEffect);
                        }
                    }
                }
            }
        }
Пример #2
0
        public void AddPostEffects()
        {
            if (mainCam != null)
            {
                Debug.Log("Main Camera: " + mainCam.name);
                RemovePostEffects(mainCam);
                Debug.Log("Adding post effects");

                if (UseSSAO)
                {
                    SSAOEffect ssaoEffect = mainCam.GetComponent <SSAOEffect>();
                    if (!ssaoEffect)
                    {
                        Debug.Log("Adding SSAO");
                        ssaoEffect = mainCam.gameObject.AddComponent <SSAOEffect>();
                        ssaoEffect.m_SSAOShader    = effectShaders["ScreenSpaceAmbientObscurance"];
                        ssaoEffect.m_RandomTexture = effectTextures["RandomVectors"];
                    }
                }

                if (UseColorCorrection)
                {
                    ColorCorrectionLUT ccEffect = mainCam.GetComponent <ColorCorrectionLUT>();
                    if (!ccEffect)
                    {
                        Debug.Log("Adding ColorCorrection");
                        ccEffect        = mainCam.gameObject.AddComponent <ColorCorrectionLUT>();
                        ccEffect.shader = effectShaders["ColorCorrection3DLut"];
                        ccEffect.Convert(effectTextures["ContrastEnhanced3D16"], "");
                    }
                }

                if (UseAA)
                {
                    AntialiasingAsPostEffect AAeffect = mainCam.GetComponent <AntialiasingAsPostEffect>();
                    if (!AAeffect)
                    {
                        Debug.Log("Adding AA");
                        AAeffect                   = mainCam.gameObject.AddComponent <AntialiasingAsPostEffect>();
                        AAeffect.shader            = effectShaders["AA_DLAA"];
                        AAeffect.dlaaShader        = effectShaders["AA_DLAA"];
                        AAeffect.nfaaShader        = effectShaders["AA_NFAA"];
                        AAeffect.shaderFXAAII      = effectShaders["AA_FXAA2"];
                        AAeffect.shaderFXAAIII     = effectShaders["AA_FXAA3Console"];
                        AAeffect.shaderFXAAPreset2 = effectShaders["AA_FXAAPreset2"];
                        AAeffect.shaderFXAAPreset3 = effectShaders["AA_FXAAPreset3"];
                        AAeffect.ssaaShader        = effectShaders["AA_SSAA"];
                        //AAeffect.shader = effectShaders["AA_NFAA"];
                        AAeffect.mode      = AAMode.NFAA;
                        AAeffect.dlaaSharp = true;
                    }
                }

                if (UseEdgeDetect)
                {
                    EdgeDetectEffectNormal EdgeEffect = mainCam.GetComponent <EdgeDetectEffectNormal>();
                    if (!EdgeEffect)
                    {
                        Debug.Log("Adding EdgeEffect");
                        EdgeEffect        = mainCam.gameObject.AddComponent <EdgeDetectEffectNormal>();
                        EdgeEffect.shader = effectShaders["EdgeDetectNormals"];
                    }
                }

                if (UseCrease)
                {
                    Crease creaseEffect = mainCam.GetComponent <Crease>();
                    if (!creaseEffect)
                    {
                        Debug.Log("Adding Crease Effect");
                        creaseEffect                  = mainCam.gameObject.AddComponent <Crease>();
                        creaseEffect.blurShader       = effectShaders["BLOOM_SeparableBlurPlus"];
                        creaseEffect.depthFetchShader = effectShaders["ConvertDepth"];
                        creaseEffect.shader           = effectShaders["CreaseApply"];
                    }
                }

                if (UseDOF)
                {
                    DepthOfFieldScatter dofEffect = mainCam.GetComponent <DepthOfFieldScatter>();
                    if (!dofEffect)
                    {
                        Debug.Log("Adding DOF");
                        dofEffect                 = mainCam.gameObject.AddComponent <DepthOfFieldScatter>();
                        dofEffect.shader          = effectShaders["DOF_DepthOfFieldScatter"];
                        dofEffect.nearBlur        = false;
                        dofEffect.blurSampleCount = DepthOfFieldScatter.BlurSampleCount.High;
                        dofEffect.highResolution  = true;
                        //dofEffect.blurType = DepthOfFieldScatter.BlurType.DX11;
                        dofEffect.aperture = 10f;
                    }
                }

                if (UseBloom)
                {
                    Bloom bloomEffect = mainCam.GetComponent <Bloom>();
                    if (!bloomEffect)
                    {
                        Debug.Log("Adding Bloom");
                        bloomEffect     = mainCam.gameObject.AddComponent <Bloom>();
                        bloomEffect.hdr = Bloom.HDRBloomMode.Auto;
                        bloomEffect.supportHDRTextures = true;
                        bloomEffect.lensflareMode      = Bloom.LensFlareStyle.Combined;
                        bloomEffect.quality            = Bloom.BloomQuality.High;
                        bloomEffect.lensflareIntensity = 1.2f;
                        //bloomEffect.bloomThreshhold = 0.45f;

                        bloomEffect.shader = effectShaders["BLOOM_BlurAndFlares"];
                        bloomEffect.blurAndFlaresShader    = effectShaders["BLOOM_BlurAndFlares"];
                        bloomEffect.lensFlareShader        = effectShaders["BLOOM_LensFlareCreate"];
                        bloomEffect.screenBlendShader      = effectShaders["BLOOM_BlendForBloom"];
                        bloomEffect.brightPassFilterShader = effectShaders["BLOOM_BrightPassFilter2"];
                        bloomEffect.lensFlareVignetteMask  = effectTextures["VignetteMask"];
                    }
                }

                if (UseTonemap)
                {
                    ToneMapping toneEffect = mainCam.GetComponent <ToneMapping>();
                    if (!toneEffect)
                    {
                        Debug.Log("Adding Tonemapper");

                        toneEffect        = mainCam.gameObject.AddComponent <ToneMapping>();
                        toneEffect.shader = effectShaders["Tonemapper"];
                        //toneEffect.type = ToneMapping.TonemapperType.Photographic;
                        toneEffect.type = ToneMapping.TonemapperType.AdaptiveReinhard;
                        toneEffect.exposureAdjustment = 1f;
                        toneEffect.white = 1.75f;
                    }
                }

                if (UseVignette)
                {
                    Vignetting vigEffect = mainCam.GetComponent <Vignetting>();
                    if (!vigEffect)
                    {
                        Debug.Log("Adding Vignette/Chromatic Aberration");

                        vigEffect        = mainCam.gameObject.AddComponent <Vignetting>();
                        vigEffect.shader = effectShaders["VignettingShader"];
                        vigEffect.separableBlurShader   = effectShaders["DOF_SeparableBlur"];
                        vigEffect.chromAberrationShader = effectShaders["ChromaticAberrationShader"];
                        vigEffect.mode = Vignetting.AberrationMode.Simple;
                        vigEffect.chromaticAberration = 1f;
                        vigEffect.intensity           = 1f;
                    }
                }
            }
        }