Пример #1
0
    private void OnPreCull()
    {
        Camera camera = this.GetCamera();

        if (camera == null)
        {
            return;
        }
        if (this.rtWidth < 1 || this.rtHeight < 1)
        {
            return;
        }
        if (this.sunshineCamera == null)
        {
            this.sunshineCamera = base.GetComponent <SunshineCamera>();
            if (this.sunshine_cb != null)
            {
                this.sunshine_cb.Clear();
                this.MYFILTER_STYLES = null;
            }
        }
        if (!this.sunshineCamera.GoodToGo)
        {
            if (this.sunshine_cb != null)
            {
                this.sunshine_cb.Clear();
                this.MYFILTER_STYLES = null;
            }
            return;
        }
        if (this.MYFILTER_STYLES == null)
        {
            this.SetKeywordArray();
        }
        Vector3 direction = camera.ViewportPointToRay(new Vector3(0f, 0f, 0f)).direction;
        Vector3 v         = camera.ViewportPointToRay(new Vector3(1f, 0f, 0f)).direction - direction;
        Vector3 v2        = camera.ViewportPointToRay(new Vector3(0f, 1f, 0f)).direction - direction;

        Sunshine.Instance.PostScatterMaterial.SetVector("worldLightRay", Sunshine.Instance.SunLight.transform.forward);
        Sunshine.Instance.PostScatterMaterial.SetVector("worldRay", direction);
        Sunshine.Instance.PostScatterMaterial.SetVector("worldRayU", v);
        Sunshine.Instance.PostScatterMaterial.SetVector("worldRayV", v2);
        Sunshine.Instance.PostScatterMaterial.SetTexture("_ScatterRamp", Sunshine.Instance.ScatterRamp);
        this.quality = (int)(1 + Sunshine.Instance.ScatterSamplingQuality);
        Sunshine.Instance.PostScatterMaterial.SetColor("ScatterColor", Sunshine.Instance.ScatterColor);
        if (Sunshine.Instance.ScatterAnimateNoise)
        {
            this.scatterNoiseSeed += Time.deltaTime * Sunshine.Instance.ScatterAnimateNoiseSpeed;
            this.scatterNoiseSeed -= Mathf.Floor(this.scatterNoiseSeed);
        }
        Sunshine.Instance.PostScatterMaterial.SetTexture("ScatterDitherMap", Sunshine.Instance.ScatterDitherTexture);
        float value = 1f - Sunshine.Instance.ScatterExaggeration;
        float y     = 1f / (Mathf.Clamp01(value) * Sunshine.Instance.LightDistance / camera.farClipPlane);
        float num   = Sunshine.Instance.ScatterSky * Sunshine.Instance.ScatterIntensity;

        Sunshine.Instance.PostScatterMaterial.SetVector("ScatterIntensityVolumeSky", new Vector4(Sunshine.Instance.ScatterIntensity, y, num * 0.333f, num * 0.667f));
        int  b    = SunshineMath.RelativeResolutionDivisor(Sunshine.Instance.ScatterResolution);
        int2 @int = new int2(camera.pixelWidth, camera.pixelHeight) / b;

        @int.x = Mathf.Max(@int.x, 1);
        @int.y = Mathf.Max(@int.y, 1);
        Sunshine.Instance.PostScatterMaterial.SetVector("ScatterDitherData", new Vector3((float)@int.x / (float)Sunshine.Instance.ScatterDitherTexture.width, (float)@int.y / (float)Sunshine.Instance.ScatterDitherTexture.height, (!Sunshine.Instance.ScatterAnimateNoise) ? 0f : this.scatterNoiseSeed));
        Sunshine.Instance.PostBlurMaterial.SetFloat("BlurDepthTollerance", Sunshine.Instance.ScatterBlurDepthTollerance);
        if (this.sunshine_cb == null)
        {
            CommandBuffer[] commandBuffers = camera.GetCommandBuffers(CameraEvent.BeforeImageEffects);
            for (int i = 0; i < commandBuffers.Length; i++)
            {
                if (commandBuffers[i].name == "Sunshine CommandBuffer")
                {
                    this.sunshine_cb = commandBuffers[i];
                    break;
                }
            }
        }
        if (this.sunshine_cb == null)
        {
            this.sunshine_cb      = new CommandBuffer();
            this.sunshine_cb.name = "Sunshine CommandBuffer";
            camera.AddCommandBuffer(CameraEvent.BeforeImageEffects, this.sunshine_cb);
        }
        this.sunshine_cb.Clear();
        int nameID = Shader.PropertyToID("_SunshineScreenCopy");

        this.sunshine_cb.GetTemporaryRT(nameID, this.rtWidth, this.rtHeight, 0, FilterMode.Point, RenderTextureFormat.DefaultHDR, RenderTextureReadWrite.Default);
        this.sunshine_cb.Blit(BuiltinRenderTextureType.CameraTarget, nameID, this.blitMaterial, 0);
        int nameID2 = Shader.PropertyToID("_STempRT");
        int nameID3 = Shader.PropertyToID("_STempPingPongRT");

        this.sunshine_cb.GetTemporaryRT(nameID2, @int.x, @int.y, 0, FilterMode.Point, RenderTextureFormat.DefaultHDR, RenderTextureReadWrite.Default);
        this.sunshine_cb.GetTemporaryRT(nameID3, @int.x, @int.y, 0, FilterMode.Point, RenderTextureFormat.DefaultHDR, RenderTextureReadWrite.Default);
        this.sunshine_cb.SetGlobalTexture("_ScatterTexture", nameID2);
        this.sunshine_cb.DisableShaderKeyword(this.MYFILTER_STYLES[this.quality][0]);
        this.sunshine_cb.DisableShaderKeyword(this.MYFILTER_STYLES[this.quality][1]);
        this.sunshine_cb.DisableShaderKeyword(this.MYFILTER_STYLES[this.quality][2]);
        this.sunshine_cb.DisableShaderKeyword(this.MYFILTER_STYLES[this.quality][3]);
        this.sunshine_cb.EnableShaderKeyword(this.MYFILTER_STYLES[this.quality][4]);
        this.sunshine_cb.Blit(Texture2D.blackTexture, nameID2, Sunshine.Instance.PostScatterMaterial, 0);
        this.sunshine_cb.SetGlobalVector("BlurXY", new Vector2(1f, 0f));
        this.sunshine_cb.Blit(nameID2, nameID3, Sunshine.Instance.PostBlurMaterial, 0);
        this.sunshine_cb.SetGlobalVector("BlurXY", new Vector2(0f, 1f));
        this.sunshine_cb.Blit(nameID3, nameID2, Sunshine.Instance.PostBlurMaterial, 0);
        this.sunshine_cb.SetGlobalTexture(this.MainTexID, nameID);
        this.sunshine_cb.Blit(nameID, BuiltinRenderTextureType.CameraTarget, Sunshine.Instance.PostScatterMaterial, 1);
        this.sunshine_cb.ReleaseTemporaryRT(nameID);
        this.sunshine_cb.ReleaseTemporaryRT(nameID2);
        this.sunshine_cb.ReleaseTemporaryRT(nameID3);
    }
