Skip to content

Commit

Permalink
More Refactoring and Clean Up
Browse files Browse the repository at this point in the history
  • Loading branch information
maikramer committed Mar 22, 2019
1 parent 78ea6c5 commit 6e505a9
Show file tree
Hide file tree
Showing 20 changed files with 1,150 additions and 1,256 deletions.
1,985 changes: 947 additions & 1,038 deletions .idea/.idea.Materialize/.idea/workspace.xml

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions Assets/Scripts/General/ProgramEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ public enum FileFormat
Invalid
}

public enum GraphicsQuality
{
High,
Medium,
Low
}

public enum MapType
{
None,
Expand All @@ -33,12 +40,5 @@ public enum ScreenMode
FullScreen,
Windowed
}

public enum GraphicsQuality
{
High,
Medium,
Low
}
}
}
17 changes: 7 additions & 10 deletions Assets/Scripts/General/ProgramManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ public class ProgramManager : MonoBehaviour
private int _windowId;
public bool ApplicationIsQuitting;
public int DesiredFrameRate;
public ProgramEnums.GraphicsQuality GraphicsQuality;
public Vector2 GuiScale = new Vector2(1, 1);
public HDRenderPipelineAsset HighQualityAsset;
[HideInInspector] public string LastPath;
public HDRenderPipelineAsset LowQualityAsset;
public Light MainLight;
public MessagePanel MessagePanelObject;
public HDRenderPipeline RenderPipeline;
public HDRenderPipelineAsset HighQualityAsset;
public HDRenderPipelineAsset MediumQualityAsset;
public HDRenderPipelineAsset LowQualityAsset;
public ProgramEnums.GraphicsQuality GraphicsQuality;
public MessagePanel MessagePanelObject;
public Volume PostProcessingVolume;
public HDRenderPipeline RenderPipeline;
public Volume SceneVolume;

#region Settings
Expand Down Expand Up @@ -215,10 +215,7 @@ public static IEnumerator SetScreen(ProgramEnums.ScreenMode screenMode)
if (Application.isEditor) yield break;
yield return null;

if (MainGui.Instance)
{
MainGui.Instance.CloseWindows();
}
if (MainGui.Instance) MainGui.Instance.CloseWindows();

Instance.PostProcessingVolume.enabled = false;
Instance.SceneVolume.enabled = false;
Expand Down Expand Up @@ -276,7 +273,7 @@ private static HDRenderPipelineAsset GetRpQualityAsset()
}

/// <summary>
/// Get the Highest resolution skipping n matches
/// Get the Highest resolution skipping n matches
/// </summary>
/// <param name="skip"> number of matches to skip</param>
/// <returns> resolution after n skips in the same aspect ratio than native </returns>
Expand Down
11 changes: 6 additions & 5 deletions Assets/Scripts/General/SaveLoadProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using Plugins.Extension;
using Settings;
using UnityEngine;
using Graphics = UnityEngine.Graphics;

#if UNITY_STANDALONE_WIN
using System.Windows.Forms;
using System.Drawing;
Expand Down Expand Up @@ -232,22 +232,26 @@ private IEnumerator SaveTexture(Texture2D textureToSave, string pathToFile)
bytes = textureToSave.EncodeToPNG();
break;
}

case "jpg":
{
bytes = textureToSave.EncodeToJPG();
break;
}

case "tga":
{
bytes = ImageConversion.EncodeToTGA(textureToSave);
break;
}

case "exr":
{
const Texture2D.EXRFlags flags = Texture2D.EXRFlags.CompressZIP;
bytes = textureToSave.EncodeToEXR(flags);
break;
}

