/// <summary> /// 这个由于只能通过unity的质量等级设置,所以调用这个函数的时候会 /// 同时设置贴图、像素灯数目、实时反射探针、各项异性 /// </summary> /// <param name="quality"></param> public static void SetShadowQuality(ShadowQuality quality, bool bForce = false) { if (OldShadowQuality != quality || bForce) { OldShadowQuality = quality; currData.currShadowQuality = quality; switch (quality) { case ShadowQuality.Fastest: SetShadow_Fastest(); break; case ShadowQuality.Good: SetShadow_Good(); break; case ShadowQuality.High: SetShadow_High(); break; case ShadowQuality.Best: SetShadow_Best(); break; } } SetTextureQuality(currData.currTextureQuality, true); SetPixelLightQuality(currData.currSceneRenderingQuality); SetRealTimeReflectionProbe(currData.currSceneRenderingQuality); SetTextureAniso(currData.currTextureQuality); }
public void SelectShadowQuality(ShadowQuality quality) { switch (quality) { case ShadowQuality.Low: RTAntiAliasing = AntiAliasing.Samples2; shadowRT.width = 1024; shadowRT.height = 1024; break; case ShadowQuality.Middle: RTAntiAliasing = AntiAliasing.Samples4; shadowRT.width = 2048; shadowRT.height = 2048; break; case ShadowQuality.High: RTAntiAliasing = AntiAliasing.Samples8; shadowRT.width = 4096; shadowRT.height = 4096; break; default: Debug.LogError("ShadowQuality Parameter Error!"); break; } shadowRT.antiAliasing = (int)RTAntiAliasing; }
public void Apply() { // Resolution Resolution resolution = Screen.resolutions[resolutionDropdown.value]; FullScreenMode fsm = (FullScreenMode)fullscreenDropdown.value; SettingsManager.settingsData.width = resolution.width; SettingsManager.settingsData.height = resolution.height; SettingsManager.settingsData.fullScreenMode = fullscreenDropdown.value; Debug.Log(resolution.ToString()); Debug.Log(fsm); Screen.SetResolution(resolution.width, resolution.height, fsm); // Shadow Quality SettingsManager.settingsData.shadowQuality = shadowQualityDropdown.value; ShadowQuality sq = (ShadowQuality)shadowQualityDropdown.value; Debug.Log(sq); QualitySettings.shadows = sq; // Shadow Distance QualitySettings.shadowDistance = SettingsManager.settingsData.shadowDistance; // Anisotropic Filtering SettingsManager.settingsData.anisotropicFiltering = anisotropicFilteringDropdown.value; AnisotropicFiltering af = (AnisotropicFiltering)anisotropicFilteringDropdown.value; Debug.Log(af); QualitySettings.anisotropicFiltering = af; // Anti-Aliasing QualitySettings.antiAliasing = SettingsManager.settingsData.antiAliasing; }
private static ShaderFeatures GetSupportedShaderFeatures() { ShaderFeatures shaderFeatures; shaderFeatures = ShaderFeatures.MainLight; ShadowQuality shadows = QualitySettings.shadows; if (shadows != ShadowQuality.Disable) { shaderFeatures |= ShaderFeatures.MainLightShadows; if (shadows != ShadowQuality.HardOnly) { shaderFeatures |= ShaderFeatures.SoftShadows; } } shaderFeatures |= ShaderFeatures.AdditionalLightShadows; // These are both always "on", and dictated by the number of lights shaderFeatures |= ShaderFeatures.VertexLighting; shaderFeatures |= ShaderFeatures.AdditionalLights; shaderFeatures |= ShaderFeatures.MixedLighting; // As this is settable per-camera (and the graphics settings UI depends on a camera being marked "main camera"), // we assume it's on (and strip if the shader doesn't have a deferred pass) shaderFeatures |= ShaderFeatures.DeferredShading; // Built-in doesn't throw this switch, but the shader library has it, so set it here shaderFeatures |= ShaderFeatures.DeferredWithoutAccurateGbufferNormals; return(shaderFeatures); }
private void RenderReflectionCamera(ReflectionCameraInfo info) { // bail if we don't have a camera or renderer if (info == null || info.ReflectionCamera == null || info.SourceCamera == null || ReflectRenderer == null || ReflectRenderer.sharedMaterial == null || !ReflectRenderer.enabled) { return; } CurrentRecursionLevel = currentCameras.Count + (info.SourceCameraIsReflection ? 1 : 0); renderCount++; Camera sourceCamera = info.SourceCamera; Camera reflectionCamera = info.ReflectionCamera; int oldPixelLightCount = QualitySettings.pixelLightCount; int oldCullingMask = reflectionCamera.cullingMask; bool oldSoftParticles = QualitySettings.softParticles; int oldAntiAliasing = QualitySettings.antiAliasing; ShadowQuality oldShadows = QualitySettings.shadows; SyncCameraSettings(reflectionCamera, sourceCamera); // MAGIC MIRROR RECURSION OPTIMIZATION if (currentCameras.Count > 1) { if (currentCameras.Count > 3) { QualitySettings.shadows = ShadowQuality.Disable; } QualitySettings.shadows = ShadowQuality.HardOnly; QualitySettings.antiAliasing = 0; QualitySettings.softParticles = false; QualitySettings.pixelLightCount = 0; reflectionCamera.cullingMask &= waterLayerInverse; } else { QualitySettings.pixelLightCount = MaximumPerPixelLightsToReflect; } Transform reflectionTransform = transform; Vector3 reflectionNormal = (NormalIsForward ? -reflectionTransform.forward : reflectionTransform.up); // use shared reflection render function RenderReflection(info, reflectionTransform, reflectionNormal, ClipPlaneOffset); // restore render state reflectionCamera.cullingMask = oldCullingMask; QualitySettings.pixelLightCount = oldPixelLightCount; QualitySettings.softParticles = oldSoftParticles; QualitySettings.antiAliasing = oldAntiAliasing; QualitySettings.shadows = oldShadows; ReflectRenderer.sharedMaterial.SetTexture(ReflectionSamplerName, info.TargetTexture); ReflectRenderer.sharedMaterial.SetTexture(ReflectionSamplerName2, info.TargetTexture2); ReflectRenderer.sharedMaterial.DisableKeyword(mirrorRecursionLimitKeyword); currentCameras.Remove(info); info.SourceCamera = null; info.TargetTexture = null; info.TargetTexture2 = null; cameraCache.Add(info); }
/// <summary> /// Load values found inside PlayerPrefs. /// </summary> private void LoadValues() { ResolutionIndex = PlayerPrefs.GetInt("SETTINGSMANAGER_RESOLUTIONINDEX", ResolutionIndex); if (ResolutionIndex <= -1) { Vector2Int currentResolution = new Vector2Int(Screen.currentResolution.width, Screen.currentResolution.height); bool exit = false; foreach (KeyValuePair <AspectRatioTypes, Vector2Int[]> aspectRatio in m_ResolutionList) { for (int i = 0; i < aspectRatio.Value.Length; i++) { if (currentResolution == aspectRatio.Value[i]) { ResolutionIndex = i; AspectRatio = aspectRatio.Key; exit = true; break; } } if (exit) { break; } } if (ResolutionIndex == -1) { // Standard 1080p ResolutionIndex = 2; AspectRatio = AspectRatioTypes.Ratio16by9; } } else { AspectRatio = PlayerPrefsUtil.GetEnum("SETTINGSMANAGER_ASPECTRATIO", AspectRatio); } Fullscreen = PlayerPrefsUtil.GetBool("SETTINGSMANAGER_FULLSCREEN", Fullscreen); RefreshRate = PlayerPrefs.GetInt("SETTINGSMANAGER_REFRESHRATE", RefreshRate); PixelLightCount = PlayerPrefs.GetInt("SETTINGSMANAGER_PIXELLIGHTCOUNT", PixelLightCount); TextureQuality = PlayerPrefsUtil.GetEnum("SETTINGSMANAGER_TEXTUREQUALITYTYPE", TextureQuality); AnisotropicFiltering = PlayerPrefsUtil.GetBool("SETTINGSMANAGER_ANISOTROPICFILTERING", AnisotropicFiltering); AntiAliasing = PlayerPrefsUtil.GetEnum("SETTINGSMANAGER_ANTIALIASING", AntiAliasing); SoftParticles = PlayerPrefsUtil.GetBool("SETTINGSMANAGER_SOFTPARTICLES", SoftParticles); RealtimeReflectionProbe = PlayerPrefsUtil.GetBool("SETTINGSMANAGER_REALTIMEREFLECTIONPROBE", RealtimeReflectionProbe); VSyncCount = PlayerPrefs.GetInt("SETTINGSMANAGER_VSYNCCOUNT", VSyncCount); ShadowQualityType = PlayerPrefsUtil.GetEnum("SETTINGSMANAGER_SHADOWQUALITYTYPE", ShadowQualityType); ShadowResolutionType = PlayerPrefsUtil.GetEnum("SETTINGSMANAGER_SHADOWRESOLUTIONTYPE", ShadowResolutionType); ShadowProjectionType = PlayerPrefsUtil.GetEnum("SETTINGSMANAGER_SHADOWPROJECTIONTYPE", ShadowProjectionType); ShadowDistance = PlayerPrefsUtil.GetEnum("SETTINGSMANAGER_SHADOWDISTANCETYPE", ShadowDistance); ShadowmaskModeType = PlayerPrefsUtil.GetEnum("SETTINGSMANAGER_SHADOWMASKMODE", ShadowmaskModeType); ShadowNearPlaneOffset = PlayerPrefs.GetInt("SETTINGSMANAGER_SHADOWNEARPLANEOFFSET", ShadowNearPlaneOffset); ShadowCascadeType = PlayerPrefsUtil.GetEnum("SETTINGSMANAGER_SHADOWCASCADETYPE", ShadowCascadeType); }
private static void DrawShadow(ref RainRender rend) { ShadowQuality currentQuality = QualitySettings.shadows; QualitySettings.shadows = ShadowQuality.Disable; rend.shadowCamera.Render(); QualitySettings.shadows = currentQuality; }
public void ConfrimSettings() { var resol = resolutions.Find(t => t.index == dropDownResol.value); Screen.SetResolution(resol.value_1, resol.value_2, true); var antialias = antialaisings.Find(t => t.index == dropDownAntialaisings.value); QualitySettings.antiAliasing = antialias.value_1; var texture = textures.Find(t => t.index == dropDownTextures.value); QualitySettings.masterTextureLimit = texture.value_1; QualitySettings.vSyncCount = v_sync.isOn ? 1 : 0; var shadow = shadows.Find(t => t.index == dropDownShadow.value); ShadowQuality sh_q = new ShadowQuality(); ShadowResolution sh_resol = new ShadowResolution(); if (shadow.value_1 == 0) { sh_q = ShadowQuality.Disable; } else if (shadow.value_1 == 1) { sh_q = ShadowQuality.All; switch (shadow.value_2) { case 0: sh_resol = ShadowResolution.Low; break; case 1: sh_resol = ShadowResolution.Medium; break; case 2: sh_resol = ShadowResolution.High; break; case 3: sh_resol = ShadowResolution.VeryHigh; break; default: sh_resol = ShadowResolution.Medium; break; } } QualitySettings.shadows = sh_q; QualitySettings.shadowResolution = sh_resol; SaveSettings(resol.index, antialias.index, texture.index, QualitySettings.vSyncCount, shadow.index); }
public void SetPerformanceDefault() { PerfPreset = PerformancePreset.Default; PerfLODMultiplier = 1; PerfMsaa = 0; PerfRagdollAmount = 3; PerfResolutionMult = 1; PerfShaderQuality = ShaderQuality.PhysicallyBased; PerfShadowQuality = ShadowQuality.Low; }
private void RenderReflection(Camera camera, Camera reflectionCamera) { reflectionCamera.cullingMask = this._Data.ReflectionMask; this.SetCameraSettings(camera, reflectionCamera); this._CurrentTarget = this.GetRenderTexture(camera.pixelWidth, camera.pixelHeight, reflectionCamera); this._TemporaryTargets[camera] = this._CurrentTarget; TemporaryRenderTexture temporary = RenderTexturesCache.GetTemporary(this._CurrentTarget.Texture.width, this._CurrentTarget.Texture.height, 16, this._CurrentTarget.Texture.format, true, false, false); reflectionCamera.targetTexture = temporary; reflectionCamera.transform.eulerAngles = PlanarReflection.CalculateReflectionAngles(camera); reflectionCamera.transform.position = this.CalculateReflectionPosition(camera); float w = -this._Water.transform.position.y - 0.07f; Vector4 plane = new Vector4(0f, 1f, 0f, w); Matrix4x4 matrix4x = Matrix4x4.zero; matrix4x = Reflection.CalculateReflectionMatrix(matrix4x, plane); Vector3 position = matrix4x.MultiplyPoint(camera.transform.position); reflectionCamera.worldToCameraMatrix = camera.worldToCameraMatrix * matrix4x; Vector4 clipPlane = Reflection.CameraSpacePlane(reflectionCamera, this._Water.transform.position, new Vector3(0f, 1f, 0f), 0.07f, 1f); Matrix4x4 matrix4x2 = camera.projectionMatrix; matrix4x2 = Reflection.CalculateObliqueMatrix(matrix4x2, clipPlane); reflectionCamera.projectionMatrix = matrix4x2; reflectionCamera.transform.position = position; Vector3 eulerAngles = camera.transform.eulerAngles; reflectionCamera.transform.eulerAngles = new Vector3(-eulerAngles.x, eulerAngles.y, eulerAngles.z); reflectionCamera.clearFlags = ((!this._Data.ReflectSkybox) ? CameraClearFlags.Color : CameraClearFlags.Skybox); if (this._Data.RenderShadows) { GL.invertCulling = true; reflectionCamera.Render(); GL.invertCulling = false; } else { ShadowQuality shadows = QualitySettings.shadows; QualitySettings.shadows = ShadowQuality.Disable; GL.invertCulling = true; reflectionCamera.Render(); GL.invertCulling = false; QualitySettings.shadows = shadows; } reflectionCamera.targetTexture = null; if (this._UtilitiesMaterial == null) { this._UtilitiesMaterial = new Material(this._UtilitiesShader) { hideFlags = HideFlags.DontSave }; } Graphics.Blit(temporary, this._CurrentTarget, this._UtilitiesMaterial, 0); temporary.Dispose(); }
public void Run(ShadowQuality quality, Bitmap frameBuffer, Bitmap background, float[,] intensities) { if (quality == ShadowQuality.Mesh) { MeshShade(frameBuffer, intensities); } else { SmoothShade(frameBuffer, background, intensities); } }
void CloneGlobalShadowSettings() { shadows = QualitySettings.shadows; ShadowResolution = QualitySettings.shadowResolution; shadowNearPlaneOffset = QualitySettings.shadowNearPlaneOffset; shadowCascades = QualitySettings.shadowCascades; ShadowProjection = QualitySettings.shadowProjection; shadowDistance = QualitySettings.shadowDistance; shadowCascade2Split = QualitySettings.shadowCascade2Split; shadowCascade4Split = QualitySettings.shadowCascade4Split; }
void OnPreRender() { if (disableShadows) { storedShadows = QualitySettings.shadows; QualitySettings.shadows = ShadowQuality.Disable; } if (disableFog) { fogOn = RenderSettings.fog; RenderSettings.fog = false; } }
internal void CopySettings(MenuSettings settings) { volume = settings.volume; shadows = settings.shadows; shadowsQuality = settings.shadowsQuality; antiAliasing = settings.antiAliasing; anisotropicFiltering = settings.anisotropicFiltering; realTimeReflections = settings.realTimeReflections; vSync = settings.vSync; resolution = settings.resolution; fullScreen = settings.fullScreen; }
public MainWindow() { InitializeComponent(); _shadowQuality = ShadowQuality.Smooth; _grid = new Cell[CellRows, CellCols]; _smoothedIntensities = new float[CellRows, CellCols]; for (int r = 0; r < CellRows; r++) { for (int c = 0; c < CellCols; c++) { _grid[r, c] = new Cell(); } } _gameObjects = new List <IGameObject>(); _rayEmitters = new List <IRayEmitter>(); var player = new Character(new Vector2(400, 200)); _gameObjects.Add(player); _rayEmitters.Add(player); _rayTracer = new RayTracer(_grid); _shadowShader = new ShadowShader(); _caveBrush = new TextureBrush(new Bitmap("Content/background.png")); _background = new Bitmap(Width, Height, PixelFormat.Format32bppPArgb); _frameBuffer = new Bitmap(Width, Height, PixelFormat.Format32bppPArgb); _writeableBitmap = new WriteableBitmap(Width, Height, 96, 96, PixelFormats.Bgr32, null); Canvas.Source = _writeableBitmap; using (Graphics graphics = Graphics.FromImage(_frameBuffer)) { graphics.Clear(Color.Black); } AddSurfaces(); _gameTime = new GameTime(); _controller = new Controller(); _isRendering = true; _renderThread = new Thread(RenderLoop); _renderThread.Start(); }
public MenuSettings() { volume = 1; shadows = Shadow.Soft; shadowsQuality = ShadowQuality.Ultra; antiAliasing = AntiAliasing.X8; anisotropicFiltering = AnisotropicFiltering.Enable; realTimeReflections = true; vSync = VSync.Half; resolution = MaxResolution; fullScreen = true; }
/// <summary> /// Render a reflection to the reflection render textures and apply to material /// </summary> /// <param name="sourceCamera">Source camera</param> /// <param name="reflectionCamera">Reflection camera</param> private void RenderReflectionCamera(Camera sourceCamera, Camera reflectionCamera) { CreateRenderTextures(sourceCamera); int oldPixelLightCount = QualitySettings.pixelLightCount; int oldCullingMask = reflectionCamera.cullingMask; bool oldSoftParticles = QualitySettings.softParticles; int oldAntiAliasing = QualitySettings.antiAliasing; ShadowQuality oldShadows = QualitySettings.shadows; SyncCameraSettings(reflectionCamera, sourceCamera); if (WeatherMakerScript.Instance != null && QualitySettings.shadows != ShadowQuality.Disable && WeatherMakerLightManagerScript.ScreenSpaceShadowMode != UnityEngine.Rendering.BuiltinShaderMode.Disabled) { QualitySettings.shadows = WeatherMakerScript.Instance.PerformanceProfile.ReflectionShadows; } // get reflection normal vector Transform reflectionTransform = transform; Vector3 reflectionNormal = (NormalIsForward ? -reflectionTransform.forward : reflectionTransform.up); if (TransformNormalNegate) { reflectionNormal = -reflectionNormal; } // render the actual reflection if (sourceCamera.stereoEnabled) { if (sourceCamera.stereoTargetEye == StereoTargetEyeMask.Both || sourceCamera.stereoTargetEye == StereoTargetEyeMask.Left) { RenderReflectionInternal(sourceCamera, reflectionCamera, reflectionTransform, reflectionNormal, StereoTargetEyeMask.Left, LeftEyeTexture); } if (sourceCamera.stereoTargetEye == StereoTargetEyeMask.Both || sourceCamera.stereoTargetEye == StereoTargetEyeMask.Right) { RenderReflectionInternal(sourceCamera, reflectionCamera, reflectionTransform, reflectionNormal, StereoTargetEyeMask.Right, RightEyeTexture); } } else { RenderReflectionInternal(sourceCamera, reflectionCamera, reflectionTransform, reflectionNormal, StereoTargetEyeMask.Both, LeftEyeTexture); } // restore render state reflectionCamera.cullingMask = oldCullingMask; QualitySettings.pixelLightCount = oldPixelLightCount; QualitySettings.softParticles = oldSoftParticles; QualitySettings.antiAliasing = oldAntiAliasing; QualitySettings.shadows = oldShadows; }
private void ApplyShadowToggle() { bool value = Settings.Get("EnableShadows", true); EnableShadowsToggle.isOn = value; ShadowQuality sq = ShadowQuality.Disable; if (value) { sq = ShadowQuality.All; } QualitySettings.shadows = sq; ShadowDistanceSlider.interactable = value; }
// Start is called before the first frame update private void Start() { // Set Shadow level and shadow quality _shadowLevel = QualitySettings.shadows; _shadowQuality = QualitySettings.shadowResolution; // OPTIONAL // Force set dropdown component ForceSetModule(); // Check if the module is available ModuleAvailable(); // Init shadow module InitModule(); }
private void OnKeyUp(object sender, KeyEventArgs e) { _controller.UpdateKey(e.Key, false); if (e.Key == Key.X) { if (_shadowQuality == ShadowQuality.Mesh) { _shadowQuality = ShadowQuality.Smooth; } else { _shadowQuality = ShadowQuality.Mesh; } } }
/// <summary> /// /// </summary> /// <param name="isSet"></param> public QualitySettingsKun(bool isSet) : base() { isDirty = false; if (isSet) { activeColorSpace = QualitySettings.activeColorSpace; anisotropicFiltering = QualitySettings.anisotropicFiltering; antiAliasing = QualitySettings.antiAliasing; asyncUploadBufferSize = QualitySettings.asyncUploadBufferSize; asyncUploadPersistentBuffer = QualitySettings.asyncUploadPersistentBuffer; asyncUploadTimeSlice = QualitySettings.asyncUploadTimeSlice; billboardsFaceCameraPosition = QualitySettings.billboardsFaceCameraPosition; desiredColorSpace = QualitySettings.desiredColorSpace; lodBias = QualitySettings.lodBias; masterTextureLimit = QualitySettings.masterTextureLimit; maximumLODLevel = QualitySettings.maximumLODLevel; maxQueuedFrames = QualitySettings.maxQueuedFrames; names = QualitySettings.names; particleRaycastBudget = QualitySettings.particleRaycastBudget; pixelLightCount = QualitySettings.pixelLightCount; realtimeReflectionProbes = QualitySettings.realtimeReflectionProbes; resolutionScalingFixedDPIFactor = QualitySettings.resolutionScalingFixedDPIFactor; shadowCascade2Split = QualitySettings.shadowCascade2Split; mShadowCascade4Split = new Vector3Kun(QualitySettings.shadowCascade4Split); shadowCascades = QualitySettings.shadowCascades; shadowDistance = QualitySettings.shadowDistance; shadowmaskMode = QualitySettings.shadowmaskMode; shadowNearPlaneOffset = QualitySettings.shadowNearPlaneOffset; shadowProjection = QualitySettings.shadowProjection; shadowResolution = QualitySettings.shadowResolution; shadows = QualitySettings.shadows; #if UNITY_2019_1_OR_NEWER skinWeights = QualitySettings.skinWeights; #endif softParticles = QualitySettings.softParticles; softVegetation = QualitySettings.softVegetation; streamingMipmapsActive = QualitySettings.streamingMipmapsActive; streamingMipmapsAddAllCameras = QualitySettings.streamingMipmapsAddAllCameras; streamingMipmapsMaxFileIORequests = QualitySettings.streamingMipmapsMaxFileIORequests; streamingMipmapsMaxLevelReduction = QualitySettings.streamingMipmapsMaxLevelReduction; streamingMipmapsMemoryBudget = QualitySettings.streamingMipmapsMemoryBudget; streamingMipmapsRenderersPerFrame = QualitySettings.streamingMipmapsRenderersPerFrame; vSyncCount = QualitySettings.vSyncCount; } }
/// <summary> /// Load values from a SettingPreset object minus resolution. /// </summary> public void LoadValues(SettingsPreset preset) { PixelLightCount = preset.PixelLightCount; TextureQuality = preset.TextureQuality; AnisotropicFiltering = preset.AnisotropicFiltering; AntiAliasing = preset.AntiAliasing; SoftParticles = preset.SoftParticles; RealtimeReflectionProbe = preset.RealtimeReflectionProbe; VSyncCount = preset.VSyncCount; ShadowQualityType = preset.ShadowQualityType; ShadowResolutionType = preset.ShadowResolutionType; ShadowProjectionType = preset.ShadowProjectionType; ShadowDistance = preset.ShadowDistance; ShadowmaskModeType = preset.ShadowmaskModeType; ShadowNearPlaneOffset = preset.ShadowNearPlaneOffset; ShadowCascadeType = preset.ShadowCascadeType; }
/// <summary> /// /// </summary> /// <param name="binaryReader"></param> public virtual void Deserialize(BinaryReader binaryReader) { activeColorSpace = (ColorSpace)binaryReader.ReadInt32(); anisotropicFiltering = (AnisotropicFiltering)binaryReader.ReadInt32(); antiAliasing = binaryReader.ReadInt32(); asyncUploadBufferSize = binaryReader.ReadInt32(); asyncUploadPersistentBuffer = binaryReader.ReadBoolean(); asyncUploadTimeSlice = binaryReader.ReadInt32(); billboardsFaceCameraPosition = binaryReader.ReadBoolean(); desiredColorSpace = (ColorSpace)binaryReader.ReadInt32(); lodBias = binaryReader.ReadSingle(); masterTextureLimit = binaryReader.ReadInt32(); maximumLODLevel = binaryReader.ReadInt32(); maxQueuedFrames = binaryReader.ReadInt32(); names = SerializerKun.DesirializeStrings(binaryReader); particleRaycastBudget = binaryReader.ReadInt32(); pixelLightCount = binaryReader.ReadInt32(); realtimeReflectionProbes = binaryReader.ReadBoolean(); resolutionScalingFixedDPIFactor = binaryReader.ReadSingle(); shadowCascade2Split = binaryReader.ReadSingle(); mShadowCascade4Split = SerializerKun.DesirializeObject <Vector3Kun>(binaryReader); shadowCascades = binaryReader.ReadInt32(); shadowDistance = binaryReader.ReadSingle(); shadowmaskMode = (ShadowmaskMode)binaryReader.ReadInt32(); shadowNearPlaneOffset = binaryReader.ReadSingle(); shadowProjection = (ShadowProjection)binaryReader.ReadInt32(); shadowResolution = (ShadowResolution)binaryReader.ReadInt32(); shadows = (ShadowQuality)binaryReader.ReadInt32(); #if UNITY_2019_1_OR_NEWER skinWeights = (SkinWeights)binaryReader.ReadInt32(); #endif softParticles = binaryReader.ReadBoolean(); softVegetation = binaryReader.ReadBoolean(); streamingMipmapsActive = binaryReader.ReadBoolean(); streamingMipmapsAddAllCameras = binaryReader.ReadBoolean(); streamingMipmapsMaxFileIORequests = binaryReader.ReadInt32(); streamingMipmapsMaxLevelReduction = binaryReader.ReadInt32(); streamingMipmapsMemoryBudget = binaryReader.ReadSingle(); streamingMipmapsRenderersPerFrame = binaryReader.ReadInt32(); vSyncCount = binaryReader.ReadInt32(); isDirty = binaryReader.ReadBoolean(); }
//protected virtual void OnWillRenderObject() //{ // BeginCameraRendering(Camera.current); //} public virtual void BeginCameraRendering(Camera cam) { if (cam == _reflectionCamera) { return; } _currentCamera = cam; //Force the mirror to be in the Water layer, so it will avoid to be rendered by the reflection cameras gameObject.layer = LayerMask.NameToLayer("Water"); if (AllowRender()) { if (!_insideRendering) { _insideRendering = true; //Tune the quality settings for the reflected image int oldPixelLightCount = QualitySettings.pixelLightCount; if (_disablePixelLights) { QualitySettings.pixelLightCount = 0; } ShadowQuality oldShadowQuality = QualitySettings.shadows; QualitySettings.shadows = (ShadowQuality)(Mathf.Min((int)_reflectionShadowType, (int)oldShadowQuality)); CreateReflectionTexture(); RenderReflection(); _insideRendering = false; // Restore the quality settings QualitySettings.pixelLightCount = oldPixelLightCount; QualitySettings.shadows = oldShadowQuality; } } else { ClearRenderTexture(_reflectionTextureLeft, Color.red); ClearRenderTexture(_reflectionTextureRight, Color.red); } }
void OnPreRender() { int InitialpixelLights = QualitySettings.pixelLightCount; ShadowQuality InitialShadows = QualitySettings.shadows; QualitySettings.pixelLightCount = 0; QualitySettings.shadows = ShadowQuality.Disable; #if UNITY_EDITOR UpdateParams(); if (ThisCamera == null) { ThisCamera = gameObject.GetComponent <Camera>(); } #endif if (_Downsample > 1 && _FogVolumeCamera) { SurrogateMaterial.SetInt("_SrcBlend", (int)_BlendMode); Shader.EnableKeyword("_FOG_LOWRES_RENDERER"); // Profiler.BeginSample("FogVolume Render"); _FogVolumeCamera.Render(); // Profiler.EndSample(); // TexelUpdate(); Shader.DisableKeyword("_FOG_LOWRES_RENDERER"); } else { Shader.DisableKeyword("_FOG_LOWRES_RENDERER"); } QualitySettings.pixelLightCount = InitialpixelLights; QualitySettings.shadows = InitialShadows; }
private void OnPreRender() { if (!RequestRefresh(Time.renderedFrameCount)) { return; // Skip if not need to refresh on this frame } CreateWaterObjects(_camViewpoint); if (!_camReflections) { return; } // Find out the reflection plane: position and normal in world space Vector3 planePos = OceanRenderer.Instance.Root.position; Vector3 planeNormal = Vector3.up; // Optionally disable pixel lights for reflection/refraction int oldPixelLightCount = QualitySettings.pixelLightCount; if (_disablePixelLights) { QualitySettings.pixelLightCount = 0; } // Optionally disable shadows for reflection/refraction ShadowQuality oldShadowQuality = QualitySettings.shadows; if (_disableShadows) { QualitySettings.shadows = ShadowQuality.Disable; } UpdateCameraModes(); // Reflect camera around reflection plane float d = -Vector3.Dot(planeNormal, planePos) - _clipPlaneOffset; Vector4 reflectionPlane = new Vector4(planeNormal.x, planeNormal.y, planeNormal.z, d); Matrix4x4 reflection = Matrix4x4.zero; CalculateReflectionMatrix(ref reflection, reflectionPlane); Vector3 newpos = reflection.MultiplyPoint(_camViewpoint.transform.position); _camReflections.worldToCameraMatrix = _camViewpoint.worldToCameraMatrix * reflection; // Setup oblique projection matrix so that near plane is our reflection // plane. This way we clip everything below/above it for free. Vector4 clipPlane = CameraSpacePlane(_camReflections, planePos, planeNormal, 1.0f); _camReflections.projectionMatrix = _camViewpoint.CalculateObliqueMatrix(clipPlane); // Set custom culling matrix from the current camera _camReflections.cullingMatrix = _camViewpoint.projectionMatrix * _camViewpoint.worldToCameraMatrix; _camReflections.targetTexture = _reflectionTexture; // Invert culling because view is mirrored bool oldCulling = GL.invertCulling; GL.invertCulling = !oldCulling; _camReflections.transform.position = newpos; Vector3 euler = _camViewpoint.transform.eulerAngles; _camReflections.transform.eulerAngles = new Vector3(-euler.x, euler.y, euler.z); _camReflections.cullingMatrix = _camReflections.projectionMatrix * _camReflections.worldToCameraMatrix; ForceDistanceCulling(_farClipPlane); _camReflections.Render(); GL.invertCulling = oldCulling; // Restore shadows if (_disableShadows) { QualitySettings.shadows = oldShadowQuality; } // Restore pixel light count if (_disablePixelLights) { QualitySettings.pixelLightCount = oldPixelLightCount; } Refreshed(Time.renderedFrameCount); //remember this frame as last refreshed }
private void OnPreRender() { if (Enabled && !ReferenceEquals(cam, null)) { Shader.DisableKeyword("SCENE_VIEW"); if (ReferenceEquals(null, LightingPassShader)) { LightingPassShader = Shader.Find("Hidden/LightingPass"); if (ReferenceEquals(null, LightingPassShader) && !ReferenceEquals(null, _lightingPass)) { LightingPassShader = _lightingPass; } } if (ReferenceEquals(null, ProfileShader)) { ProfileShader = Shader.Find("Hidden/SSS_Profile"); if (ReferenceEquals(null, ProfileShader) && !ReferenceEquals(null, _profile)) { ProfileShader = _profile; } } m_TextureSize.x = cam.pixelWidth / Downsampling; m_TextureSize.y = cam.pixelHeight / Downsampling; CreateCameras(cam, out ProfileCamera, out LightingCamera); #region Render Profile if (ProfilePerObject) { UpdateCameraModes(cam, ProfileCamera); //ProfileCamera.allowHDR = false; ////humm, removes a lot of artifacts when far away InitialpixelLights = QualitySettings.pixelLightCount; InitialShadows = QualitySettings.shadows; QualitySettings.pixelLightCount = 0; QualitySettings.shadows = ShadowQuality.Disable; Shader.EnableKeyword("SSS_PROFILES"); ProfileCamera.cullingMask = SSS_Layer; ProfileCamera.backgroundColor = Color.black; ProfileCamera.clearFlags = CameraClearFlags.SolidColor; /* * if (cam.stereoEnabled) * { //Left eye * if (cam.stereoTargetEye == StereoTargetEyeMask.Both || cam.stereoTargetEye == StereoTargetEyeMask.Left) * { * ProfileCamera.stereoTargetEye = StereoTargetEyeMask.Left; * * //ProfileCamera.transform.localPosition = InputTracking.GetLocalPosition(XRNode.LeftEye); * //ProfileCamera.transform.localRotation = InputTracking.GetLocalRotation(XRNode.LeftEye); * ProfileCamera.projectionMatrix = cam.GetStereoProjectionMatrix(Camera.StereoscopicEye.Left); * ProfileCamera.worldToCameraMatrix = cam.GetStereoViewMatrix(Camera.StereoscopicEye.Left); * GetProfileRT(ref SSS_ProfileTex, (int)m_TextureSize.x, (int)m_TextureSize.y, "SSS_ProfileTex"); * Util.RenderToTarget(ProfileCamera, SSS_ProfileTex, ProfileShader); * Shader.SetGlobalTexture("SSS_ProfileTex", SSS_ProfileTex); * } * //Right eye * if (cam.stereoTargetEye == StereoTargetEyeMask.Both || cam.stereoTargetEye == StereoTargetEyeMask.Left) * { * ProfileCamera.stereoTargetEye = StereoTargetEyeMask.Right; * //ProfileCamera.transform.localPosition = InputTracking.GetLocalPosition(XRNode.RightEye); * //ProfileCamera.transform.localRotation = InputTracking.GetLocalRotation(XRNode.RightEye); * ProfileCamera.projectionMatrix = cam.GetStereoProjectionMatrix(Camera.StereoscopicEye.Right); * ProfileCamera.projectionMatrix = cam.GetStereoProjectionMatrix(Camera.StereoscopicEye.Right); * ProfileCamera.worldToCameraMatrix = cam.GetStereoViewMatrix(Camera.StereoscopicEye.Right); * GetProfileRT(ref SSS_ProfileTexR, (int)m_TextureSize.x, (int)m_TextureSize.y, "SSS_ProfileTexR"); * Rendering.RenderToTarget(ProfileCamera, SSS_ProfileTexR, ProfileShader); * Shader.SetGlobalTexture("SSS_ProfileTexR", SSS_ProfileTexR); * } * * } * else * { */ //Mono //ProfileCamera.projectionMatrix = cam.projectionMatrix;//avoid frustum jitter from taa GetProfileRT(ref SSS_ProfileTex, (int)m_TextureSize.x, (int)m_TextureSize.y, "SSS_ProfileTex"); Util.RenderToTarget(ProfileCamera, SSS_ProfileTex, ProfileShader); Shader.SetGlobalTexture("SSS_ProfileTex", SSS_ProfileTex); //} QualitySettings.pixelLightCount = InitialpixelLights; QualitySettings.shadows = InitialShadows; } else { Shader.DisableKeyword("SSS_PROFILES"); SafeDestroy(SSS_ProfileTex); //SafeDestroy(SSS_ProfileTexR); } #endregion #region Render Lighting UpdateCameraModes(cam, LightingCamera); LightingCamera.allowHDR = cam.allowHDR; // if (SurfaceScattering) { if (ReferenceEquals(null, sss_convolution)) { sss_convolution = LightingCameraGO.GetComponent <SSS_convolution>(); } if (sss_convolution && sss_convolution._BlurMaterial) { sss_convolution._BlurMaterial.SetFloat("DepthTest", Mathf.Max(.00001f, DepthTest / 20)); maxDistance = Mathf.Max(0, maxDistance); sss_convolution._BlurMaterial.SetFloat("maxDistance", maxDistance); sss_convolution._BlurMaterial.SetFloat("NormalTest", Mathf.Max(.001f, NormalTest)); sss_convolution._BlurMaterial.SetFloat("EdgeOffset", EdgeOffset); sss_convolution._BlurMaterial.SetInt("_SSS_NUM_SAMPLES", ShaderIterations + 1); sss_convolution._BlurMaterial.SetColor("sssColor", sssColor); if (Dither) { sss_convolution._BlurMaterial.EnableKeyword("RANDOMIZED_ROTATION"); sss_convolution._BlurMaterial.SetFloat("DitherScale", DitherScale); //sss_convolution._BlurMaterial.SetFloat("DitherSpeed", DitherSpeed * 10); sss_convolution._BlurMaterial.SetFloat("DitherIntensity", DitherIntensity); if (NoiseTexture) { sss_convolution._BlurMaterial.SetTexture("NoiseTexture", NoiseTexture); } else { Debug.Log("Noise texture not available"); } } else { sss_convolution._BlurMaterial.DisableKeyword("RANDOMIZED_ROTATION"); } if (UseProfileTest && ProfilePerObject) { sss_convolution._BlurMaterial.EnableKeyword("PROFILE_TEST"); } else { sss_convolution._BlurMaterial.DisableKeyword("PROFILE_TEST"); } if (DEBUG_DISTANCE) { sss_convolution._BlurMaterial.EnableKeyword("DEBUG_DISTANCE"); } else { sss_convolution._BlurMaterial.DisableKeyword("DEBUG_DISTANCE"); } if (FixPixelLeaks) { sss_convolution._BlurMaterial.EnableKeyword("OFFSET_EDGE_TEST"); } else { sss_convolution._BlurMaterial.DisableKeyword("OFFSET_EDGE_TEST"); } if (DitherEdgeTest) { sss_convolution._BlurMaterial.EnableKeyword("DITHER_EDGE_TEST"); } else { sss_convolution._BlurMaterial.DisableKeyword("DITHER_EDGE_TEST"); } } sss_convolution.iterations = ScatteringIterations; sss_convolution.BlurRadius = ScatteringRadius; LightingCamera.depthTextureMode = DepthTextureMode.DepthNormals; //LightingCamera.transform.position = cam.transform.position; //LightingCamera.transform.rotation = cam.transform.rotation; //LightingCamera.projectionMatrix = cam.projectionMatrix;//avoid frustum jitter from taa GetRT(ref LightingTex, (int)m_TextureSize.x, (int)m_TextureSize.y, "LightingTexture"); GetRT(ref LightingTexBlurred, (int)m_TextureSize.x, (int)m_TextureSize.y, "SSSLightingTextureBlurred"); sss_convolution.blurred = LightingTexBlurred; sss_convolution.rtFormat = LightingTex.format; if (!ReferenceEquals(null, LightingPassShader)) { Util.RenderToTarget(LightingCamera, LightingTex, LightingPassShader); Shader.SetGlobalTexture("LightingTexBlurred", LightingTexBlurred); Shader.SetGlobalTexture("LightingTex", LightingTex); } } #endregion } else { //LightingCamera.depthTextureMode = DepthTextureMode.None; } }
private void OnPreRender() { savedShadowQuality = QualitySettings.shadows; QualitySettings.shadows = ShadowQuality.Disable; }
/// <summary> /// Load values from a SettingPreset object including resolution. /// </summary> public void LoadValues(SettingsPreset preset, bool loadResolution) { if (loadResolution) { ResolutionIndex = PlayerPrefs.GetInt("SETTINGSMANAGER_RESOLUTIONINDEX", ResolutionIndex); if (ResolutionIndex <= -1) { Vector2Int currentResolution = new Vector2Int(Screen.currentResolution.width, Screen.currentResolution.height); bool exit = false; foreach (KeyValuePair <AspectRatioTypes, Vector2Int[]> aspectRatio in m_ResolutionList) { for (int i = 0; i < aspectRatio.Value.Length; i++) { if (currentResolution == aspectRatio.Value[i]) { ResolutionIndex = i; AspectRatio = aspectRatio.Key; exit = true; break; } } if (exit) { break; } } if (ResolutionIndex == -1) { // Standard 1080p ResolutionIndex = 2; AspectRatio = AspectRatioTypes.Ratio16by9; } } else { AspectRatio = PlayerPrefsUtil.GetEnum("SETTINGSMANAGER_ASPECTRATIO", AspectRatio); } Fullscreen = PlayerPrefsUtil.GetBool("SETTINGSMANAGER_FULLSCREEN", Fullscreen); RefreshRate = PlayerPrefs.GetInt("SETTINGSMANAGER_REFRESHRATE", RefreshRate); } PixelLightCount = preset.PixelLightCount; TextureQuality = preset.TextureQuality; AnisotropicFiltering = preset.AnisotropicFiltering; AntiAliasing = preset.AntiAliasing; SoftParticles = preset.SoftParticles; RealtimeReflectionProbe = preset.RealtimeReflectionProbe; VSyncCount = preset.VSyncCount; ShadowQualityType = preset.ShadowQualityType; ShadowResolutionType = preset.ShadowResolutionType; ShadowProjectionType = preset.ShadowProjectionType; ShadowDistance = preset.ShadowDistance; ShadowmaskModeType = preset.ShadowmaskModeType; ShadowNearPlaneOffset = preset.ShadowNearPlaneOffset; ShadowCascadeType = preset.ShadowCascadeType; }
/// <summary> /// Apply changes done to the manager towards the actual game. If overwrite, it will force save all settings, not just the changed ones. /// </summary> public void ApplyChanges(bool overwrite = false) { // Screen if (overwrite || (m_CurrentResolutionIndex != ResolutionIndex || m_CurrentAspectRatio != AspectRatio || m_CurrentlyFullscreen != Fullscreen || m_CurrentRefreshRate != RefreshRate)) { m_CurrentAspectRatio = AspectRatio; m_CurrentResolutionIndex = ResolutionIndex; m_CurrentlyFullscreen = Fullscreen; m_CurrentRefreshRate = RefreshRate; Vector2Int resolution = m_ResolutionList[m_CurrentAspectRatio][m_CurrentResolutionIndex]; Screen.SetResolution(resolution.x, resolution.y, m_CurrentlyFullscreen, m_CurrentRefreshRate); PlayerPrefsUtil.SetEnum("SETTINGSMANAGER_ASPECTRATIO", m_CurrentAspectRatio); PlayerPrefs.SetInt("SETTINGSMANAGER_RESOLUTIONINDEX", m_CurrentResolutionIndex); PlayerPrefsUtil.SetBool("SETTINGSMANAGER_FULLSCREEN", m_CurrentlyFullscreen); PlayerPrefs.GetInt("SETTINGSMANAGER_REFRESHRATE", m_CurrentRefreshRate); } // Graphics if (overwrite || (m_CurrentPixelLightCount != PixelLightCount)) { m_CurrentPixelLightCount = PixelLightCount; QualitySettings.pixelLightCount = m_CurrentPixelLightCount; PlayerPrefs.SetInt("SETTINGSMANAGER_PIXELLIGHTCOUNT", m_CurrentPixelLightCount); } if (overwrite || (m_CurrentTextureQualityType != TextureQuality)) { m_CurrentTextureQualityType = TextureQuality; QualitySettings.masterTextureLimit = (int)m_CurrentTextureQualityType; PlayerPrefsUtil.SetEnum("SETTINGSMANAGER_TEXTUREQUALITYTYPE", m_CurrentTextureQualityType); } if (overwrite || (m_CurrentAnisotropicFiltering != AnisotropicFiltering)) { m_CurrentAnisotropicFiltering = AnisotropicFiltering; QualitySettings.anisotropicFiltering = m_CurrentAnisotropicFiltering ? UnityEngine.AnisotropicFiltering.Enable : UnityEngine.AnisotropicFiltering.Disable; PlayerPrefsUtil.SetBool("SETTINGSMANAGER_ANISOTROPICFILTERING", m_CurrentAnisotropicFiltering); } if (overwrite || (m_CurrentAntiAliasingType != AntiAliasing)) { m_CurrentAntiAliasingType = AntiAliasing; QualitySettings.antiAliasing = (int)m_CurrentAntiAliasingType; PlayerPrefsUtil.SetEnum("SETTINGSMANAGER_ANTIALIASINGTYPE", m_CurrentAntiAliasingType); } if (overwrite || (m_CurrentSoftParticles != SoftParticles)) { m_CurrentSoftParticles = SoftParticles; QualitySettings.softParticles = m_CurrentSoftParticles; PlayerPrefsUtil.SetBool("SETTINGSMANAGER_SOFTPARTICLES", m_CurrentSoftParticles); } if (overwrite || (m_CurrentRealtimeReflectionProbe != RealtimeReflectionProbe)) { m_CurrentRealtimeReflectionProbe = RealtimeReflectionProbe; QualitySettings.realtimeReflectionProbes = m_CurrentRealtimeReflectionProbe; PlayerPrefsUtil.SetBool("SETTINGSMANAGER_REALTIMEREFLECTIONPROBE", m_CurrentRealtimeReflectionProbe); } if (overwrite || (m_CurrentVSyncCount != VSyncCount)) { m_CurrentVSyncCount = VSyncCount; QualitySettings.vSyncCount = VSyncCount; PlayerPrefs.SetInt("SETTINGSMANAGER_VSYNCCOUNT", m_CurrentVSyncCount); } // Shadows if (overwrite || (m_CurrentShadowQualityType != ShadowQualityType)) { m_CurrentShadowQualityType = ShadowQualityType; QualitySettings.shadows = m_CurrentShadowQualityType; PlayerPrefsUtil.SetEnum("SETTINGSMANAGER_SHADOWQUALITYTYPE", m_CurrentShadowQualityType); } if (overwrite || (m_CurrentShadowResolutionType != ShadowResolutionType)) { m_CurrentShadowResolutionType = ShadowResolutionType; QualitySettings.shadowResolution = m_CurrentShadowResolutionType; PlayerPrefsUtil.SetEnum("SETTINGSMANAGER_SHADOWRESOLUTIONTYPE", m_CurrentShadowQualityType); } if (overwrite || (m_CurrentShadowProjectionType != ShadowProjectionType)) { m_CurrentShadowProjectionType = ShadowProjectionType; QualitySettings.shadowProjection = m_CurrentShadowProjectionType; PlayerPrefsUtil.SetEnum("SETTINGSMANAGER_SHADOWPROJECTIONTYPE", m_CurrentShadowProjectionType); } if (overwrite || (m_CurrentShadowDistanceType != ShadowDistance)) { m_CurrentShadowDistanceType = ShadowDistance; QualitySettings.shadowDistance = (int)m_CurrentShadowDistanceType; PlayerPrefsUtil.SetEnum("SETTINGSMANAGER_SHADOWDISTANCETYPE", m_CurrentShadowProjectionType); } if (overwrite || (m_CurrentShadowmaskModeType != ShadowmaskModeType)) { m_CurrentShadowmaskModeType = ShadowmaskModeType; QualitySettings.shadowmaskMode = m_CurrentShadowmaskModeType; PlayerPrefsUtil.SetEnum("SETTINGSMANAGER_SHADOWMASKMODE", m_CurrentShadowmaskModeType); } if (overwrite || (m_CurrentShadowNearPlaneOffset != ShadowNearPlaneOffset)) { m_CurrentShadowNearPlaneOffset = ShadowNearPlaneOffset; QualitySettings.shadowNearPlaneOffset = m_CurrentShadowNearPlaneOffset; PlayerPrefs.SetInt("SETTINGSMANAGER_SHADOWNEARPLANEOFFSET", m_CurrentShadowNearPlaneOffset); } if (overwrite || (m_CurrentShadowCascadeType != ShadowCascadeType)) { m_CurrentShadowCascadeType = ShadowCascadeType; QualitySettings.shadowCascades = (int)m_CurrentShadowCascadeType; PlayerPrefsUtil.SetEnum("SETTINGSMANAGER_SHADOWCASCADETYPE", m_CurrentShadowCascadeType); } }