Пример #2
0
 public void OnPostProcess(RenderTexture source, RenderTexture destination)
 {
     if (!this.GoodToGo)
     {
         Graphics.Blit(source, destination);
         return;
     }
     if (Sunshine.Instance.DebugView == SunshineDebugViews.Cascades)
     {
         SunshinePostprocess.Blit(source, destination, Sunshine.Instance.PostDebugMaterial, SunshinePostDebugPass.DebugCascades);
     }
     else
     {
         bool scatterActive = Sunshine.Instance.ScatterActive;
         if (scatterActive)
         {
             bool flag = Sunshine.Instance.ScatterBlur;
             if (!Sunshine.Instance.PostBlurSupported)
             {
                 flag = false;
             }
             bool      flag2 = Sunshine.Instance.OvercastAffectsScatter && (Sunshine.Instance.OvercastTexture || Sunshine.Instance.ScatterOvercastTexture);
             bool      customScatterOvercast = Sunshine.Instance.CustomScatterOvercast;
             Texture2D overcastTexture       = (!flag2) ? null : ((!customScatterOvercast) ? Sunshine.Instance.OvercastTexture : Sunshine.Instance.ScatterOvercastTexture);
             float     overcastScale         = (!customScatterOvercast) ? Sunshine.Instance.OvercastScale : Sunshine.Instance.ScatterOvercastScale;
             Vector2   overcastMovement      = (!customScatterOvercast) ? Sunshine.Instance.OvercastMovement : Sunshine.Instance.ScatterOvercastMovement;
             float     overcastPlaneHeight   = (!customScatterOvercast) ? Sunshine.Instance.OvercastPlaneHeight : Sunshine.Instance.ScatterOvercastPlaneHeight;
             this.ConfigureOvercast(flag2, overcastTexture, overcastScale, overcastMovement, overcastPlaneHeight);
             Vector3 direction = this.AttachedCamera.ViewportPointToRay(new Vector3(0f, 0f, 0f)).direction;
             Vector3 v         = this.AttachedCamera.ViewportPointToRay(new Vector3(1f, 0f, 0f)).direction - direction;
             Vector3 v2        = this.AttachedCamera.ViewportPointToRay(new Vector3(0f, 1f, 0f)).direction - direction;
             Sunshine.Instance.PostScatterMaterial.SetVector("worldLightRay", Sunshine.Instance.SunLight.transform.forward);
             Sunshine.Instance.PostScatterMaterial.SetVector("worldRay", direction);
             Sunshine.Instance.PostScatterMaterial.SetVector("worldRayU", v);
             Sunshine.Instance.PostScatterMaterial.SetVector("worldRayV", v2);
             Sunshine.Instance.PostScatterMaterial.SetTexture("_ScatterRamp", Sunshine.Instance.ScatterRamp);
             SunshineKeywords.SetScatterQuality(Sunshine.Instance.ScatterSamplingQuality);
             Sunshine.Instance.PostScatterMaterial.SetVector("ScatterColor", Sunshine.Instance.ScatterColor);
             if (Sunshine.Instance.ScatterAnimateNoise)
             {
                 this.scatterNoiseSeed += Time.deltaTime * Sunshine.Instance.ScatterAnimateNoiseSpeed;
                 this.scatterNoiseSeed -= Mathf.Floor(this.scatterNoiseSeed);
             }
             Sunshine.Instance.PostScatterMaterial.SetTexture("ScatterDitherMap", Sunshine.Instance.ScatterDitherTexture);
             float value = 1f - Sunshine.Instance.ScatterExaggeration;
             float y     = 1f / (Mathf.Clamp01(value) * Sunshine.Instance.LightDistance / this.AttachedCamera.farClipPlane);
             float num   = Sunshine.Instance.ScatterSky * Sunshine.Instance.ScatterIntensity;
             Sunshine.Instance.PostScatterMaterial.SetVector("ScatterIntensityVolumeSky", new Vector4(Sunshine.Instance.ScatterIntensity, y, num * 0.333f, num * 0.667f));
             bool flag3 = Sunshine.Instance.ScatterResolution == SunshineRelativeResolutions.Full && !flag && Sunshine.Instance.DebugView != SunshineDebugViews.Scatter;
             SunshineKeywords.ToggleScatterBlendNow(flag3);
             if (!flag3)
             {
                 int  b    = SunshineMath.RelativeResolutionDivisor(Sunshine.Instance.ScatterResolution);
                 int2 @int = new int2(source.width, source.height) / b;
                 @int.x = Mathf.Max(@int.x, 1);
                 @int.y = Mathf.Max(@int.y, 1);
                 Sunshine.Instance.PostScatterMaterial.SetVector("ScatterDitherData", new Vector3((float)@int.x / (float)Sunshine.Instance.ScatterDitherTexture.width, (float)@int.y / (float)Sunshine.Instance.ScatterDitherTexture.height, (!Sunshine.Instance.ScatterAnimateNoise) ? 0f : this.scatterNoiseSeed));
                 RenderTexture temporary = RenderTexture.GetTemporary(@int.x, @int.y, 0, source.format, RenderTextureReadWrite.Default);
                 if (temporary)
                 {
                     temporary.filterMode = FilterMode.Point;
                     temporary.wrapMode   = TextureWrapMode.Clamp;
                     SunshinePostprocess.Blit(source, temporary, Sunshine.Instance.PostScatterMaterial, SunshinePostScatterPass.DrawScatter);
                     if (flag)
                     {
                         Sunshine.Instance.PostBlurMaterial.SetFloat("BlurDepthTollerance", Sunshine.Instance.ScatterBlurDepthTollerance);
                         RenderTexture temporary2 = RenderTexture.GetTemporary(temporary.width, temporary.height, 0, temporary.format, RenderTextureReadWrite.Default);
                         if (temporary2)
                         {
                             temporary2.filterMode = temporary.filterMode;
                             temporary2.wrapMode   = temporary.wrapMode;
                             Sunshine.Instance.PostBlurMaterial.SetVector("BlurXY", new Vector2(1f, 0f));
                             SunshinePostprocess.Blit(temporary, temporary2, Sunshine.Instance.PostBlurMaterial, 0);
                             temporary.DiscardContents();
                             Sunshine.Instance.PostBlurMaterial.SetVector("BlurXY", new Vector2(0f, 1f));
                             SunshinePostprocess.Blit(temporary2, temporary, Sunshine.Instance.PostBlurMaterial, 0);
                             RenderTexture.ReleaseTemporary(temporary2);
                         }
                     }
                     temporary.filterMode = FilterMode.Bilinear;
                     if (Sunshine.Instance.DebugView == SunshineDebugViews.Scatter)
                     {
                         SunshinePostprocess.Blit(temporary, destination, Sunshine.Instance.PostDebugMaterial, SunshinePostDebugPass.DebugAlpha);
                     }
                     else
                     {
                         Sunshine.Instance.PostScatterMaterial.SetTexture("_ScatterTexture", temporary);
                         SunshinePostprocess.Blit(source, destination, Sunshine.Instance.PostScatterMaterial, SunshinePostScatterPass.ApplyScatter);
                     }
                     RenderTexture.ReleaseTemporary(temporary);
                 }
                 else
                 {
                     flag3 = true;
                 }
             }
             if (flag3)
             {
                 Sunshine.Instance.PostScatterMaterial.SetVector("ScatterDitherData", new Vector3((float)this.AttachedCamera.pixelWidth / (float)Sunshine.Instance.ScatterDitherTexture.width, (float)this.AttachedCamera.pixelHeight / (float)Sunshine.Instance.ScatterDitherTexture.height, (!Sunshine.Instance.ScatterAnimateNoise) ? 0f : this.scatterNoiseSeed));
                 SunshinePostprocess.Blit(source, destination, Sunshine.Instance.PostScatterMaterial, SunshinePostScatterPass.DrawScatter);
             }
         }
     }
 }