private void OnEnable() { this.sunshinePostprocess = base.GetComponent <SunshinePostprocess>(); if (this.sunshinePostprocess == null) { this.sunshinePostprocess = base.gameObject.AddComponent <SunshinePostprocess>(); } }
private void Init() { if (this.initChecker == null) { this.gbufferTextures = new RenderTexture[3]; this.gbufferBuffers = new RenderBuffer[3]; this.c = base.GetComponent <Camera>(); this.SetupGbufferTextures(); this.SetupTransparentCamera(); this.c.renderingPath = RenderingPath.Forward; if (DeferredShadingCamera.sceneLights == null) { DeferredShadingCamera.sceneLights = new List <DeferredLight>(); } else { foreach (DeferredLight current in DeferredShadingCamera.sceneLights) { if (current == null) { DeferredShadingCamera.sceneLights.Remove(current); } } } if (!this.compositeMaterial) { this.compositeMaterial = new Material(this.compositeShader); } if (!this.ssaoMaterial) { this.ssaoMaterial = new Material(this.ssaoShader); } if (!this.postBlurMaterial) { this.postBlurMaterial = new Material(this.postBlurShader); } if (this.sunshinePostProcess == null) { this.sunshinePostProcess = base.GetComponent <SunshinePostprocess>(); } this.initChecker = new object(); } }
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); } } } }
void OnEnable() { sunshinePostprocess = GetComponent<SunshinePostprocess>(); if(sunshinePostprocess == null) sunshinePostprocess = gameObject.AddComponent<SunshinePostprocess>(); }
private void OnEnable() { this.sunshinePostprocess = base.GetComponent<SunshinePostprocess>(); if (this.sunshinePostprocess == null) { this.sunshinePostprocess = base.gameObject.AddComponent<SunshinePostprocess>(); } }