using System; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace BeautifyEffect { [HelpURLAttribute("http://kronnect.com/taptapgo")] [ExecuteInEditMode] [AddComponentMenu("Image Effects/Rendering/Beautify")] [RequireComponent(typeof(Camera))] [ImageEffectAllowedInSceneView] public class Beautify : MonoBehaviour { [SerializeField] private BEAUTIFY_PRESET _preset = BEAUTIFY_PRESET.Medium; [SerializeField] private BEAUTIFY_QUALITY _quality; [SerializeField] private BeautifyProfile _profile; [SerializeField] private bool _compareMode; [SerializeField] [Range(-(float)Math.PI, (float)Math.PI)] private float _compareLineAngle = 1.4f; [Range(0.0001f, 0.05f)] [SerializeField] private float _compareLineWidth = 0.002f; [Range(0f, 0.2f)] [SerializeField] private float _dither = 0.02f; [SerializeField] [Range(0f, 1f)] private float _ditherDepth; [Range(0f, 1f)] [SerializeField] private float _sharpenMinDepth; [SerializeField] [Range(0f, 1.1f)] private float _sharpenMaxDepth = 0.999f; [SerializeField] [Range(0f, 15f)] private float _sharpen = 2f; [SerializeField] [Range(0f, 0.05f)] private float _sharpenDepthThreshold = 0.035f; [SerializeField] private Color _tintColor = new Color(1f, 1f, 1f, 0f); [SerializeField] [Range(0f, 0.2f)] private float _sharpenRelaxation = 0.08f; [Range(0f, 1f)] [SerializeField] private float _sharpenClamp = 0.45f; [SerializeField] [Range(0f, 1f)] private float _sharpenMotionSensibility = 0.5f; [SerializeField] [Range(-2f, 3f)] private float _saturate = 1f; [SerializeField] [Range(0.5f, 1.5f)] private float _contrast = 1.02f; [SerializeField] private float _brightness = 1.05f; [SerializeField] [Range(0f, 2f)] private float _daltonize; [SerializeField] private bool _vignetting; [SerializeField] private Color _vignettingColor = new Color(0.3f, 0.3f, 0.3f, 0.05f); [SerializeField] [Range(0f, 1f)] private float _vignettingFade; [SerializeField] private bool _vignettingCircularShape; [SerializeField] private float _vignettingAspectRatio = 1f; [Range(0f, 1f)] [SerializeField] private float _vignettingBlink; [SerializeField] private Texture2D _vignettingMask; [SerializeField] private bool _frame; [SerializeField] private Color _frameColor = new Color(1f, 1f, 1f, 0.047f); [SerializeField] private Texture2D _frameMask; [SerializeField] private bool _lut; [Range(0f, 1f)] [SerializeField] private float _lutIntensity = 1f; [SerializeField] private Texture2D _lutTexture; [SerializeField] private bool _nightVision; [SerializeField] private Color _nightVisionColor = new Color(0.5f, 1f, 0.5f, 0.5f); [SerializeField] private bool _outline; [SerializeField] private Color _outlineColor = new Color(0f, 0f, 0f, 0.8f); [SerializeField] private bool _thermalVision; [SerializeField] private bool _lensDirt; [SerializeField] [Range(0f, 1f)] private float _lensDirtThreshold = 0.5f; [Range(0f, 1f)] [SerializeField] private float _lensDirtIntensity = 0.9f; [SerializeField] private Texture2D _lensDirtTexture; [SerializeField] private bool _bloom; [SerializeField] private LayerMask _bloomCullingMask = 0; [Range(1f, 4f)] [SerializeField] private float _bloomLayerMaskDownsampling = 1f; [Range(0f, 10f)] [SerializeField] private float _bloomIntensity = 1f; [SerializeField] private float _bloomMaxBrightness = 1000f; [Range(0f, 3f)] [SerializeField] private float _bloomBoost0; [SerializeField] [Range(0f, 3f)] private float _bloomBoost1; [SerializeField] [Range(0f, 3f)] private float _bloomBoost2; [Range(0f, 3f)] [SerializeField] private float _bloomBoost3; [SerializeField] [Range(0f, 3f)] private float _bloomBoost4; [Range(0f, 3f)] [SerializeField] private float _bloomBoost5; [SerializeField] private bool _bloomAntiflicker; [SerializeField] private bool _bloomUltra; [Range(0f, 5f)] [SerializeField] private float _bloomThreshold = 0.75f; [SerializeField] private bool _bloomCustomize; [SerializeField] private bool _bloomDebug; [Range(0f, 1f)] [SerializeField] private float _bloomWeight0 = 0.5f; [Range(0f, 1f)] [SerializeField] private float _bloomWeight1 = 0.5f; [SerializeField] [Range(0f, 1f)] private float _bloomWeight2 = 0.5f; [SerializeField] [Range(0f, 1f)] private float _bloomWeight3 = 0.5f; [Range(0f, 1f)] [SerializeField] private float _bloomWeight4 = 0.5f; [SerializeField] [Range(0f, 1f)] private float _bloomWeight5 = 0.5f; [SerializeField] private bool _bloomBlur = true; [Range(0f, 1f)] [SerializeField] private float _bloomDepthAtten; [SerializeField] [Range(-1f, 1f)] private float _bloomLayerZBias; [SerializeField] private bool _anamorphicFlares; [SerializeField] [Range(0f, 10f)] private float _anamorphicFlaresIntensity = 1f; [SerializeField] private bool _anamorphicFlaresAntiflicker; [SerializeField] private bool _anamorphicFlaresUltra; [Range(0f, 5f)] [SerializeField] private float _anamorphicFlaresThreshold = 0.75f; [SerializeField] [Range(0.1f, 2f)] private float _anamorphicFlaresSpread = 1f; [SerializeField] private bool _anamorphicFlaresVertical; [SerializeField] private Color _anamorphicFlaresTint = new Color(0.5f, 0.5f, 1f, 0f); [SerializeField] private bool _anamorphicFlaresBlur = true; [SerializeField] private bool _depthOfField; [SerializeField] private bool _depthOfFieldTransparencySupport; [SerializeField] private LayerMask _depthOfFieldTransparencyLayerMask = -1; [SerializeField] private Transform _depthOfFieldTargetFocus; [SerializeField] private bool _depthOfFieldDebug; [SerializeField] private bool _depthOfFieldAutofocus; [SerializeField] private Vector2 _depthofFieldAutofocusViewportPoint = new Vector2(0.5f, 0.5f); [SerializeField] private float _depthOfFieldAutofocusMinDistance; [SerializeField] private float _depthOfFieldAutofocusMaxDistance = 10000f; [SerializeField] private LayerMask _depthOfFieldAutofocusLayerMask = -1; [SerializeField] private LayerMask _depthOfFieldExclusionLayerMask = 0; [Range(1f, 4f)] [SerializeField] private float _depthOfFieldExclusionLayerMaskDownsampling = 1f; [Range(1f, 4f)] [SerializeField] private float _depthOfFieldTransparencySupportDownsampling = 1f; [SerializeField] [Range(0.9f, 1f)] private float _depthOfFieldExclusionBias = 0.99f; [SerializeField] [Range(1f, 100f)] private float _depthOfFieldDistance = 1f; [SerializeField] [Range(0.001f, 5f)] private float _depthOfFieldFocusSpeed = 1f; [Range(1f, 5f)] [SerializeField] private int _depthOfFieldDownsampling = 2; [SerializeField] [Range(2f, 16f)] private int _depthOfFieldMaxSamples = 4; [SerializeField] [Range(0.005f, 0.5f)] private float _depthOfFieldFocalLength = 0.05f; [SerializeField] private float _depthOfFieldAperture = 2.8f; [SerializeField] private bool _depthOfFieldForegroundBlur = true; [SerializeField] private bool _depthOfFieldForegroundBlurHQ; [SerializeField] private float _depthOfFieldForegroundDistance = 0.25f; [SerializeField] private bool _depthOfFieldBokeh = true; [Range(0.5f, 3f)] [SerializeField] private float _depthOfFieldBokehThreshold = 1f; [Range(0f, 8f)] [SerializeField] private float _depthOfFieldBokehIntensity = 2f; [SerializeField] private float _depthOfFieldMaxBrightness = 1000f; [SerializeField] [Range(0f, 1f)] private float _depthOfFieldMaxDistance = 1f; [SerializeField] private FilterMode _depthOfFieldFilterMode = FilterMode.Bilinear; [NonSerialized] public OnBeforeFocusEvent OnBeforeFocus; [SerializeField] private bool _eyeAdaptation; [Range(0f, 1f)] [SerializeField] private float _eyeAdaptationMinExposure = 0.2f; [Range(1f, 100f)] [SerializeField] private float _eyeAdaptationMaxExposure = 5f; [Range(0f, 1f)] [SerializeField] private float _eyeAdaptationSpeedToLight = 0.4f; [Range(0f, 1f)] [SerializeField] private float _eyeAdaptationSpeedToDark = 0.2f; [SerializeField] private bool _purkinje; [Range(0f, 5f)] [SerializeField] private float _purkinjeAmount = 1f; [Range(0f, 1f)] [SerializeField] private float _purkinjeLuminanceThreshold = 0.15f; [SerializeField] private BEAUTIFY_TMO _tonemap; [SerializeField] private bool _sunFlares; [SerializeField] private Transform _sun; [SerializeField] private LayerMask _sunFlaresLayerMask = -1; [SerializeField] [Range(0f, 1f)] private float _sunFlaresIntensity = 1f; [Range(0f, 1f)] [SerializeField] private float _sunFlaresSolarWindSpeed = 0.01f; [SerializeField] private Color _sunFlaresTint = new Color(1f, 1f, 1f); [Range(1f, 5f)] [SerializeField] private int _sunFlaresDownsampling = 1; [Range(0f, 1f)] [SerializeField] private float _sunFlaresSunIntensity = 0.1f; [SerializeField] [Range(0f, 1f)] private float _sunFlaresSunDiskSize = 0.05f; [Range(0f, 10f)] [SerializeField] private float _sunFlaresSunRayDiffractionIntensity = 3.5f; [SerializeField] [Range(0f, 1f)] private float _sunFlaresSunRayDiffractionThreshold = 0.13f; [Range(0f, 0.2f)] [SerializeField] private float _sunFlaresCoronaRays1Length = 0.02f; [SerializeField] [Range(2f, 30f)] private int _sunFlaresCoronaRays1Streaks = 12; [Range(0f, 0.1f)] [SerializeField] private float _sunFlaresCoronaRays1Spread = 0.001f; [Range(0f, (float)Math.PI * 2f)] [SerializeField] private float _sunFlaresCoronaRays1AngleOffset; [Range(0f, 0.2f)] [SerializeField] private float _sunFlaresCoronaRays2Length = 0.05f; [SerializeField] [Range(2f, 30f)] private int _sunFlaresCoronaRays2Streaks = 12; [Range(0f, 0.1f)] [SerializeField] private float _sunFlaresCoronaRays2Spread = 0.1f; [Range(0f, (float)Math.PI * 2f)] [SerializeField] private float _sunFlaresCoronaRays2AngleOffset; [Range(0f, 1f)] [SerializeField] private float _sunFlaresGhosts1Size = 0.03f; [SerializeField] [Range(-3f, 3f)] private float _sunFlaresGhosts1Offset = 1.04f; [SerializeField] [Range(0f, 1f)] private float _sunFlaresGhosts1Brightness = 0.037f; [SerializeField] [Range(0f, 1f)] private float _sunFlaresGhosts2Size = 0.1f; [SerializeField] [Range(-3f, 3f)] private float _sunFlaresGhosts2Offset = 0.71f; [Range(0f, 1f)] [SerializeField] private float _sunFlaresGhosts2Brightness = 0.03f; [Range(0f, 1f)] [SerializeField] private float _sunFlaresGhosts3Size = 0.24f; [Range(-3f, 3f)] [SerializeField] private float _sunFlaresGhosts3Brightness = 0.025f; [Range(0f, 1f)] [SerializeField] private float _sunFlaresGhosts3Offset = 0.31f; [Range(0f, 1f)] [SerializeField] private float _sunFlaresGhosts4Size = 0.016f; [Range(-3f, 3f)] [SerializeField] private float _sunFlaresGhosts4Offset; [Range(0f, 1f)] [SerializeField] private float _sunFlaresGhosts4Brightness = 0.017f; [Range(0f, 1f)] [SerializeField] private float _sunFlaresHaloOffset = 0.22f; [Range(0f, 50f)] [SerializeField] private float _sunFlaresHaloAmplitude = 15.1415f; [Range(0f, 1f)] [SerializeField] private float _sunFlaresHaloIntensity = 0.01f; [SerializeField] private bool _sunFlaresRotationDeadZone; [SerializeField] private bool _blur; [Range(0f, 4f)] [SerializeField] private float _blurIntensity = 1f; [Range(1f, 256f)] [SerializeField] private int _pixelateAmount = 1; [SerializeField] private bool _pixelateDownscale; [Range(0f, 20f)] [SerializeField] private float _antialiasStrength = 5f; [Range(0f, 0.05f)] [SerializeField] private float _antialiasDepthThreshold = 0.001f; public bool isDirty; private static Beautify _beautify; public const string SKW_BLOOM = "BEAUTIFY_BLOOM"; public const string SKW_LUT = "BEAUTIFY_LUT"; public const string SKW_NIGHT_VISION = "BEAUTIFY_NIGHT_VISION"; public const string SKW_THERMAL_VISION = "BEAUTIFY_THERMAL_VISION"; public const string SKW_OUTLINE = "BEAUTIFY_OUTLINE"; public const string SKW_FRAME = "BEAUTIFY_FRAME"; public const string SKW_FRAME_MASK = "BEAUTIFY_FRAME_MASK"; public const string SKW_DALTONIZE = "BEAUTIFY_DALTONIZE"; public const string SKW_DIRT = "BEAUTIFY_DIRT"; public const string SKW_VIGNETTING = "BEAUTIFY_VIGNETTING"; public const string SKW_VIGNETTING_MASK = "BEAUTIFY_VIGNETTING_MASK"; public const string SKW_DEPTH_OF_FIELD = "BEAUTIFY_DEPTH_OF_FIELD"; public const string SKW_DEPTH_OF_FIELD_TRANSPARENT = "BEAUTIFY_DEPTH_OF_FIELD_TRANSPARENT"; public const string SKW_EYE_ADAPTATION = "BEAUTIFY_EYE_ADAPTATION"; public const string SKW_TONEMAP_ACES = "BEAUTIFY_TONEMAP_ACES"; public const string SKW_PURKINJE = "BEAUTIFY_PURKINJE"; public const string SKW_BLOOM_USE_DEPTH = "BEAUTIFY_BLOOM_USE_DEPTH"; public const string SKW_BLOOM_USE_LAYER = "BEAUTIFY_BLOOM_USE_LAYER"; private Material bMatDesktop; private Material bMatMobile; private Material bMatBasic; [SerializeField] private Material bMat; private Camera currentCamera; private Vector3 camPrevForward; private Vector3 camPrevPos; private float currSens; private int renderPass; private RenderTextureFormat rtFormat; private RenderTexture[] rt; private RenderTexture[] rtAF; private RenderTexture[] rtEA; private RenderTexture rtEAacum; private RenderTexture rtEAHist; private float dofPrevDistance; private float dofLastAutofocusDistance; private Vector4 dofLastBokehData; private Camera sceneCamera; private Camera depthCam; private GameObject depthCamObj; private List shaderKeywords; private Shader depthShader; private Shader dofExclusionShader; private bool shouldUpdateMaterialProperties; private const string BEAUTIFY_BUILD_HINT = "BeautifyBuildHint700RC1"; private float sunFlareCurrentIntensity; private Vector4 sunLastScrPos; private float sunLastRot; private Texture2D flareNoise; private RenderTexture dofDepthTexture; private RenderTexture dofExclusionTexture; private RenderTexture bloomSourceTexture; private RenderTexture bloomSourceDepthTexture; private RenderTexture pixelateTexture; private RenderTextureDescriptor rtDescBase; private float sunFlareTime; private int dofCurrentLayerMaskValue; public BEAUTIFY_PRESET preset { get { return _preset; } set { if (_preset != value) { _preset = value; UpdateMaterialProperties(); } } } public BEAUTIFY_QUALITY quality { get { return _quality; } set { if (_quality != value) { _quality = value; UpdateQualitySettings(); UpdateMaterialProperties(); } } } public BeautifyProfile profile { get { return _profile; } set { if (_profile != value) { _profile = value; if (_profile != null) { _profile.Load(this); _preset = BEAUTIFY_PRESET.Custom; } } } } public bool compareMode { get { return _compareMode; } set { if (_compareMode != value) { _compareMode = value; UpdateMaterialProperties(); } } } public float compareLineAngle { get { return _compareLineAngle; } set { if (_compareLineAngle != value) { _compareLineAngle = value; UpdateMaterialProperties(); } } } public float compareLineWidth { get { return _compareLineWidth; } set { if (_compareLineWidth != value) { _compareLineWidth = value; UpdateMaterialProperties(); } } } public float dither { get { return _dither; } set { if (_dither != value) { _preset = BEAUTIFY_PRESET.Custom; _dither = value; UpdateMaterialProperties(); } } } public float ditherDepth { get { return _ditherDepth; } set { if (_ditherDepth != value) { _preset = BEAUTIFY_PRESET.Custom; _ditherDepth = value; UpdateMaterialProperties(); } } } public float sharpenMinDepth { get { return _sharpenMinDepth; } set { if (_sharpenMinDepth != value) { _sharpenMinDepth = value; UpdateMaterialProperties(); } } } public float sharpenMaxDepth { get { return _sharpenMaxDepth; } set { if (_sharpenMaxDepth != value) { _sharpenMaxDepth = value; UpdateMaterialProperties(); } } } public float sharpen { get { return _sharpen; } set { if (_sharpen != value) { _preset = BEAUTIFY_PRESET.Custom; _sharpen = value; UpdateMaterialProperties(); } } } public float sharpenDepthThreshold { get { return _sharpenDepthThreshold; } set { if (_sharpenDepthThreshold != value) { _preset = BEAUTIFY_PRESET.Custom; _sharpenDepthThreshold = value; UpdateMaterialProperties(); } } } public Color tintColor { get { return _tintColor; } set { if (_tintColor != value) { _tintColor = value; UpdateMaterialProperties(); } } } public float sharpenRelaxation { get { return _sharpenRelaxation; } set { if (_sharpenRelaxation != value) { _preset = BEAUTIFY_PRESET.Custom; _sharpenRelaxation = value; UpdateMaterialProperties(); } } } public float sharpenClamp { get { return _sharpenClamp; } set { if (_sharpenClamp != value) { _preset = BEAUTIFY_PRESET.Custom; _sharpenClamp = value; UpdateMaterialProperties(); } } } public float sharpenMotionSensibility { get { return _sharpenMotionSensibility; } set { if (_sharpenMotionSensibility != value) { _sharpenMotionSensibility = value; UpdateMaterialProperties(); } } } public float saturate { get { return _saturate; } set { if (_saturate != value) { _preset = BEAUTIFY_PRESET.Custom; _saturate = value; UpdateMaterialProperties(); } } } public float contrast { get { return _contrast; } set { if (_contrast != value) { _preset = BEAUTIFY_PRESET.Custom; _contrast = value; UpdateMaterialProperties(); } } } public float brightness { get { return _brightness; } set { if (_brightness != value) { _preset = BEAUTIFY_PRESET.Custom; _brightness = value; UpdateMaterialProperties(); } } } public float daltonize { get { return _daltonize; } set { if (_daltonize != value) { _preset = BEAUTIFY_PRESET.Custom; _daltonize = value; UpdateMaterialProperties(); } } } public bool vignetting { get { return _vignetting; } set { if (_vignetting != value) { _vignetting = value; UpdateMaterialProperties(); } } } public Color vignettingColor { get { return _vignettingColor; } set { if (_vignettingColor != value) { _vignettingColor = value; UpdateMaterialProperties(); } } } public float vignettingFade { get { return _vignettingFade; } set { if (_vignettingFade != value) { _vignettingFade = value; UpdateMaterialProperties(); } } } public bool vignettingCircularShape { get { return _vignettingCircularShape; } set { if (_vignettingCircularShape != value) { _vignettingCircularShape = value; UpdateMaterialProperties(); } } } public float vignettingAspectRatio { get { return _vignettingAspectRatio; } set { if (_vignettingAspectRatio != value) { _vignettingAspectRatio = value; UpdateMaterialProperties(); } } } public float vignettingBlink { get { return _vignettingBlink; } set { if (_vignettingBlink != value) { _vignettingBlink = value; UpdateMaterialProperties(); } } } public Texture2D vignettingMask { get { return _vignettingMask; } set { if (_vignettingMask != value) { _vignettingMask = value; UpdateMaterialProperties(); } } } public bool frame { get { return _frame; } set { if (_frame != value) { _frame = value; UpdateMaterialProperties(); } } } public Color frameColor { get { return _frameColor; } set { if (_frameColor != value) { _frameColor = value; UpdateMaterialProperties(); } } } public Texture2D frameMask { get { return _frameMask; } set { if (_frameMask != value) { _frameMask = value; UpdateMaterialProperties(); } } } public bool lut { get { return _lut; } set { if (_lut != value) { _lut = value; if (_lut) { _nightVision = false; _thermalVision = false; } UpdateMaterialProperties(); } } } public float lutIntensity { get { return _lutIntensity; } set { if (_lutIntensity != value) { _lutIntensity = value; UpdateMaterialProperties(); } } } public Texture2D lutTexture { get { return _lutTexture; } set { if (_lutTexture != value) { _lutTexture = value; UpdateMaterialProperties(); } } } public bool nightVision { get { return _nightVision; } set { if (_nightVision != value) { _nightVision = value; if (_nightVision) { _thermalVision = false; _lut = false; _vignetting = true; _vignettingFade = 0f; _vignettingColor = new Color(0f, 0f, 0f, 0.1254902f); _vignettingCircularShape = true; } else { _vignetting = false; } UpdateMaterialProperties(); } } } public Color nightVisionColor { get { return _nightVisionColor; } set { if (_nightVisionColor != value) { _nightVisionColor = value; UpdateMaterialProperties(); } } } public bool outline { get { return _outline; } set { if (_outline != value) { _outline = value; UpdateMaterialProperties(); } } } public Color outlineColor { get { return _outlineColor; } set { if (_outlineColor != value) { _outlineColor = value; UpdateMaterialProperties(); } } } public bool thermalVision { get { return _thermalVision; } set { if (_thermalVision != value) { _thermalVision = value; if (_thermalVision) { _nightVision = false; _lut = false; _vignetting = true; _vignettingFade = 0f; _vignettingColor = new Color(1f, 0.0627451f, 0.0627451f, 6f / 85f); _vignettingCircularShape = true; } else { _vignetting = false; } UpdateMaterialProperties(); } } } public bool lensDirt { get { return _lensDirt; } set { if (_lensDirt != value) { _lensDirt = value; UpdateMaterialProperties(); } } } public float lensDirtThreshold { get { return _lensDirtThreshold; } set { if (_lensDirtThreshold != value) { _lensDirtThreshold = value; UpdateMaterialProperties(); } } } public float lensDirtIntensity { get { return _lensDirtIntensity; } set { if (_lensDirtIntensity != value) { _lensDirtIntensity = value; UpdateMaterialProperties(); } } } public Texture2D lensDirtTexture { get { return _lensDirtTexture; } set { if (_lensDirtTexture != value) { _lensDirtTexture = value; UpdateMaterialProperties(); } } } public bool bloom { get { return _bloom; } set { if (_bloom != value) { _bloom = value; UpdateMaterialProperties(); } } } public LayerMask bloomCullingMask { get { return _bloomCullingMask; } set { if ((int)_bloomCullingMask != (int)value) { _bloomCullingMask = value; UpdateMaterialProperties(); } } } public float bloomLayerMaskDownsampling { get { return _bloomLayerMaskDownsampling; } set { if (_bloomLayerMaskDownsampling != value) { _bloomLayerMaskDownsampling = Mathf.Max(value, 1f); UpdateMaterialProperties(); } } } public float bloomIntensity { get { return _bloomIntensity; } set { if (_bloomIntensity != value) { _bloomIntensity = Mathf.Abs(value); UpdateMaterialProperties(); } } } public float bloomMaxBrightness { get { return _bloomMaxBrightness; } set { if (_bloomMaxBrightness != value) { _bloomMaxBrightness = Mathf.Abs(value); UpdateMaterialProperties(); } } } public float bloomBoost0 { get { return _bloomBoost0; } set { if (_bloomBoost0 != value) { _bloomBoost0 = value; UpdateMaterialProperties(); } } } public float bloomBoost1 { get { return _bloomBoost1; } set { if (_bloomBoost1 != value) { _bloomBoost1 = value; UpdateMaterialProperties(); } } } public float bloomBoost2 { get { return _bloomBoost2; } set { if (_bloomBoost2 != value) { _bloomBoost2 = value; UpdateMaterialProperties(); } } } public float bloomBoost3 { get { return _bloomBoost3; } set { if (_bloomBoost3 != value) { _bloomBoost3 = value; UpdateMaterialProperties(); } } } public float bloomBoost4 { get { return _bloomBoost4; } set { if (_bloomBoost4 != value) { _bloomBoost4 = value; UpdateMaterialProperties(); } } } public float bloomBoost5 { get { return _bloomBoost5; } set { if (_bloomBoost5 != value) { _bloomBoost5 = value; UpdateMaterialProperties(); } } } public bool bloomAntiflicker { get { return _bloomAntiflicker; } set { if (_bloomAntiflicker != value) { _bloomAntiflicker = value; UpdateMaterialProperties(); } } } public bool bloomUltra { get { return _bloomUltra; } set { if (_bloomUltra != value) { _bloomUltra = value; UpdateMaterialProperties(); } } } public float bloomThreshold { get { return _bloomThreshold; } set { if (_bloomThreshold != value) { _bloomThreshold = value; UpdateMaterialProperties(); } } } public bool bloomCustomize { get { return _bloomCustomize; } set { if (_bloomCustomize != value) { _bloomCustomize = value; UpdateMaterialProperties(); } } } public bool bloomDebug { get { return _bloomDebug; } set { if (_bloomDebug != value) { _bloomDebug = value; UpdateMaterialProperties(); } } } public float bloomWeight0 { get { return _bloomWeight0; } set { if (_bloomWeight0 != value) { _bloomWeight0 = value; UpdateMaterialProperties(); } } } public float bloomWeight1 { get { return _bloomWeight1; } set { if (_bloomWeight1 != value) { _bloomWeight1 = value; UpdateMaterialProperties(); } } } public float bloomWeight2 { get { return _bloomWeight2; } set { if (_bloomWeight2 != value) { _bloomWeight2 = value; UpdateMaterialProperties(); } } } public float bloomWeight3 { get { return _bloomWeight3; } set { if (_bloomWeight3 != value) { _bloomWeight3 = value; UpdateMaterialProperties(); } } } public float bloomWeight4 { get { return _bloomWeight4; } set { if (_bloomWeight4 != value) { _bloomWeight4 = value; UpdateMaterialProperties(); } } } public float bloomWeight5 { get { return _bloomWeight5; } set { if (_bloomWeight5 != value) { _bloomWeight5 = value; UpdateMaterialProperties(); } } } public bool bloomBlur { get { return _bloomBlur; } set { if (_bloomBlur != value) { _bloomBlur = value; UpdateMaterialProperties(); } } } public float bloomDepthAtten { get { return _bloomDepthAtten; } set { if (_bloomDepthAtten != value) { _bloomDepthAtten = value; UpdateMaterialProperties(); } } } public float bloomLayerZBias { get { return _bloomLayerZBias; } set { if (_bloomLayerZBias != value) { _bloomLayerZBias = Mathf.Clamp(value, -1f, 1f); UpdateMaterialProperties(); } } } public bool anamorphicFlares { get { return _anamorphicFlares; } set { if (_anamorphicFlares != value) { _anamorphicFlares = value; UpdateMaterialProperties(); } } } public float anamorphicFlaresIntensity { get { return _anamorphicFlaresIntensity; } set { if (_anamorphicFlaresIntensity != value) { _anamorphicFlaresIntensity = Mathf.Abs(value); UpdateMaterialProperties(); } } } public bool anamorphicFlaresAntiflicker { get { return _anamorphicFlaresAntiflicker; } set { if (_anamorphicFlaresAntiflicker != value) { _anamorphicFlaresAntiflicker = value; UpdateMaterialProperties(); } } } public bool anamorphicFlaresUltra { get { return _anamorphicFlaresUltra; } set { if (_anamorphicFlaresUltra != value) { _anamorphicFlaresUltra = value; UpdateMaterialProperties(); } } } public float anamorphicFlaresThreshold { get { return _anamorphicFlaresThreshold; } set { if (_anamorphicFlaresThreshold != value) { _anamorphicFlaresThreshold = value; UpdateMaterialProperties(); } } } public float anamorphicFlaresSpread { get { return _anamorphicFlaresSpread; } set { if (_anamorphicFlaresSpread != value) { _anamorphicFlaresSpread = value; UpdateMaterialProperties(); } } } public bool anamorphicFlaresVertical { get { return _anamorphicFlaresVertical; } set { if (_anamorphicFlaresVertical != value) { _anamorphicFlaresVertical = value; UpdateMaterialProperties(); } } } public Color anamorphicFlaresTint { get { return _anamorphicFlaresTint; } set { if (_anamorphicFlaresTint != value) { _anamorphicFlaresTint = value; UpdateMaterialProperties(); } } } public bool anamorphicFlaresBlur { get { return _anamorphicFlaresBlur; } set { if (_anamorphicFlaresBlur != value) { _anamorphicFlaresBlur = value; UpdateMaterialProperties(); } } } public bool depthOfField { get { return _depthOfField; } set { if (_depthOfField != value) { _depthOfField = value; UpdateMaterialProperties(); } } } public bool depthOfFieldTransparencySupport { get { return _depthOfFieldTransparencySupport; } set { if (_depthOfFieldTransparencySupport != value) { _depthOfFieldTransparencySupport = value; UpdateMaterialProperties(); } } } public LayerMask depthOfFieldTransparencyLayerMask { get { return _depthOfFieldTransparencyLayerMask; } set { if ((int)_depthOfFieldTransparencyLayerMask != (int)value) { _depthOfFieldTransparencyLayerMask = value; UpdateMaterialProperties(); } } } public Transform depthOfFieldTargetFocus { get { return _depthOfFieldTargetFocus; } set { if (_depthOfFieldTargetFocus != value) { _depthOfFieldTargetFocus = value; UpdateMaterialProperties(); } } } public bool depthOfFieldDebug { get { return _depthOfFieldDebug; } set { if (_depthOfFieldDebug != value) { _depthOfFieldDebug = value; UpdateMaterialProperties(); } } } public bool depthOfFieldAutofocus { get { return _depthOfFieldAutofocus; } set { if (_depthOfFieldAutofocus != value) { _depthOfFieldAutofocus = value; UpdateMaterialProperties(); } } } public Vector2 depthofFieldAutofocusViewportPoint { get { return _depthofFieldAutofocusViewportPoint; } set { if (_depthofFieldAutofocusViewportPoint != value) { _depthofFieldAutofocusViewportPoint = value; UpdateMaterialProperties(); } } } public float depthOfFieldAutofocusMinDistance { get { return _depthOfFieldAutofocusMinDistance; } set { if (_depthOfFieldAutofocusMinDistance != value) { _depthOfFieldAutofocusMinDistance = value; UpdateMaterialProperties(); } } } public float depthOfFieldAutofocusMaxDistance { get { return _depthOfFieldAutofocusMaxDistance; } set { if (_depthOfFieldAutofocusMaxDistance != value) { _depthOfFieldAutofocusMaxDistance = value; UpdateMaterialProperties(); } } } public LayerMask depthOfFieldAutofocusLayerMask { get { return _depthOfFieldAutofocusLayerMask; } set { if ((int)_depthOfFieldAutofocusLayerMask != (int)value) { _depthOfFieldAutofocusLayerMask = value; UpdateMaterialProperties(); } } } public LayerMask depthOfFieldExclusionLayerMask { get { return _depthOfFieldExclusionLayerMask; } set { if ((int)_depthOfFieldExclusionLayerMask != (int)value) { _depthOfFieldExclusionLayerMask = value; UpdateMaterialProperties(); } } } public float depthOfFieldExclusionLayerMaskDownsampling { get { return _depthOfFieldExclusionLayerMaskDownsampling; } set { if (_depthOfFieldExclusionLayerMaskDownsampling != value) { _depthOfFieldExclusionLayerMaskDownsampling = Mathf.Max(value, 1f); UpdateMaterialProperties(); } } } public float depthOfFieldTransparencySupportDownsampling { get { return _depthOfFieldTransparencySupportDownsampling; } set { if (_depthOfFieldTransparencySupportDownsampling != value) { _depthOfFieldTransparencySupportDownsampling = Mathf.Max(value, 1f); UpdateMaterialProperties(); } } } public float depthOfFieldExclusionBias { get { return _depthOfFieldExclusionBias; } set { if (_depthOfFieldExclusionBias != value) { _depthOfFieldExclusionBias = Mathf.Clamp01(value); UpdateMaterialProperties(); } } } public float depthOfFieldDistance { get { return _depthOfFieldDistance; } set { if (_depthOfFieldDistance != value) { _depthOfFieldDistance = Mathf.Max(value, 1f); UpdateMaterialProperties(); } } } public float depthOfFieldFocusSpeed { get { return _depthOfFieldFocusSpeed; } set { if (_depthOfFieldFocusSpeed != value) { _depthOfFieldFocusSpeed = Mathf.Clamp(value, 0.001f, 1f); UpdateMaterialProperties(); } } } public int depthOfFieldDownsampling { get { return _depthOfFieldDownsampling; } set { if (_depthOfFieldDownsampling != value) { _depthOfFieldDownsampling = Mathf.Max(value, 1); UpdateMaterialProperties(); } } } public int depthOfFieldMaxSamples { get { return _depthOfFieldMaxSamples; } set { if (_depthOfFieldMaxSamples != value) { _depthOfFieldMaxSamples = Mathf.Max(value, 2); UpdateMaterialProperties(); } } } public float depthOfFieldFocalLength { get { return _depthOfFieldFocalLength; } set { if (_depthOfFieldFocalLength != value) { _depthOfFieldFocalLength = Mathf.Abs(value); UpdateMaterialProperties(); } } } public float depthOfFieldAperture { get { return _depthOfFieldAperture; } set { if (_depthOfFieldAperture != value) { _depthOfFieldAperture = Mathf.Abs(value); UpdateMaterialProperties(); } } } public bool depthOfFieldForegroundBlur { get { return _depthOfFieldForegroundBlur; } set { if (_depthOfFieldForegroundBlur != value) { _depthOfFieldForegroundBlur = value; UpdateMaterialProperties(); } } } public bool depthOfFieldForegroundBlurHQ { get { return _depthOfFieldForegroundBlurHQ; } set { if (_depthOfFieldForegroundBlurHQ != value) { _depthOfFieldForegroundBlurHQ = value; UpdateMaterialProperties(); } } } public float depthOfFieldForegroundDistance { get { return _depthOfFieldForegroundDistance; } set { if (_depthOfFieldForegroundDistance != value) { _depthOfFieldForegroundDistance = value; UpdateMaterialProperties(); } } } public bool depthOfFieldBokeh { get { return _depthOfFieldBokeh; } set { if (_depthOfFieldBokeh != value) { _depthOfFieldBokeh = value; UpdateMaterialProperties(); } } } public float depthOfFieldBokehThreshold { get { return _depthOfFieldBokehThreshold; } set { if (_depthOfFieldBokehThreshold != value) { _depthOfFieldBokehThreshold = Mathf.Max(value, 0f); UpdateMaterialProperties(); } } } public float depthOfFieldBokehIntensity { get { return _depthOfFieldBokehIntensity; } set { if (_depthOfFieldBokehIntensity != value) { _depthOfFieldBokehIntensity = Mathf.Max(value, 0f); UpdateMaterialProperties(); } } } public float depthOfFieldMaxBrightness { get { return _depthOfFieldMaxBrightness; } set { if (_depthOfFieldMaxBrightness != value) { _depthOfFieldMaxBrightness = Mathf.Abs(value); UpdateMaterialProperties(); } } } public float depthOfFieldMaxDistance { get { return _depthOfFieldMaxDistance; } set { if (_depthOfFieldMaxDistance != value) { _depthOfFieldMaxDistance = Mathf.Abs(value); UpdateMaterialProperties(); } } } public FilterMode depthOfFieldFilterMode { get { return _depthOfFieldFilterMode; } set { if (_depthOfFieldFilterMode != value) { _depthOfFieldFilterMode = value; UpdateMaterialProperties(); } } } public bool eyeAdaptation { get { return _eyeAdaptation; } set { if (_eyeAdaptation != value) { _eyeAdaptation = value; UpdateMaterialProperties(); } } } public float eyeAdaptationMinExposure { get { return _eyeAdaptationMinExposure; } set { if (_eyeAdaptationMinExposure != value) { _eyeAdaptationMinExposure = Mathf.Clamp01(value); UpdateMaterialProperties(); } } } public float eyeAdaptationMaxExposure { get { return _eyeAdaptationMaxExposure; } set { if (_eyeAdaptationMaxExposure != value) { _eyeAdaptationMaxExposure = Mathf.Clamp(value, 1f, 100f); UpdateMaterialProperties(); } } } public float eyeAdaptationSpeedToLight { get { return _eyeAdaptationSpeedToLight; } set { if (_eyeAdaptationSpeedToLight != value) { _eyeAdaptationSpeedToLight = Mathf.Clamp01(value); UpdateMaterialProperties(); } } } public float eyeAdaptationSpeedToDark { get { return _eyeAdaptationSpeedToDark; } set { if (_eyeAdaptationSpeedToDark != value) { _eyeAdaptationSpeedToDark = Mathf.Clamp01(value); UpdateMaterialProperties(); } } } public bool purkinje { get { return _purkinje; } set { if (_purkinje != value) { _purkinje = value; UpdateMaterialProperties(); } } } public float purkinjeAmount { get { return _purkinjeAmount; } set { if (_purkinjeAmount != value) { _purkinjeAmount = Mathf.Clamp(value, 0f, 5f); UpdateMaterialProperties(); } } } public float purkinjeLuminanceThreshold { get { return _purkinjeLuminanceThreshold; } set { if (purkinjeLuminanceThreshold != value) { _purkinjeLuminanceThreshold = Mathf.Clamp(value, 0f, 1f); UpdateMaterialProperties(); } } } public BEAUTIFY_TMO tonemap { get { return _tonemap; } set { if (_tonemap != value) { _tonemap = value; if (_tonemap == BEAUTIFY_TMO.ACES) { _saturate = 0f; _contrast = 1f; } UpdateMaterialProperties(); } } } public bool sunFlares { get { return _sunFlares; } set { if (_sunFlares != value) { _sunFlares = value; UpdateMaterialProperties(); } } } public Transform sun { get { return _sun; } set { if (_sun != value) { _sun = value; UpdateMaterialProperties(); } } } public LayerMask sunFlaresLayerMask { get { return _sunFlaresLayerMask; } set { if ((int)_sunFlaresLayerMask != (int)value) { _sunFlaresLayerMask = value; UpdateMaterialProperties(); } } } public float sunFlaresIntensity { get { return _sunFlaresIntensity; } set { if (_sunFlaresIntensity != value) { _sunFlaresIntensity = value; UpdateMaterialProperties(); } } } public float sunFlaresSolarWindSpeed { get { return _sunFlaresSolarWindSpeed; } set { if (_sunFlaresSolarWindSpeed != value) { _sunFlaresSolarWindSpeed = value; UpdateMaterialProperties(); } } } public Color sunFlaresTint { get { return _sunFlaresTint; } set { if (_sunFlaresTint != value) { _sunFlaresTint = value; UpdateMaterialProperties(); } } } public int sunFlaresDownsampling { get { return _sunFlaresDownsampling; } set { if (_sunFlaresDownsampling != value) { _sunFlaresDownsampling = Mathf.Max(value, 1); UpdateMaterialProperties(); } } } public float sunFlaresSunIntensity { get { return _sunFlaresSunIntensity; } set { if (_sunFlaresSunIntensity != value) { _sunFlaresSunIntensity = value; UpdateMaterialProperties(); } } } public float sunFlaresSunDiskSize { get { return _sunFlaresSunDiskSize; } set { if (_sunFlaresSunDiskSize != value) { _sunFlaresSunDiskSize = value; UpdateMaterialProperties(); } } } public float sunFlaresSunRayDiffractionIntensity { get { return _sunFlaresSunRayDiffractionIntensity; } set { if (_sunFlaresSunRayDiffractionIntensity != value) { _sunFlaresSunRayDiffractionIntensity = value; UpdateMaterialProperties(); } } } public float sunFlaresSunRayDiffractionThreshold { get { return _sunFlaresSunRayDiffractionThreshold; } set { if (_sunFlaresSunRayDiffractionThreshold != value) { _sunFlaresSunRayDiffractionThreshold = value; UpdateMaterialProperties(); } } } public float sunFlaresCoronaRays1Length { get { return _sunFlaresCoronaRays1Length; } set { if (_sunFlaresCoronaRays1Length != value) { _sunFlaresCoronaRays1Length = value; UpdateMaterialProperties(); } } } public int sunFlaresCoronaRays1Streaks { get { return _sunFlaresCoronaRays1Streaks; } set { if (_sunFlaresCoronaRays1Streaks != value) { _sunFlaresCoronaRays1Streaks = value; UpdateMaterialProperties(); } } } public float sunFlaresCoronaRays1Spread { get { return _sunFlaresCoronaRays1Spread; } set { if (_sunFlaresCoronaRays1Spread != value) { _sunFlaresCoronaRays1Spread = value; UpdateMaterialProperties(); } } } public float sunFlaresCoronaRays1AngleOffset { get { return _sunFlaresCoronaRays1AngleOffset; } set { if (_sunFlaresCoronaRays1AngleOffset != value) { _sunFlaresCoronaRays1AngleOffset = value; UpdateMaterialProperties(); } } } public float sunFlaresCoronaRays2Length { get { return _sunFlaresCoronaRays2Length; } set { if (_sunFlaresCoronaRays2Length != value) { _sunFlaresCoronaRays2Length = value; UpdateMaterialProperties(); } } } public int sunFlaresCoronaRays2Streaks { get { return _sunFlaresCoronaRays2Streaks; } set { if (_sunFlaresCoronaRays2Streaks != value) { _sunFlaresCoronaRays2Streaks = value; UpdateMaterialProperties(); } } } public float sunFlaresCoronaRays2Spread { get { return _sunFlaresCoronaRays2Spread; } set { if (_sunFlaresCoronaRays2Spread != value) { _sunFlaresCoronaRays2Spread = value; UpdateMaterialProperties(); } } } public float sunFlaresCoronaRays2AngleOffset { get { return _sunFlaresCoronaRays2AngleOffset; } set { if (_sunFlaresCoronaRays2AngleOffset != value) { _sunFlaresCoronaRays2AngleOffset = value; UpdateMaterialProperties(); } } } public float sunFlaresGhosts1Size { get { return _sunFlaresGhosts1Size; } set { if (_sunFlaresGhosts1Size != value) { _sunFlaresGhosts1Size = value; UpdateMaterialProperties(); } } } public float sunFlaresGhosts1Offset { get { return _sunFlaresGhosts1Offset; } set { if (_sunFlaresGhosts1Offset != value) { _sunFlaresGhosts1Offset = value; UpdateMaterialProperties(); } } } public float sunFlaresGhosts1Brightness { get { return _sunFlaresGhosts1Brightness; } set { if (_sunFlaresGhosts1Brightness != value) { _sunFlaresGhosts1Brightness = value; UpdateMaterialProperties(); } } } public float sunFlaresGhosts2Size { get { return _sunFlaresGhosts2Size; } set { if (_sunFlaresGhosts2Size != value) { _sunFlaresGhosts2Size = value; UpdateMaterialProperties(); } } } public float sunFlaresGhosts2Offset { get { return _sunFlaresGhosts2Offset; } set { if (_sunFlaresGhosts2Offset != value) { _sunFlaresGhosts2Offset = value; UpdateMaterialProperties(); } } } public float sunFlaresGhosts2Brightness { get { return _sunFlaresGhosts2Brightness; } set { if (_sunFlaresGhosts2Brightness != value) { _sunFlaresGhosts2Brightness = value; UpdateMaterialProperties(); } } } public float sunFlaresGhosts3Size { get { return _sunFlaresGhosts3Size; } set { if (_sunFlaresGhosts3Size != value) { _sunFlaresGhosts3Size = value; UpdateMaterialProperties(); } } } public float sunFlaresGhosts3Brightness { get { return _sunFlaresGhosts3Brightness; } set { if (_sunFlaresGhosts3Brightness != value) { _sunFlaresGhosts3Brightness = value; UpdateMaterialProperties(); } } } public float sunFlaresGhosts3Offset { get { return _sunFlaresGhosts3Offset; } set { if (_sunFlaresGhosts3Offset != value) { _sunFlaresGhosts3Offset = value; UpdateMaterialProperties(); } } } public float sunFlaresGhosts4Size { get { return _sunFlaresGhosts4Size; } set { if (_sunFlaresGhosts4Size != value) { _sunFlaresGhosts4Size = value; UpdateMaterialProperties(); } } } public float sunFlaresGhosts4Offset { get { return _sunFlaresGhosts4Offset; } set { if (_sunFlaresGhosts4Offset != value) { _sunFlaresGhosts4Offset = value; UpdateMaterialProperties(); } } } public float sunFlaresGhosts4Brightness { get { return _sunFlaresGhosts4Brightness; } set { if (_sunFlaresGhosts4Brightness != value) { _sunFlaresGhosts4Brightness = value; UpdateMaterialProperties(); } } } public float sunFlaresHaloOffset { get { return _sunFlaresHaloOffset; } set { if (_sunFlaresHaloOffset != value) { _sunFlaresHaloOffset = value; UpdateMaterialProperties(); } } } public float sunFlaresHaloAmplitude { get { return _sunFlaresHaloAmplitude; } set { if (_sunFlaresHaloAmplitude != value) { _sunFlaresHaloAmplitude = value; UpdateMaterialProperties(); } } } public float sunFlaresHaloIntensity { get { return _sunFlaresHaloIntensity; } set { if (_sunFlaresHaloIntensity != value) { _sunFlaresHaloIntensity = value; UpdateMaterialProperties(); } } } public bool sunFlaresRotationDeadZone { get { return _sunFlaresRotationDeadZone; } set { if (_sunFlaresRotationDeadZone != value) { _sunFlaresRotationDeadZone = value; UpdateMaterialProperties(); } } } public bool blur { get { return _blur; } set { if (_blur != value) { _blur = value; UpdateMaterialProperties(); } } } public float blurIntensity { get { return _blurIntensity; } set { if (_blurIntensity != value) { _blurIntensity = value; UpdateMaterialProperties(); } } } public int pixelateAmount { get { return _pixelateAmount; } set { if (_pixelateAmount != value) { _pixelateAmount = value; UpdateMaterialProperties(); } } } public bool pixelateDownscale { get { return _pixelateDownscale; } set { if (_pixelateDownscale != value) { _pixelateDownscale = value; UpdateMaterialProperties(); } } } public float antialiasStrength { get { return _antialiasStrength; } set { if (_antialiasStrength != value) { _antialiasStrength = value; UpdateMaterialProperties(); } } } public float antialiasDepthThreshold { get { return _antialiasDepthThreshold; } set { if (_antialiasDepthThreshold != value) { _antialiasDepthThreshold = value; UpdateMaterialProperties(); } } } public static Beautify instance { get { if (_beautify == null) { Camera[] allCameras = Camera.allCameras; foreach (Camera camera in allCameras) { _beautify = camera.GetComponent(); if (_beautify != null) { break; } } } return _beautify; } } public Camera cameraEffect { get { return currentCamera; } } public float depthOfFieldCurrentFocalPointDistance { get { return dofLastAutofocusDistance; } } private void OnEnable() { currentCamera = GetComponent(); if (_profile != null) { _profile.Load(this); } UpdateMaterialPropertiesNow(); } private void OnDestroy() { CleanUpRT(); if (depthCamObj != null) { UnityEngine.Object.DestroyImmediate(depthCamObj); depthCamObj = null; } if (rtEAacum != null) { rtEAacum.Release(); } if (rtEAHist != null) { rtEAHist.Release(); } if (bMatDesktop != null) { UnityEngine.Object.DestroyImmediate(bMatDesktop); bMatDesktop = null; } if (bMatMobile != null) { UnityEngine.Object.DestroyImmediate(bMatMobile); bMatMobile = null; } if (bMatBasic != null) { UnityEngine.Object.DestroyImmediate(bMatBasic); bMatBasic = null; } bMat = null; } private void Reset() { UpdateMaterialPropertiesNow(); } private void LateUpdate() { if (bMat == null || !Application.isPlaying || _sharpenMotionSensibility <= 0f) { return; } float num = Vector3.Angle(camPrevForward, currentCamera.transform.forward) * _sharpenMotionSensibility; float num2 = (currentCamera.transform.position - camPrevPos).sqrMagnitude * 10f * _sharpenMotionSensibility; float num3 = num + num2; if (num3 > 0.1f) { camPrevForward = currentCamera.transform.forward; camPrevPos = currentCamera.transform.position; if (num3 > _sharpenMotionSensibility) { num3 = _sharpenMotionSensibility; } currSens += num3; float min = _sharpen * _sharpenMotionSensibility * 0.75f; float max = _sharpen * (1f + _sharpenMotionSensibility) * 0.5f; currSens = Mathf.Clamp(currSens, min, max); } else { if (currSens <= 0.001f) { return; } currSens *= 0.75f; } float num4 = Mathf.Clamp(_sharpen - currSens, 0f, _sharpen); UpdateSharpenParams(num4); } private void OnPreCull() { bool flag = (_bloom || _anamorphicFlares) && (int)_bloomCullingMask != 0; if (base.enabled && base.gameObject.activeSelf && !(currentCamera == null) && !(bMat == null) && (_depthOfField || flag)) { CleanUpRT(); if (dofCurrentLayerMaskValue != _depthOfFieldExclusionLayerMask.value) { shouldUpdateMaterialProperties = true; } if (depthOfField && (_depthOfFieldTransparencySupport || (int)_depthOfFieldExclusionLayerMask != 0)) { CheckDoFTransparencySupport(); CheckDoFExclusionMask(); } if (flag) { CheckBloomCullingLayer(); } } } private void OnPreRender() { if (_pixelateDownscale && _pixelateAmount > 1 && rtDescBase.width > 1 && rtDescBase.height > 1) { RenderTextureDescriptor desc = rtDescBase; desc.width = Mathf.RoundToInt(Mathf.Max(1, currentCamera.pixelWidth / _pixelateAmount)); float num = (float)currentCamera.pixelHeight / (float)currentCamera.pixelWidth; desc.height = Mathf.Max(1, Mathf.RoundToInt((float)desc.width * num)); pixelateTexture = RenderTexture.GetTemporary(desc); currentCamera.targetTexture = pixelateTexture; } } private void CleanUpRT() { if (dofDepthTexture != null) { RenderTexture.ReleaseTemporary(dofDepthTexture); dofDepthTexture = null; } if (dofExclusionTexture != null) { RenderTexture.ReleaseTemporary(dofExclusionTexture); dofExclusionTexture = null; } if (bloomSourceTexture != null) { RenderTexture.ReleaseTemporary(bloomSourceTexture); bloomSourceTexture = null; } if (bloomSourceDepthTexture != null) { RenderTexture.ReleaseTemporary(bloomSourceDepthTexture); bloomSourceDepthTexture = null; } if (pixelateTexture != null) { RenderTexture.ReleaseTemporary(pixelateTexture); pixelateTexture = null; } } private void CheckDoFTransparencySupport() { if (depthCam == null) { if (depthCamObj == null) { depthCamObj = new GameObject("DepthCamera"); depthCamObj.hideFlags = HideFlags.HideAndDontSave; depthCam = depthCamObj.AddComponent(); depthCam.enabled = false; } else { depthCam = depthCamObj.GetComponent(); if (depthCam == null) { UnityEngine.Object.DestroyImmediate(depthCamObj); depthCamObj = null; return; } } } depthCam.CopyFrom(currentCamera); depthCam.rect = new Rect(0f, 0f, 1f, 1f); depthCam.depthTextureMode = DepthTextureMode.None; depthCam.renderingPath = RenderingPath.Forward; float num = _depthOfFieldTransparencySupportDownsampling * (float)_depthOfFieldDownsampling; dofDepthTexture = RenderTexture.GetTemporary((int)((float)currentCamera.pixelWidth / num), (int)((float)currentCamera.pixelHeight / num), 16, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); dofDepthTexture.filterMode = FilterMode.Point; depthCam.backgroundColor = new Color(84f / 85f, 0.4470558f, 0.75f, 0f); depthCam.clearFlags = CameraClearFlags.Color; depthCam.targetTexture = dofDepthTexture; depthCam.cullingMask = _depthOfFieldTransparencyLayerMask; if (depthShader == null) { depthShader = Shader.Find("Beautify/CopyDepth"); } depthCam.RenderWithShader(depthShader, "RenderType"); bMat.SetTexture("_DepthTexture", dofDepthTexture); } private void CheckDoFExclusionMask() { if (depthCam == null) { if (depthCamObj == null) { depthCamObj = new GameObject("DepthCamera"); depthCamObj.hideFlags = HideFlags.HideAndDontSave; depthCam = depthCamObj.AddComponent(); depthCam.enabled = false; } else { depthCam = depthCamObj.GetComponent(); if (depthCam == null) { UnityEngine.Object.DestroyImmediate(depthCamObj); depthCamObj = null; return; } } } depthCam.CopyFrom(currentCamera); depthCam.rect = new Rect(0f, 0f, 1f, 1f); depthCam.depthTextureMode = DepthTextureMode.None; depthCam.renderingPath = RenderingPath.Forward; float num = _depthOfFieldExclusionLayerMaskDownsampling * (float)_depthOfFieldDownsampling; dofExclusionTexture = RenderTexture.GetTemporary((int)((float)currentCamera.pixelWidth / num), (int)((float)currentCamera.pixelHeight / num), 16, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); dofExclusionTexture.filterMode = FilterMode.Point; depthCam.backgroundColor = new Color(84f / 85f, 0.4470558f, 0.75f, 0f); depthCam.clearFlags = CameraClearFlags.Color; depthCam.targetTexture = dofExclusionTexture; depthCam.cullingMask = _depthOfFieldExclusionLayerMask; if (dofExclusionShader == null) { dofExclusionShader = Shader.Find("Beautify/CopyDepthBiased"); } depthCam.RenderWithShader(dofExclusionShader, null); bMat.SetTexture("_DofExclusionTexture", dofExclusionTexture); } private void CheckBloomCullingLayer() { if (depthCam == null) { if (depthCamObj == null) { depthCamObj = new GameObject("DepthCamera"); depthCamObj.hideFlags = HideFlags.HideAndDontSave; depthCam = depthCamObj.AddComponent(); depthCam.enabled = false; } else { depthCam = depthCamObj.GetComponent(); if (depthCam == null) { UnityEngine.Object.DestroyImmediate(depthCamObj); depthCamObj = null; return; } } } depthCam.CopyFrom(currentCamera); depthCam.rect = new Rect(0f, 0f, 1f, 1f); depthCam.depthTextureMode = DepthTextureMode.None; depthCam.allowMSAA = false; depthCam.allowHDR = false; int num; if (_quality == BEAUTIFY_QUALITY.BestPerformance) { num = 256; } else { num = ((!_bloomUltra) ? 512 : (currentCamera.pixelHeight / 4 * 4)); num = (int)((float)num * (1f / _bloomLayerMaskDownsampling) / 4f) * 4; } float num2 = (float)currentCamera.pixelHeight / (float)currentCamera.pixelWidth; bloomSourceTexture = RenderTexture.GetTemporary(num, Mathf.Max(1, (int)((float)num * num2)), 0, rtFormat); bloomSourceDepthTexture = RenderTexture.GetTemporary(bloomSourceTexture.width, bloomSourceTexture.height, 24, RenderTextureFormat.Depth); depthCam.clearFlags = CameraClearFlags.Color; depthCam.stereoTargetEye = StereoTargetEyeMask.None; depthCam.renderingPath = RenderingPath.Forward; depthCam.backgroundColor = Color.black; depthCam.SetTargetBuffers(bloomSourceTexture.colorBuffer, bloomSourceDepthTexture.depthBuffer); depthCam.cullingMask = _bloomCullingMask; depthCam.Render(); bMat.SetTexture("_BloomSourceTex", bloomSourceTexture); bMat.SetTexture("_BloomSourceDepth", bloomSourceDepthTexture); } protected virtual void OnRenderImage(RenderTexture source, RenderTexture destination) { if (bMat == null || !base.enabled) { Graphics.Blit(source, destination); return; } if (shouldUpdateMaterialProperties) { UpdateMaterialPropertiesNow(); } bool flag = _quality != BEAUTIFY_QUALITY.Basic; rtDescBase = source.descriptor; rtDescBase.msaaSamples = 1; rtDescBase.colorFormat = rtFormat; rtDescBase.depthBufferBits = 0; RenderTexture renderTexture = null; RenderTexture renderTexture2 = null; RenderTexture renderTexture3 = null; float num = (float)source.height / (float)source.width; bool flag2 = _blur && _blurIntensity > 0f && flag; if (renderPass == 0 || flag2) { if (flag2) { int num2; if (_blurIntensity < 1f) { num2 = (int)Mathf.Lerp(currentCamera.pixelWidth, 512f, _blurIntensity); if (_quality == BEAUTIFY_QUALITY.BestPerformance) { num2 /= 2; } } else { num2 = ((_quality != BEAUTIFY_QUALITY.BestQuality) ? 256 : 512); num2 = (int)((float)num2 / _blurIntensity); } RenderTextureDescriptor desc = rtDescBase; desc.width = num2; desc.height = Mathf.Max(1, (int)((float)num2 * num)); renderTexture2 = RenderTexture.GetTemporary(desc); if (renderPass == 0) { renderTexture = RenderTexture.GetTemporary(desc); } } else { renderTexture = RenderTexture.GetTemporary(rtDescBase); } } RenderTexture renderTexture4 = null; RenderTexture renderTexture5 = null; if (flag) { if (_pixelateAmount > 1) { source.filterMode = FilterMode.Point; if (!_pixelateDownscale) { RenderTextureDescriptor desc2 = rtDescBase; desc2.width = Mathf.RoundToInt(Mathf.Max(1, source.width / _pixelateAmount)); desc2.height = Mathf.Max(1, Mathf.RoundToInt((float)desc2.width * num)); renderTexture4 = RenderTexture.GetTemporary(desc2); renderTexture4.filterMode = FilterMode.Point; Graphics.Blit(source, renderTexture4, bMat, (_quality != BEAUTIFY_QUALITY.BestQuality) ? 18 : 22); source = renderTexture4; } } if (_depthOfField) { UpdateDepthOfFieldData(); int pass = ((_quality != BEAUTIFY_QUALITY.BestQuality) ? 6 : 12); RenderTextureDescriptor desc3 = rtDescBase; desc3.width = source.width / _depthOfFieldDownsampling; desc3.height = source.height / _depthOfFieldDownsampling; renderTexture5 = RenderTexture.GetTemporary(desc3); renderTexture5.filterMode = _depthOfFieldFilterMode; Graphics.Blit(source, renderTexture5, bMat, pass); pass = ((_quality != BEAUTIFY_QUALITY.BestQuality) ? ((!_depthOfFieldBokeh) ? 15 : 8) : ((!_depthOfFieldBokeh) ? 19 : 14)); if (_quality == BEAUTIFY_QUALITY.BestQuality && _depthOfFieldForegroundBlur && _depthOfFieldForegroundBlurHQ) { BlurThisAlpha(renderTexture5, 16f); } BlurThisDoF(renderTexture5, pass); if (_depthOfFieldDebug) { source.MarkRestoreExpected(); pass = ((_quality != BEAUTIFY_QUALITY.BestQuality) ? 7 : 13); Graphics.Blit(renderTexture5, destination, bMat, pass); RenderTexture.ReleaseTemporary(renderTexture5); return; } bMat.SetTexture("_DoFTex", renderTexture5); } } bool flag3 = _sunFlares && _sun != null; if (flag && (_lensDirt || _bloom || _anamorphicFlares || flag3)) { RenderTexture renderTexture6 = null; int num3; int num4; if (_quality == BEAUTIFY_QUALITY.BestPerformance) { num3 = 4; num4 = 256; } else { num3 = 5; num4 = ((!_bloomUltra) ? 512 : (source.height / 4 * 4)); } if (rt == null || rt.Length != num3 + 1) { rt = new RenderTexture[num3 + 1]; } if (rtAF == null || rtAF.Length != num3 + 1) { rtAF = new RenderTexture[num3 + 1]; } if (_bloom || (_lensDirt && !_anamorphicFlares)) { UpdateMaterialBloomIntensityAndThreshold(); RenderTextureDescriptor desc4 = rtDescBase; for (int i = 0; i <= num3; i++) { desc4.width = num4; desc4.height = Mathf.Max(1, (int)((float)num4 * num)); rt[i] = RenderTexture.GetTemporary(desc4); num4 /= 2; } renderTexture6 = rt[0]; if (_quality == BEAUTIFY_QUALITY.BestQuality && _bloomAntiflicker) { Graphics.Blit(source, rt[0], bMat, 9); } else { Graphics.Blit(source, rt[0], bMat, 2); } BlurThis(rt[0]); for (int j = 0; j < num3; j++) { if (_quality == BEAUTIFY_QUALITY.BestPerformance) { if (_bloomBlur) { BlurThisDownscaling(rt[j], rt[j + 1]); } else { Graphics.Blit(rt[j], rt[j + 1], bMat, 18); } } else { Graphics.Blit(rt[j], rt[j + 1], bMat, 7); BlurThis(rt[j + 1]); } } if (_bloom) { for (int num5 = num3; num5 > 0; num5--) { rt[num5 - 1].MarkRestoreExpected(); Graphics.Blit(rt[num5], rt[num5 - 1], bMat, (_quality != BEAUTIFY_QUALITY.BestQuality) ? 13 : 8); } if (quality == BEAUTIFY_QUALITY.BestQuality && _bloomCustomize) { bMat.SetTexture("_BloomTex4", rt[4]); bMat.SetTexture("_BloomTex3", rt[3]); bMat.SetTexture("_BloomTex2", rt[2]); bMat.SetTexture("_BloomTex1", rt[1]); bMat.SetTexture("_BloomTex", rt[0]); RenderTextureDescriptor descriptor = rt[0].descriptor; renderTexture3 = RenderTexture.GetTemporary(descriptor); renderTexture6 = renderTexture3; Graphics.Blit(rt[num3], renderTexture6, bMat, 6); } } } if (_anamorphicFlares) { UpdateMaterialAnamorphicIntensityAndThreshold(); int num6 = ((_quality != BEAUTIFY_QUALITY.BestPerformance) ? ((!_anamorphicFlaresUltra) ? 512 : (source.height / 4 * 4)) : 256); RenderTextureDescriptor desc5 = rtDescBase; int num7 = num6; for (int k = 0; k <= num3; k++) { if (_anamorphicFlaresVertical) { desc5.width = num7; desc5.height = Mathf.Max(1, (int)((float)num6 * num / _anamorphicFlaresSpread)); rtAF[k] = RenderTexture.GetTemporary(desc5); } else { desc5.width = Mathf.Max(1, (int)((float)num6 * num / _anamorphicFlaresSpread)); desc5.height = num7; rtAF[k] = RenderTexture.GetTemporary(desc5); } num6 /= 2; } if (_anamorphicFlaresAntiflicker && _quality == BEAUTIFY_QUALITY.BestQuality) { Graphics.Blit(source, rtAF[0], bMat, 9); } else { Graphics.Blit(source, rtAF[0], bMat, 2); } rtAF[0] = BlurThisOneDirection(rtAF[0], _anamorphicFlaresVertical); for (int l = 0; l < num3; l++) { if (_quality == BEAUTIFY_QUALITY.BestPerformance) { Graphics.Blit(rtAF[l], rtAF[l + 1], bMat, 18); if (_anamorphicFlaresBlur) { rtAF[l + 1] = BlurThisOneDirection(rtAF[l + 1], _anamorphicFlaresVertical); } } else { Graphics.Blit(rtAF[l], rtAF[l + 1], bMat, 7); rtAF[l + 1] = BlurThisOneDirection(rtAF[l + 1], _anamorphicFlaresVertical); } } for (int num8 = num3; num8 > 0; num8--) { rtAF[num8 - 1].MarkRestoreExpected(); if (num8 == 1) { Graphics.Blit(rtAF[num8], rtAF[num8 - 1], bMat, (_quality != BEAUTIFY_QUALITY.BestQuality) ? 14 : 10); } else { Graphics.Blit(rtAF[num8], rtAF[num8 - 1], bMat, (_quality != BEAUTIFY_QUALITY.BestQuality) ? 13 : 8); } } if (_bloom) { if (_lensDirt) { rt[3].MarkRestoreExpected(); Graphics.Blit(rtAF[3], rt[3], bMat, (_quality != BEAUTIFY_QUALITY.BestQuality) ? 13 : 11); } renderTexture6.MarkRestoreExpected(); Graphics.Blit(rtAF[0], renderTexture6, bMat, (_quality != BEAUTIFY_QUALITY.BestQuality) ? 13 : 11); } else { renderTexture6 = rtAF[0]; } UpdateMaterialBloomIntensityAndThreshold(); } if (flag3) { Vector3 vector = currentCamera.transform.position - _sun.transform.forward * 1000f; Vector3 vector2 = currentCamera.WorldToViewportPoint(vector); float num9 = 0f; if (vector2.z > 0f && vector2.x >= -0.1f && vector2.x < 1.1f && vector2.y >= -0.1f && vector2.y < 1.1f) { Ray ray = new Ray(currentCamera.transform.position, (vector - currentCamera.transform.position).normalized); if (!Physics.Raycast(ray, currentCamera.farClipPlane, _sunFlaresLayerMask)) { Vector2 vector3 = vector2 - Vector3.one * 0.5f; num9 = _sunFlaresIntensity * Mathf.Clamp01((0.6f - Mathf.Max(Mathf.Abs(vector3.x), Mathf.Abs(vector3.y))) / 0.6f); } } sunFlareCurrentIntensity = Mathf.Lerp(sunFlareCurrentIntensity, num9, (!Application.isPlaying) ? 1f : 0.5f); if (sunFlareCurrentIntensity > 0f) { if (num9 > 0f) { sunLastScrPos = vector2; } bMat.SetColor("_SunTint", _sunFlaresTint * sunFlareCurrentIntensity); sunLastScrPos.z = 0.5f + sunFlareTime * _sunFlaresSolarWindSpeed; Vector2 vector4 = new Vector2(0.5f - sunLastScrPos.y, sunLastScrPos.x - 0.5f); if (!_sunFlaresRotationDeadZone || vector4.sqrMagnitude > 0.00025f) { sunLastRot = Mathf.Atan2(vector4.x, vector4.y); } sunLastScrPos.w = sunLastRot; sunFlareTime += Time.deltaTime; bMat.SetVector("_SunPos", sunLastScrPos); RenderTextureDescriptor desc6 = rtDescBase; desc6.width = currentCamera.pixelWidth / _sunFlaresDownsampling; desc6.height = currentCamera.pixelHeight / _sunFlaresDownsampling; RenderTexture temporary = RenderTexture.GetTemporary(desc6); Graphics.Blit(pass: (_quality != BEAUTIFY_QUALITY.BestQuality) ? ((!(renderTexture6 != null)) ? 16 : 17) : ((!(renderTexture6 != null)) ? 20 : 21), source: renderTexture6, dest: temporary, mat: bMat); if (_lensDirt && _bloom) { rt[3].MarkRestoreExpected(); Graphics.Blit(temporary, rt[3], bMat, (_quality != BEAUTIFY_QUALITY.BestQuality) ? 13 : 11); } renderTexture6 = temporary; RenderTexture.ReleaseTemporary(temporary); if (!_bloom && !_anamorphicFlares) { bMat.SetVector("_Bloom", Vector4.one); if (!bMat.IsKeywordEnabled("BEAUTIFY_BLOOM")) { bMat.EnableKeyword("BEAUTIFY_BLOOM"); } } } } if (renderTexture6 != null) { bMat.SetTexture("_BloomTex", renderTexture6); } else { if (bMat.IsKeywordEnabled("BEAUTIFY_BLOOM")) { bMat.DisableKeyword("BEAUTIFY_BLOOM"); } bMat.SetVector("_Bloom", Vector4.zero); } if (_lensDirt) { bMat.SetTexture("_ScreenLum", (!_anamorphicFlares || _bloom) ? rt[3] : rtAF[3]); } } if (_lensDirt) { Vector4 value = new Vector4(1f, 1f / (1.01f - _lensDirtIntensity), _lensDirtThreshold, Mathf.Max(_bloomIntensity, 1f)); bMat.SetVector("_Dirt", value); } if (Application.isPlaying && flag && (_eyeAdaptation || _purkinje)) { int num10 = ((_quality != BEAUTIFY_QUALITY.BestQuality) ? 8 : 9); int num11 = (int)Mathf.Pow(2f, num10); if (rtEA == null || rtEA.Length < num10) { rtEA = new RenderTexture[num10]; } RenderTextureDescriptor desc7 = rtDescBase; for (int m = 0; m < num10; m++) { desc7.width = num11; desc7.height = num11; rtEA[m] = RenderTexture.GetTemporary(desc7); num11 /= 2; } Graphics.Blit(source, rtEA[0], bMat, (_quality != BEAUTIFY_QUALITY.BestQuality) ? 18 : 22); int num12 = num10 - 1; int num13 = ((_quality != BEAUTIFY_QUALITY.BestQuality) ? 9 : 15); for (int n = 0; n < num12; n++) { Graphics.Blit(rtEA[n], rtEA[n + 1], bMat, (n != 0) ? (num13 + 1) : num13); } bMat.SetTexture("_EALumSrc", rtEA[num12]); if (rtEAacum == null) { int pass2 = ((_quality != BEAUTIFY_QUALITY.BestQuality) ? 18 : 22); RenderTextureDescriptor desc8 = rtDescBase; desc8.width = 2; desc8.height = 2; rtEAacum = new RenderTexture(desc8); Graphics.Blit(rtEA[num12], rtEAacum, bMat, pass2); rtEAHist = new RenderTexture(desc8); Graphics.Blit(rtEAacum, rtEAHist, bMat, pass2); } else { rtEAacum.MarkRestoreExpected(); Graphics.Blit(rtEA[num12], rtEAacum, bMat, num13 + 2); Graphics.Blit(rtEAacum, rtEAHist, bMat, num13 + 3); } bMat.SetTexture("_EAHist", rtEAHist); } if (renderTexture != null) { Graphics.Blit(source, renderTexture, bMat, 1); bMat.SetTexture("_CompareTex", renderTexture); } if (renderTexture2 != null) { float blurScale = ((!(_blurIntensity > 1f)) ? _blurIntensity : 1f); if (renderTexture != null) { Graphics.Blit(renderTexture, renderTexture2, bMat, renderPass); BlurThis(renderTexture2, blurScale); } else { BlurThisDownscaling(source, renderTexture2, blurScale); } BlurThis(renderTexture2, blurScale); if (_quality == BEAUTIFY_QUALITY.BestQuality) { BlurThis(renderTexture2, blurScale); } if (renderTexture != null) { bMat.SetTexture("_CompareTex", renderTexture2); Graphics.Blit(source, destination, bMat, renderPass); } else { Graphics.Blit(renderTexture2, destination, bMat, renderPass); } RenderTexture.ReleaseTemporary(renderTexture2); } else { Graphics.Blit(source, destination, bMat, renderPass); } if (rtEA != null) { for (int num14 = 0; num14 < rtEA.Length; num14++) { if (rtEA[num14] != null) { RenderTexture.ReleaseTemporary(rtEA[num14]); rtEA[num14] = null; } } } if (rt != null) { for (int num15 = 0; num15 < rt.Length; num15++) { if (rt[num15] != null) { RenderTexture.ReleaseTemporary(rt[num15]); rt[num15] = null; } } } if (rtAF != null) { for (int num16 = 0; num16 < rtAF.Length; num16++) { if (rtAF[num16] != null) { RenderTexture.ReleaseTemporary(rtAF[num16]); rtAF[num16] = null; } } } if (renderTexture3 != null) { RenderTexture.ReleaseTemporary(renderTexture3); } if (renderTexture5 != null) { RenderTexture.ReleaseTemporary(renderTexture5); } if (renderTexture != null) { RenderTexture.ReleaseTemporary(renderTexture); } if (renderTexture4 != null) { RenderTexture.ReleaseTemporary(renderTexture4); } } private void OnPostRender() { if (_pixelateDownscale && _pixelateAmount > 1 && pixelateTexture != null) { RenderTexture.active = null; currentCamera.targetTexture = null; pixelateTexture.filterMode = FilterMode.Point; Graphics.Blit((Texture)pixelateTexture, (RenderTexture)null); } } private void BlurThis(RenderTexture rt, float blurScale = 1f) { RenderTextureDescriptor descriptor = rt.descriptor; RenderTexture temporary = RenderTexture.GetTemporary(descriptor); temporary.filterMode = FilterMode.Bilinear; bMat.SetFloat("_BlurScale", blurScale); Graphics.Blit(rt, temporary, bMat, 4); Graphics.Blit(temporary, rt, bMat, 5); RenderTexture.ReleaseTemporary(temporary); } private void BlurThisDownscaling(RenderTexture rt, RenderTexture downscaled, float blurScale = 1f) { RenderTextureDescriptor descriptor = rt.descriptor; descriptor.width = downscaled.width; descriptor.height = downscaled.height; RenderTexture temporary = RenderTexture.GetTemporary(descriptor); temporary.filterMode = FilterMode.Bilinear; float num = rt.width / descriptor.width; bMat.SetFloat("_BlurScale", blurScale * num); Graphics.Blit(rt, temporary, bMat, 4); bMat.SetFloat("_BlurScale", blurScale); Graphics.Blit(temporary, downscaled, bMat, 5); RenderTexture.ReleaseTemporary(temporary); } private RenderTexture BlurThisOneDirection(RenderTexture rt, bool vertical, float blurScale = 1f) { RenderTextureDescriptor descriptor = rt.descriptor; RenderTexture temporary = RenderTexture.GetTemporary(descriptor); temporary.filterMode = FilterMode.Bilinear; bMat.SetFloat("_BlurScale", blurScale); Graphics.Blit(rt, temporary, bMat, (!vertical) ? 4 : 5); RenderTexture.ReleaseTemporary(rt); return temporary; } private void BlurThisDoF(RenderTexture rt, int renderPass) { RenderTextureDescriptor descriptor = rt.descriptor; RenderTexture temporary = RenderTexture.GetTemporary(descriptor); RenderTexture temporary2 = RenderTexture.GetTemporary(descriptor); temporary.filterMode = _depthOfFieldFilterMode; temporary2.filterMode = _depthOfFieldFilterMode; UpdateDepthOfFieldBlurData(new Vector2(0.44721f, -0.89443f)); Graphics.Blit(rt, temporary, bMat, renderPass); UpdateDepthOfFieldBlurData(new Vector2(-1f, 0f)); Graphics.Blit(temporary, temporary2, bMat, renderPass); UpdateDepthOfFieldBlurData(new Vector2(0.44721f, 0.89443f)); Graphics.Blit(temporary2, rt, bMat, renderPass); RenderTexture.ReleaseTemporary(temporary2); RenderTexture.ReleaseTemporary(temporary); } private void BlurThisAlpha(RenderTexture rt, float blurScale = 1f) { RenderTextureDescriptor descriptor = rt.descriptor; RenderTexture temporary = RenderTexture.GetTemporary(descriptor); temporary.filterMode = FilterMode.Bilinear; bMat.SetFloat("_BlurScale", blurScale); Graphics.Blit(rt, temporary, bMat, 23); Graphics.Blit(temporary, rt, bMat, 24); RenderTexture.ReleaseTemporary(temporary); } private void OnDidApplyAnimationProperties() { shouldUpdateMaterialProperties = true; } public void UpdateQualitySettings() { switch (_quality) { case BEAUTIFY_QUALITY.BestPerformance: _depthOfFieldDownsampling = 2; _depthOfFieldMaxSamples = 4; _sunFlaresDownsampling = 2; break; case BEAUTIFY_QUALITY.BestQuality: _depthOfFieldDownsampling = 1; _depthOfFieldMaxSamples = 8; _sunFlaresDownsampling = 1; break; } isDirty = true; } public void UpdateMaterialProperties() { if (Application.isPlaying) { shouldUpdateMaterialProperties = true; } else { UpdateMaterialPropertiesNow(); } } public void UpdateMaterialPropertiesNow() { shouldUpdateMaterialProperties = false; if (currentCamera != null && currentCamera.depthTextureMode == DepthTextureMode.None && _quality != BEAUTIFY_QUALITY.Basic) { currentCamera.depthTextureMode = DepthTextureMode.Depth; } string graphicsDeviceName = SystemInfo.graphicsDeviceName; if (graphicsDeviceName != null && graphicsDeviceName.ToUpper().Contains("MALI-T720")) { rtFormat = RenderTextureFormat.Default; _bloomBlur = false; _anamorphicFlaresBlur = false; } else { rtFormat = (SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGBHalf) ? RenderTextureFormat.ARGBHalf : RenderTextureFormat.ARGB32); } switch (_quality) { case BEAUTIFY_QUALITY.BestQuality: if (bMatDesktop == null) { bMatDesktop = new Material(Shader.Find("Beautify/Beautify")); bMatDesktop.hideFlags = HideFlags.DontSave; } bMat = bMatDesktop; break; case BEAUTIFY_QUALITY.BestPerformance: if (bMatMobile == null) { bMatMobile = new Material(Shader.Find("Beautify/BeautifyMobile")); bMatMobile.hideFlags = HideFlags.DontSave; } bMat = bMatMobile; break; case BEAUTIFY_QUALITY.Basic: if (bMatBasic == null) { bMatBasic = new Material(Shader.Find("Beautify/BeautifyBasic")); bMatBasic.hideFlags = HideFlags.DontSave; } bMat = bMatBasic; break; } bool flag = QualitySettings.activeColorSpace == ColorSpace.Linear; switch (_preset) { case BEAUTIFY_PRESET.Soft: _sharpen = 2f; if (flag) { _sharpen *= 2f; } _sharpenDepthThreshold = 0.035f; _sharpenRelaxation = 0.065f; _sharpenClamp = 0.4f; _saturate = 0.5f; _contrast = 1.005f; _brightness = 1.05f; _dither = 0.02f; _ditherDepth = 0f; _daltonize = 0f; break; case BEAUTIFY_PRESET.Medium: _sharpen = 3f; if (flag) { _sharpen *= 2f; } _sharpenDepthThreshold = 0.035f; _sharpenRelaxation = 0.07f; _sharpenClamp = 0.45f; _saturate = 1f; _contrast = 1.02f; _brightness = 1.05f; _dither = 0.02f; _ditherDepth = 0f; _daltonize = 0f; break; case BEAUTIFY_PRESET.Strong: _sharpen = 4.75f; if (flag) { _sharpen *= 2f; } _sharpenDepthThreshold = 0.035f; _sharpenRelaxation = 0.075f; _sharpenClamp = 0.5f; _saturate = 1.5f; _contrast = 1.03f; _brightness = 1.05f; _dither = 0.022f; _ditherDepth = 0f; _daltonize = 0f; break; case BEAUTIFY_PRESET.Exaggerated: _sharpen = 6f; if (flag) { _sharpen *= 2f; } _sharpenDepthThreshold = 0.035f; _sharpenRelaxation = 0.08f; _sharpenClamp = 0.55f; _saturate = 2.25f; _contrast = 1.035f; _brightness = 1.05f; _dither = 0.025f; _ditherDepth = 0f; _daltonize = 0f; break; } isDirty = true; if (bMat == null) { return; } renderPass = 1; if (_pixelateAmount > 1) { if (QualitySettings.antiAliasing > 1) { QualitySettings.antiAliasing = 1; } if (_pixelateDownscale) { _dither = 0f; } } UpdateSharpenParams(_sharpen); bool flag2 = currentCamera != null && currentCamera.orthographic; bMat.SetVector("_Dither", new Vector4(_dither, (!flag2) ? _ditherDepth : 0f, (_sharpenMaxDepth + _sharpenMinDepth) * 0.5f, Mathf.Abs(_sharpenMaxDepth - _sharpenMinDepth) * 0.5f + ((!flag2) ? 0f : 1000f))); bMat.SetVector("_AntialiasData", new Vector3(_antialiasStrength, _antialiasDepthThreshold, 0f)); float y = ((!flag) ? _contrast : (1f + (_contrast - 1f) / 2.2f)); bMat.SetVector("_ColorBoost", new Vector4(_brightness, y, _saturate, _daltonize * 10f)); Color value = _vignettingColor; value.a *= ((!_vignetting) ? 0f : 32f); float num = 1f - _vignettingBlink * 2f; if (num < 0f) { num = 0f; } value.r *= num; value.g *= num; value.b *= num; bMat.SetColor("_Vignetting", value); if (currentCamera != null) { bMat.SetFloat("_VignettingAspectRatio", (!_vignettingCircularShape || !(_vignettingBlink <= 0f)) ? (_vignettingAspectRatio + 1.001f / (1.001f - _vignettingBlink) - 1f) : (1f / currentCamera.aspect)); } if (_frame) { Vector4 value2 = new Vector4(_frameColor.r, _frameColor.g, _frameColor.b, (1.00001f - _frameColor.a) * 0.5f); bMat.SetVector("_Frame", value2); } bMat.SetColor("_Outline", _outlineColor); float num2 = 1E-05f + _bloomWeight0 + _bloomWeight1 + _bloomWeight2 + _bloomWeight3 + _bloomWeight4 + _bloomWeight5; bMat.SetVector("_BloomWeights", new Vector4(_bloomWeight0 / num2 + _bloomBoost0, _bloomWeight1 / num2 + _bloomBoost1, _bloomWeight2 / num2 + _bloomBoost2, _bloomWeight3 / num2 + _bloomBoost3)); bMat.SetVector("_BloomWeights2", new Vector4(_bloomWeight4 / num2 + _bloomBoost4, _bloomWeight5 / num2 + _bloomBoost5, _bloomMaxBrightness, num2)); if (_bloomDebug && (_bloom || _anamorphicFlares || _sunFlares)) { renderPass = 3; } if (_sunFlares) { bMat.SetVector("_SunData", new Vector4(_sunFlaresSunIntensity, _sunFlaresSunDiskSize, _sunFlaresSunRayDiffractionIntensity, _sunFlaresSunRayDiffractionThreshold)); bMat.SetVector("_SunCoronaRays1", new Vector4(_sunFlaresCoronaRays1Length, Mathf.Max((float)_sunFlaresCoronaRays1Streaks / 2f, 1f), Mathf.Max(_sunFlaresCoronaRays1Spread, 0.0001f), _sunFlaresCoronaRays1AngleOffset)); bMat.SetVector("_SunCoronaRays2", new Vector4(_sunFlaresCoronaRays2Length, Mathf.Max((float)_sunFlaresCoronaRays2Streaks / 2f, 1f), Mathf.Max(_sunFlaresCoronaRays2Spread + 0.0001f), _sunFlaresCoronaRays2AngleOffset)); bMat.SetVector("_SunGhosts1", new Vector4(0f, _sunFlaresGhosts1Size, _sunFlaresGhosts1Offset, _sunFlaresGhosts1Brightness)); bMat.SetVector("_SunGhosts2", new Vector4(0f, _sunFlaresGhosts2Size, _sunFlaresGhosts2Offset, _sunFlaresGhosts2Brightness)); bMat.SetVector("_SunGhosts3", new Vector4(0f, _sunFlaresGhosts3Size, _sunFlaresGhosts3Offset, _sunFlaresGhosts3Brightness)); bMat.SetVector("_SunGhosts4", new Vector4(0f, _sunFlaresGhosts4Size, _sunFlaresGhosts4Offset, _sunFlaresGhosts4Brightness)); bMat.SetVector("_SunHalo", new Vector3(_sunFlaresHaloOffset, _sunFlaresHaloAmplitude, _sunFlaresHaloIntensity * 100f)); } if (_lensDirtTexture == null) { _lensDirtTexture = Resources.Load("Textures/dirt2"); } bMat.SetTexture("_OverlayTex", _lensDirtTexture); bMat.SetColor("_AFTint", _anamorphicFlaresTint); if (_depthOfField && (int)_depthOfFieldAutofocusLayerMask != 0) { Shader.SetGlobalFloat("_BeautifyDepthBias", _depthOfFieldExclusionBias); } dofCurrentLayerMaskValue = _depthOfFieldExclusionLayerMask.value; if (_compareMode) { renderPass = 0; bMat.SetVector("_CompareParams", new Vector4(Mathf.Cos(_compareLineAngle), Mathf.Sin(_compareLineAngle), 0f - Mathf.Cos(_compareLineAngle), _compareLineWidth)); } if (shaderKeywords == null) { shaderKeywords = new List(); } else { shaderKeywords.Clear(); } if (_quality != BEAUTIFY_QUALITY.Basic) { if (_lut && _lutTexture != null) { shaderKeywords.Add("BEAUTIFY_LUT"); bMat.SetTexture("_LUTTex", _lutTexture); bMat.SetColor("_FXColor", new Color(0f, 0f, 0f, _lutIntensity)); } else if (_nightVision) { shaderKeywords.Add("BEAUTIFY_NIGHT_VISION"); Color value3 = _nightVisionColor; if (flag) { value3.a *= 5f * value3.a; } else { value3.a *= 3f * value3.a; } value3.r *= value3.a; value3.g *= value3.a; value3.b *= value3.a; bMat.SetColor("_FXColor", value3); } else if (_thermalVision) { shaderKeywords.Add("BEAUTIFY_THERMAL_VISION"); } else if (_daltonize > 0f) { shaderKeywords.Add("BEAUTIFY_DALTONIZE"); } else { bMat.SetColor("_FXColor", new Color(0f, 0f, 0f, _lutIntensity)); } bMat.SetColor("_TintColor", _tintColor); if (_sunFlares) { if (flareNoise == null) { flareNoise = Resources.Load("Textures/flareNoise"); } flareNoise.wrapMode = TextureWrapMode.Repeat; bMat.SetTexture("_FlareTex", flareNoise); if (_sun == null) { Light[] array = UnityEngine.Object.FindObjectsOfType(); foreach (Light light in array) { if (light.type == LightType.Directional && light.enabled && light.gameObject.activeSelf) { _sun = light.transform; break; } } } } if (_vignetting) { if (_vignettingMask != null) { bMat.SetTexture("_VignettingMask", _vignettingMask); shaderKeywords.Add("BEAUTIFY_VIGNETTING_MASK"); } else { shaderKeywords.Add("BEAUTIFY_VIGNETTING"); } } if (_frame) { if (_frameMask != null) { bMat.SetTexture("_FrameMask", _frameMask); shaderKeywords.Add("BEAUTIFY_FRAME_MASK"); } else { shaderKeywords.Add("BEAUTIFY_FRAME"); } } if (_outline) { shaderKeywords.Add("BEAUTIFY_OUTLINE"); } if (_lensDirt) { shaderKeywords.Add("BEAUTIFY_DIRT"); } if (_bloom || _anamorphicFlares || _sunFlares) { shaderKeywords.Add("BEAUTIFY_BLOOM"); if (_bloomDepthAtten > 0f) { bMat.SetFloat("_BloomDepthTreshold", _bloomDepthAtten); shaderKeywords.Add("BEAUTIFY_BLOOM_USE_DEPTH"); } if ((_bloom || _anamorphicFlares) && (int)_bloomCullingMask != 0) { bMat.SetFloat("_BloomLayerZBias", _bloomLayerZBias); shaderKeywords.Add("BEAUTIFY_BLOOM_USE_LAYER"); } } if (_depthOfField) { if (_depthOfFieldTransparencySupport || (int)_depthOfFieldExclusionLayerMask != 0) { shaderKeywords.Add("BEAUTIFY_DEPTH_OF_FIELD_TRANSPARENT"); } else { shaderKeywords.Add("BEAUTIFY_DEPTH_OF_FIELD"); } } if (_eyeAdaptation) { Vector4 value4 = new Vector4(_eyeAdaptationMinExposure, _eyeAdaptationMaxExposure, _eyeAdaptationSpeedToDark, _eyeAdaptationSpeedToLight); bMat.SetVector("_EyeAdaptation", value4); shaderKeywords.Add("BEAUTIFY_EYE_ADAPTATION"); } if (_quality == BEAUTIFY_QUALITY.BestQuality && _tonemap == BEAUTIFY_TMO.ACES) { shaderKeywords.Add("BEAUTIFY_TONEMAP_ACES"); } if (_purkinje || _vignetting) { float z = _vignettingFade + _vignettingBlink * 0.5f; if (_vignettingBlink > 0.99f) { z = 1f; } Vector3 vector = new Vector3(_purkinjeAmount, _purkinjeLuminanceThreshold, z); bMat.SetVector("_Purkinje", vector); shaderKeywords.Add("BEAUTIFY_PURKINJE"); } } bMat.shaderKeywords = shaderKeywords.ToArray(); } private void UpdateMaterialBloomIntensityAndThreshold() { float num = _bloomThreshold; if (QualitySettings.activeColorSpace == ColorSpace.Linear) { num *= num; } bMat.SetVector("_Bloom", new Vector4(_bloomIntensity + ((!_anamorphicFlares) ? 0f : 0.0001f), 0f, 0f, num)); } private void UpdateMaterialAnamorphicIntensityAndThreshold() { float num = _anamorphicFlaresThreshold; if (QualitySettings.activeColorSpace == ColorSpace.Linear) { num *= num; } float x = _anamorphicFlaresIntensity / (_bloomIntensity + 0.0001f); bMat.SetVector("_Bloom", new Vector4(x, 0f, 0f, num)); } private void UpdateSharpenParams(float sharpen) { bMat.SetVector("_Sharpen", new Vector4(sharpen, _sharpenDepthThreshold, _sharpenClamp, _sharpenRelaxation)); } private void UpdateDepthOfFieldData() { float num; if (!_depthOfFieldAutofocus) { num = ((!(_depthOfFieldTargetFocus != null)) ? _depthOfFieldDistance : ((!(currentCamera.WorldToScreenPoint(_depthOfFieldTargetFocus.position).z < 0f)) ? Vector3.Distance(currentCamera.transform.position, _depthOfFieldTargetFocus.position) : currentCamera.farClipPlane)); } else { UpdateDoFAutofocusDistance(); num = ((!(dofLastAutofocusDistance > 0f)) ? currentCamera.farClipPlane : dofLastAutofocusDistance); } if (OnBeforeFocus != null) { num = OnBeforeFocus(num); } dofPrevDistance = Mathf.Lerp(dofPrevDistance, num, (!Application.isPlaying) ? 1f : (_depthOfFieldFocusSpeed * Time.deltaTime * 30f)); float y = _depthOfFieldAperture * (_depthOfFieldFocalLength / Mathf.Max(dofPrevDistance - _depthOfFieldFocalLength, 0.001f)) * 41.666668f; dofLastBokehData = new Vector4(dofPrevDistance, y, 0f, 0f); bMat.SetVector("_BokehData", dofLastBokehData); bMat.SetVector("_BokehData2", new Vector4((!_depthOfFieldForegroundBlur) ? currentCamera.farClipPlane : _depthOfFieldForegroundDistance, _depthOfFieldMaxSamples, _depthOfFieldBokehThreshold, _depthOfFieldBokehIntensity * _depthOfFieldBokehIntensity)); bMat.SetVector("_BokehData3", new Vector3(_depthOfFieldMaxBrightness, _depthOfFieldMaxDistance * (currentCamera.farClipPlane + 1f), 0f)); } private void UpdateDepthOfFieldBlurData(Vector2 blurDir) { float num = 1f / (float)_depthOfFieldDownsampling; blurDir *= num; dofLastBokehData.z = blurDir.x; dofLastBokehData.w = blurDir.y; bMat.SetVector("_BokehData", dofLastBokehData); } private void UpdateDoFAutofocusDistance() { Vector3 position = _depthofFieldAutofocusViewportPoint; position.z = 10f; Ray ray = currentCamera.ViewportPointToRay(position); RaycastHit hitInfo; if (Physics.Raycast(ray, out hitInfo, currentCamera.farClipPlane, _depthOfFieldAutofocusLayerMask)) { dofLastAutofocusDistance = Mathf.Clamp(hitInfo.distance, _depthOfFieldAutofocusMinDistance, _depthOfFieldAutofocusMaxDistance); } else { dofLastAutofocusDistance = currentCamera.farClipPlane; } } public Texture2D GenerateSepiaLUT() { Texture2D texture2D = new Texture2D(1024, 32, TextureFormat.ARGB32, false, true); Color[] array = new Color[32768]; Vector3 lhs = default(Vector3); for (int i = 0; i < 32; i++) { for (int j = 0; j < 1024; j++) { lhs.z = (float)(j / 32 * 8) / 255f; lhs.y = (float)(i * 8) / 255f; lhs.x = (float)(j % 32 * 8) / 255f; float r = Vector3.Dot(lhs, new Vector3(0.393f, 0.769f, 0.189f)); float g = Vector3.Dot(lhs, new Vector3(0.349f, 0.686f, 0.168f)); float b = Vector3.Dot(lhs, new Vector3(0.272f, 0.534f, 0.131f)); array[i * 1024 + j] = new Color(r, g, b); } } texture2D.SetPixels(array); texture2D.Apply(); return texture2D; } public void Blink(float duration, float maxValue = 1f) { if (!(duration <= 0f)) { StartCoroutine(DoBlink(duration, maxValue)); } } private IEnumerator DoBlink(float duration, float maxValue) { float start = Time.time; float t = 0f; WaitForEndOfFrame w = new WaitForEndOfFrame(); do { t = (Time.time - start) / duration; if (t > 1f) { t = 1f; } float easeOut = t * (2f - t); vignettingBlink = easeOut * maxValue; yield return w; } while (t < 1f); start = Time.time; do { t = (Time.time - start) / duration; if (t > 1f) { t = 1f; } float easeIn = t * t; vignettingBlink = (1f - easeIn) * maxValue; yield return w; } while (t < 1f); } } }