Skip to content

Commit

Permalink
Enabled volumetrics, added support for multiple post process volumes
Browse files Browse the repository at this point in the history
added volumetrics support (HDRPAsset supportVolumetrics = true)

added support for multiple volumes
If only 1 global volume, it's used for both map_preset and other presets
If 2 or more, the highest one (in priority) is reserved for presets and the second highest for map_preset
So map creators should create a separate global volume with the highest priority and reserve it for the mod
  • Loading branch information
andreamatt committed Jan 25, 2020
1 parent b4878df commit 981b755
Show file tree
Hide file tree
Showing 13 changed files with 388 additions and 303 deletions.
15 changes: 13 additions & 2 deletions BabboSettings/BabboSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using ReplayEditor;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.Rendering.HDPipeline;
using UnityEngine.Rendering;
using UnityEngine.Rendering.PostProcessing;

namespace BabboSettings
Expand All @@ -20,7 +22,7 @@ public static BabboSettings Instance {

private GameEffects effects;
private Window window;
private MapPreset mapPreset;
private MapPresetUpdater mapPresetUpdater;
private CustomCameraController cameraController;
public PresetsManager presetsManager;
//private DayNightController dayNightController;
Expand All @@ -36,7 +38,7 @@ public void Start() {
DontDestroyOnLoad(gameObject);

effects = gameObject.AddComponent<GameEffects>();
mapPreset = gameObject.AddComponent<MapPreset>();
mapPresetUpdater = gameObject.AddComponent<MapPresetUpdater>();
window = gameObject.AddComponent<Window>();
PatchData.Instance.window = window;
cameraController = gameObject.AddComponent<CustomCameraController>();
Expand All @@ -50,6 +52,15 @@ public void Start() {
private void Update() {
// if the map changed, needs to find/create new effects
effects.checkAndGetEffects();

//var HDRPAsset = FindObjectOfType<HDRenderPipelineAsset>();
//if (HDRPAsset != null) {
// Logger.Log("Asset found");
// HDRPAsset.renderPipelineSettings.supportVolumetrics = true;
//}
//else {
// Logger.Log("Asset not found");
//}
}

private bool last_IsReplayActive = false;
Expand Down
11 changes: 10 additions & 1 deletion BabboSettings/BabboSettings.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@
<ItemGroup>
<Compile Include="CameraMode.cs" />
<Compile Include="DayNightController.cs" />
<Compile Include="EffectSuite.cs" />
<Compile Include="FocusMode.cs" />
<Compile Include="GameEffects.cs" />
<Compile Include="Logger.cs" />
<Compile Include="MapPreset.cs" />
<Compile Include="MapPresetUpdater.cs" />
<Compile Include="Module.cs" />
<Compile Include="PatchData.cs" />
<Compile Include="Patches\KeyFramePatches.cs" />
Expand Down Expand Up @@ -77,6 +78,14 @@
<Reference Include="Unity.Postprocessing.Runtime">
<HintPath>..\References\Unity.Postprocessing.Runtime.dll</HintPath>
</Reference>
<Reference Include="Unity.RenderPipelines.Core.Runtime, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\Unity.RenderPipelines.Core.Runtime.dll</HintPath>
</Reference>
<Reference Include="Unity.RenderPipelines.HighDefinition.Runtime, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\Unity.RenderPipelines.HighDefinition.Runtime.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\References\UnityEngine.CoreModule.dll</HintPath>
Expand Down
95 changes: 95 additions & 0 deletions BabboSettings/EffectSuite.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine.Rendering.PostProcessing;

namespace BabboSettings
{
public class EffectSuite
{
public AmbientOcclusion AO;
public AutoExposure EXPO;
public Bloom BLOOM;
public ChromaticAberration CA;
public ColorGrading COLOR; // NOT SERIALIZABLE
public DepthOfField DOF;
public Grain GRAIN;
public LensDistortion LENS;
public MotionBlur BLUR;
public ScreenSpaceReflections REFL;
public Vignette VIGN;

public static EffectSuite FromVolume(PostProcessVolume post_volume) {
if (post_volume == null) {
Logger.Debug("Post_volume is null in EffectSuite.FromVolume");
return null;
}

var suite = new EffectSuite();
string not_found = "";
if ((suite.AO = post_volume.profile.GetSetting<AmbientOcclusion>()) == null) {
not_found += "ao,";
suite.AO = post_volume.profile.AddSettings<AmbientOcclusion>();
suite.AO.enabled.Override(false);
}
if ((suite.EXPO = post_volume.profile.GetSetting<AutoExposure>()) == null) {
not_found += "expo,";
suite.EXPO = post_volume.profile.AddSettings<AutoExposure>();
suite.EXPO.enabled.Override(false);
}
if ((suite.BLOOM = post_volume.profile.GetSetting<Bloom>()) == null) {
not_found += "bloom,";
suite.BLOOM = post_volume.profile.AddSettings<Bloom>();
suite.BLOOM.enabled.Override(false);
}
if ((suite.CA = post_volume.profile.GetSetting<ChromaticAberration>()) == null) {
not_found += "ca,";
suite.CA = post_volume.profile.AddSettings<ChromaticAberration>();
suite.CA.enabled.Override(false);
}
if ((suite.COLOR = post_volume.profile.GetSetting<ColorGrading>()) == null) {
not_found += "color,";
suite.COLOR = post_volume.profile.AddSettings<ColorGrading>();
suite.COLOR.enabled.Override(false);
}
if ((suite.DOF = post_volume.profile.GetSetting<DepthOfField>()) == null) {
not_found += "dof,";
suite.DOF = post_volume.profile.AddSettings<DepthOfField>();
suite.DOF.enabled.Override(false);
}
if ((suite.GRAIN = post_volume.profile.GetSetting<Grain>()) == null) {
not_found += "grain,";
suite.GRAIN = post_volume.profile.AddSettings<Grain>();
suite.GRAIN.enabled.Override(false);
}
if ((suite.BLUR = post_volume.profile.GetSetting<MotionBlur>()) == null) {
not_found += "blur,";
suite.BLUR = post_volume.profile.AddSettings<MotionBlur>();
suite.BLUR.enabled.Override(false);
}
if ((suite.LENS = post_volume.profile.GetSetting<LensDistortion>()) == null) {
not_found += "lens,";
suite.LENS = post_volume.profile.AddSettings<LensDistortion>();
suite.LENS.enabled.Override(false);
}
if ((suite.REFL = post_volume.profile.GetSetting<ScreenSpaceReflections>()) == null) {
not_found += "refl,";
suite.REFL = post_volume.profile.AddSettings<ScreenSpaceReflections>();
suite.REFL.enabled.Override(false);
}
if ((suite.VIGN = post_volume.profile.GetSetting<Vignette>()) == null) {
not_found += "vign,";
suite.VIGN = post_volume.profile.AddSettings<Vignette>();
suite.VIGN.enabled.Override(false);
}

if (not_found.Length > 0) {
Logger.Debug("Not found: " + not_found);
}

return suite;
}
}
}
111 changes: 36 additions & 75 deletions BabboSettings/GameEffects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Experimental.Rendering.HDPipeline;
using UnityEngine.Rendering;
using UnityEngine.Rendering.PostProcessing;

namespace BabboSettings
Expand All @@ -15,22 +17,15 @@ public class GameEffects : Module
// Settings stuff
public PostProcessLayer post_layer;
public PostProcessVolume post_volume;
public PostProcessVolume map_post_volume;
public FastApproximateAntialiasing FXAA;
public TemporalAntialiasing TAA; // NOT SERIALIZABLE
public SubpixelMorphologicalAntialiasing SMAA;

public AmbientOcclusion AO;
public AutoExposure EXPO;
public Bloom BLOOM;
public ChromaticAberration CA;
public ColorGrading COLOR; // NOT SERIALIZABLE
public DepthOfField DOF;
public FocusMode focus_mode = FocusMode.Custom;
public Grain GRAIN;
public LensDistortion LENS;
public MotionBlur BLUR;
public ScreenSpaceReflections REFL;
public Vignette VIGN;

public EffectSuite effectSuite;
public EffectSuite map_effectSuite;

private void getEffects() {
post_layer = Camera.main.GetComponent<PostProcessLayer>();
Expand All @@ -41,78 +36,44 @@ private void getEffects() {
post_layer.enabled = true;
Logger.Debug("post_layer was disabled");
}
post_volume = FindObjectOfType<PostProcessVolume>();
if (post_volume != null) {
string not_found = "";
if ((AO = post_volume.profile.GetSetting<AmbientOcclusion>()) == null) {
not_found += "ao,";
AO = post_volume.profile.AddSettings<AmbientOcclusion>();
AO.enabled.Override(false);
}
if ((EXPO = post_volume.profile.GetSetting<AutoExposure>()) == null) {
not_found += "expo,";
EXPO = post_volume.profile.AddSettings<AutoExposure>();
EXPO.enabled.Override(false);
}
if ((BLOOM = post_volume.profile.GetSetting<Bloom>()) == null) {
not_found += "bloom,";
BLOOM = post_volume.profile.AddSettings<Bloom>();
BLOOM.enabled.Override(false);
}
if ((CA = post_volume.profile.GetSetting<ChromaticAberration>()) == null) {
not_found += "ca,";
CA = post_volume.profile.AddSettings<ChromaticAberration>();
CA.enabled.Override(false);
}
if ((COLOR = post_volume.profile.GetSetting<ColorGrading>()) == null) {
not_found += "color,";
COLOR = post_volume.profile.AddSettings<ColorGrading>();
COLOR.enabled.Override(false);
}
if ((DOF = post_volume.profile.GetSetting<DepthOfField>()) == null) {
not_found += "dof,";
DOF = post_volume.profile.AddSettings<DepthOfField>();
DOF.enabled.Override(false);
}
if ((GRAIN = post_volume.profile.GetSetting<Grain>()) == null) {
not_found += "grain,";
GRAIN = post_volume.profile.AddSettings<Grain>();
GRAIN.enabled.Override(false);
}
if ((BLUR = post_volume.profile.GetSetting<MotionBlur>()) == null) {
not_found += "blur,";
BLUR = post_volume.profile.AddSettings<MotionBlur>();
BLUR.enabled.Override(false);
}
if ((LENS = post_volume.profile.GetSetting<LensDistortion>()) == null) {
not_found += "lens,";
LENS = post_volume.profile.AddSettings<LensDistortion>();
LENS.enabled.Override(false);
}
if ((REFL = post_volume.profile.GetSetting<ScreenSpaceReflections>()) == null) {
not_found += "refl,";
REFL = post_volume.profile.AddSettings<ScreenSpaceReflections>();
REFL.enabled.Override(false);
}
if ((VIGN = post_volume.profile.GetSetting<Vignette>()) == null) {
not_found += "vign,";
VIGN = post_volume.profile.AddSettings<Vignette>();
VIGN.enabled.Override(false);
}
if (not_found.Length > 0) {
Logger.Debug("Not found: " + not_found);
}

// get global volumes, order by decreasing priority
var allVolumes = FindObjectsOfType<PostProcessVolume>().Where(v => v.isGlobal).OrderBy(v => -v.priority).ToList();
Logger.Log($"Found {allVolumes.Count} volumes");
if (allVolumes.Count == 0) {
Logger.Log("No global volumes");
}
else if (allVolumes.Count == 1) {
Logger.Log("Only 1 global volume");
map_post_volume = post_volume = allVolumes.First();
}
else if (allVolumes.Count == 2) { // expected behaviour
post_volume = allVolumes[0];
map_post_volume = allVolumes[1];
}
else {
Logger.Debug("Post_volume is null in getEffects");
Logger.Log("More than 2 global volumes");
post_volume = allVolumes[0];
map_post_volume = allVolumes[1];
}

// get effects for the mod
effectSuite = EffectSuite.FromVolume(post_volume);

// get global map volume effects
map_effectSuite = EffectSuite.FromVolume(map_post_volume);


FXAA = post_layer.fastApproximateAntialiasing;
TAA = post_layer.temporalAntialiasing;
SMAA = post_layer.subpixelMorphologicalAntialiasing;

mapPreset.GetMapEffects();

// enable volumetric lighting/fog/...
var pipelineAsset = GraphicsSettings.renderPipelineAsset as HDRenderPipelineAsset;
pipelineAsset.renderPipelineSettings.supportVolumetrics = true;

presetsManager.ApplySettings();
presetsManager.ApplyPresets();

Expand Down Expand Up @@ -166,10 +127,10 @@ public override void LateUpdate() {
skate_pos = PlayerController.Instance.boardController.boardTransform.position;
}
if (focus_mode == FocusMode.Player) {
DOF.focusDistance.Override(Vector3.Distance(player_pos, cameraController.mainCamera.transform.position));
effectSuite.DOF.focusDistance.Override(Vector3.Distance(player_pos, cameraController.mainCamera.transform.position));
}
else if (focus_mode == FocusMode.Skate) {
DOF.focusDistance.Override(Vector3.Distance(skate_pos, cameraController.mainCamera.transform.position));
effectSuite.DOF.focusDistance.Override(Vector3.Distance(skate_pos, cameraController.mainCamera.transform.position));
}
}
}
Expand Down
Loading

0 comments on commit 981b755

Please sign in to comment.