default:
throw new ArgumentOutOfRangeException(nameof(extension), extension, null);
}
Expand Down Expand Up @@ -389,10 +393,7 @@ public IEnumerator LoadTexture(ProgramEnums.MapType textureToLoad, string pathTo
private static void ClearPanelQuickSave()
{
var panels = FindObjectsOfType<TexturePanel>();
foreach (var panel in panels)
{
panel.QuickSavePath = null;
}
foreach (var panel in panels) panel.QuickSavePath = null;
}

#if UNITY_STANDALONE_WIN
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/General/TextureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public class TextureManager : MonoBehaviour
[UsedImplicitly] [SerializeField] private Material FullMaterial = null;
public bool Hdr;
public ComputeShader MaskMapCompute;
public ComputeShader TextureProcessingCompute;
public RenderTextureFormat RenderTextureFormat;

[HideInInspector] public ProgramEnums.MapType TextureInClipboard;
public ComputeShader TextureProcessingCompute;
public Material FullMaterialInstance { get; private set; }

private void Awake()
Expand Down Expand Up @@ -225,7 +225,7 @@ public void SetFullMaterial()
public void CleanMaterial()
{
ProgramManager.Instance.TestObject.GetComponent<Renderer>().material = null;
GameObject.Destroy(FullMaterialInstance);
Destroy(FullMaterialInstance);
FullMaterialInstance = new Material(FullMaterial);
}

Expand Down
24 changes: 11 additions & 13 deletions Assets/Scripts/Gui/AoFromNormalGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public class AoFromNormalGui : TexturePanelGui
private AoSettings _aos;
private RenderTexture _blendedAoMap;

private int _imageSizeX;
private int _imageSizeY;
private int _kernelAo;
private int _kernelCombine;

Expand All @@ -36,18 +34,18 @@ protected override IEnumerator Process()
{
MessagePanel.ShowMessage("Processing Ambient Occlusion");

var tempAoMap = TextureManager.Instance.GetTempRenderTexture(_imageSizeX, _imageSizeY);
var tempAoMap = TextureManager.Instance.GetTempRenderTexture(ImageSize.x, ImageSize.y);

AoCompute.SetFloat(FinalBias, _aos.FinalBias);
AoCompute.SetFloat(FinalContrast, _aos.FinalContrast);
AoCompute.SetTexture(_kernelCombine, ImageInput, _blendedAoMap);
AoCompute.SetFloat(AoBlend, _aos.Blend);
AoCompute.SetVector(ImageSize, new Vector2(_imageSizeX, _imageSizeY));
AoCompute.SetVector(ImageSizeId, new Vector2(ImageSize.x, ImageSize.y));

AoCompute.SetTexture(_kernelCombine, "ImageInput", _blendedAoMap);
AoCompute.SetTexture(_kernelCombine, "Result", tempAoMap);
var groupsX = (int) Mathf.Ceil(_imageSizeX / 8f);
var groupsY = (int) Mathf.Ceil(_imageSizeY / 8f);
var groupsX = (int) Mathf.Ceil(ImageSize.x / 8f);
var groupsY = (int) Mathf.Ceil(ImageSize.y / 8f);
AoCompute.Dispatch(_kernelCombine, groupsX, groupsY, 1);

TextureManager.Instance.GetTextureFromRender(tempAoMap, ProgramEnums.MapType.Ao);
Expand Down Expand Up @@ -168,12 +166,12 @@ public void InitializeTextures()

CleanupTextures();

_imageSizeX = TextureManager.Instance.NormalMap.width;
_imageSizeY = TextureManager.Instance.NormalMap.height;
ImageSize.x = TextureManager.Instance.NormalMap.width;
ImageSize.y = TextureManager.Instance.NormalMap.height;

Logger.Log("Initializing Textures of size: " + _imageSizeX + "x" + _imageSizeY);
Logger.Log("Initializing Textures of size: " + ImageSize.x + "x" + ImageSize.y);

_blendedAoMap = TextureManager.Instance.GetTempRenderTexture(_imageSizeX, _imageSizeY);
_blendedAoMap = TextureManager.Instance.GetTempRenderTexture(ImageSize.x, ImageSize.y);
ThisMaterial.SetTexture(NormalTex, TextureManager.Instance.NormalMap);
}

Expand All @@ -189,7 +187,7 @@ public IEnumerator ProcessNormalDepth()

MessagePanel.ShowMessage("Processing Normal Depth");

AoCompute.SetVector(ImageSize, new Vector4(_imageSizeX, _imageSizeY, 0, 0));
AoCompute.SetVector(ImageSizeId, new Vector4(ImageSize.x, ImageSize.y, 0, 0));
AoCompute.SetFloat(Spread, _aos.Spread);

AoCompute.SetTexture(_kernelAo, ImageInput, TextureManager.Instance.NormalMap);
Expand All @@ -215,8 +213,8 @@ public IEnumerator ProcessNormalDepth()
{
AoCompute.SetFloat(BlendAmount, 1.0f / i);
AoCompute.SetFloat(Progress, i / 100.0f);
var groupsX = (int) Mathf.Ceil(_imageSizeX / 8f);
var groupsY = (int) Mathf.Ceil(_imageSizeY / 8f);
var groupsX = (int) Mathf.Ceil(ImageSize.x / 8f);
var groupsY = (int) Mathf.Ceil(ImageSize.y / 8f);
AoCompute.Dispatch(_kernelAo, groupsX, groupsY, 1);


Expand Down
22 changes: 10 additions & 12 deletions Assets/Scripts/Gui/EditDiffuseGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public class EditDiffuseGui : TexturePanelGui

private EditDiffuseSettings _eds;

private int _imageSizeX;
private int _imageSizeY;
private Material _material;
private bool _settingsInitialized;

Expand All @@ -38,7 +36,7 @@ protected override IEnumerator Process()
{
Logger.Log("Processing Diffuse");

_blitMaterial.SetVector(ImageSize, new Vector4(_imageSizeX, _imageSizeY, 0, 0));
_blitMaterial.SetVector(ImageSizeId, new Vector4(ImageSize.x, ImageSize.y, 0, 0));

_blitMaterial.SetTexture(MainTex, _diffuseMapOriginal);

Expand All @@ -65,14 +63,14 @@ protected override IEnumerator Process()
_blitMaterial.SetFloat(Saturation, _eds.Saturation);

RenderTexture.ReleaseTemporary(_tempMap);
_tempMap = TextureManager.Instance.GetTempRenderTexture(_imageSizeX, _imageSizeY);
_tempMap = TextureManager.Instance.GetTempRenderTexture(ImageSize.x, ImageSize.y);

Graphics.Blit(_diffuseMapOriginal, _tempMap, _blitMaterial, 11);

TextureManager.Instance.GetTextureFromRender(_tempMap, ProgramEnums.MapType.Diffuse);

RenderTexture.ReleaseTemporary(_tempMap);

yield break;
}

Expand Down Expand Up @@ -246,13 +244,13 @@ private void InitializeTextures()

_material.SetTexture(MainTex, _diffuseMapOriginal);

_imageSizeX = _diffuseMapOriginal.width;
_imageSizeY = _diffuseMapOriginal.height;
ImageSize.x = _diffuseMapOriginal.width;
ImageSize.y = _diffuseMapOriginal.height;

Logger.Log("Initializing Textures of size: " + _imageSizeX + "x" + _imageSizeY);
Logger.Log("Initializing Textures of size: " + ImageSize.x + "x" + ImageSize.y);

_blurMap = TextureManager.Instance.GetTempRenderTexture(_imageSizeX, _imageSizeY);
_avgMap = TextureManager.Instance.GetTempRenderTexture(_imageSizeX, _imageSizeY);
_blurMap = TextureManager.Instance.GetTempRenderTexture(ImageSize.x, ImageSize.y);
_avgMap = TextureManager.Instance.GetTempRenderTexture(ImageSize.x, ImageSize.y);
}

private IEnumerator ProcessBlur()
Expand All @@ -262,9 +260,9 @@ private IEnumerator ProcessBlur()
Logger.Log("Processing Blur");

RenderTexture.ReleaseTemporary(_tempMap);
_tempMap = TextureManager.Instance.GetTempRenderTexture(_imageSizeX, _imageSizeY);
_tempMap = TextureManager.Instance.GetTempRenderTexture(ImageSize.x, ImageSize.y);

_blitMaterial.SetVector(ImageSize, new Vector4(_imageSizeX, _imageSizeY, 0, 0));
_blitMaterial.SetVector(ImageSizeId, new Vector4(ImageSize.x, ImageSize.y, 0, 0));
_blitMaterial.SetFloat(BlurContrast, 1.0f);
_blitMaterial.SetFloat(BlurSpread, 1.0f);

Expand Down
Loading

0 comments on commit 6e505a9

Please sign in to comment.