diff --git a/src/optionals/SM.Intergrations/SMRenderer.Intergrations.csproj b/src/optionals/SM.Intergrations/SMRenderer.Intergrations.csproj
index aeea189..580452a 100644
--- a/src/optionals/SM.Intergrations/SMRenderer.Intergrations.csproj
+++ b/src/optionals/SM.Intergrations/SMRenderer.Intergrations.csproj
@@ -9,7 +9,7 @@
Properties
SM.Intergrations
SM.Intergrations
- v4.5.2
+ v4.7.2
512
true
diff --git a/src/optionals/SM.Intergrations/ShaderTool/STMaterialShader.cs b/src/optionals/SM.Intergrations/ShaderTool/STMaterialShader.cs
index 84022fc..dbc876e 100644
--- a/src/optionals/SM.Intergrations/ShaderTool/STMaterialShader.cs
+++ b/src/optionals/SM.Intergrations/ShaderTool/STMaterialShader.cs
@@ -23,30 +23,30 @@ namespace SM.Intergrations.ShaderTool
STPCompositeNode composeNode = drawNode.OGLEffect;
- ShaderFileFiles.Vertex = new[] { new ShaderFile(composeNode.Vertex.ShaderCode) };
- ShaderFileFiles.Fragment = new [] {new ShaderFile(composeNode.Fragment.ShaderCode)};
+ ShaderFiles.Vertex = new[] { new ShaderFile(composeNode.Vertex.ShaderCode) };
+ ShaderFiles.Fragment = new [] {new ShaderFile(composeNode.Fragment.ShaderCode)};
if (composeNode.Geometry != null)
- ShaderFileFiles.Geometry = new[] {new ShaderFile(composeNode.Geometry.ShaderCode)};
+ ShaderFiles.Geometry = new[] {new ShaderFile(composeNode.Geometry.ShaderCode)};
foreach (KeyValuePair pair in drawNode.Variables)
{
switch (pair.Value.Type)
{
case STPBasisType.Bool:
- _uniforms += context => Uniforms[pair.Key].SetUniform1(context.Material.ShaderArguments.Get(pair.Key, false));
+ _uniforms += context => Uniforms[pair.Key].SetBool(context.Material.ShaderArguments.Get(pair.Key, false));
break;
case STPBasisType.Float:
- _uniforms += context => Uniforms[pair.Key].SetUniform1(context.Material.ShaderArguments.Get(pair.Key, 0.0f));
+ _uniforms += context => Uniforms[pair.Key].SetFloat(context.Material.ShaderArguments.Get(pair.Key, 0.0f));
break;
case STPBasisType.Vector2:
- _uniforms += context => Uniforms[pair.Key].SetUniform2(context.Material.ShaderArguments.Get(pair.Key, Vector2.Zero));
+ _uniforms += context => Uniforms[pair.Key].SetVector2(context.Material.ShaderArguments.Get(pair.Key, Vector2.Zero));
break;
case STPBasisType.Vector3:
- _uniforms += context => Uniforms[pair.Key].SetUniform3(context.Material.ShaderArguments.Get(pair.Key, Vector3.Zero));
+ _uniforms += context => Uniforms[pair.Key].SetVector3(context.Material.ShaderArguments.Get(pair.Key, Vector3.Zero));
break;
case STPBasisType.Vector4:
_uniforms += context =>
- Uniforms[pair.Key].SetUniform4(context.Material.ShaderArguments.Get(pair.Key, Vector4.Zero));
+ Uniforms[pair.Key].SetVector4(context.Material.ShaderArguments.Get(pair.Key, Vector4.Zero));
break;
case STPBasisType.Matrix:
_uniforms += context => Uniforms[pair.Key].SetMatrix4(context.Material.ShaderArguments.Get(pair.Key, Matrix4.Identity));
diff --git a/src/optionals/SM.Intergrations/ShaderTool/STPostProcessEffect.cs b/src/optionals/SM.Intergrations/ShaderTool/STPostProcessEffect.cs
index f62445c..461b046 100644
--- a/src/optionals/SM.Intergrations/ShaderTool/STPostProcessEffect.cs
+++ b/src/optionals/SM.Intergrations/ShaderTool/STPostProcessEffect.cs
@@ -39,7 +39,7 @@ namespace SM.Intergrations.ShaderTool
}
}
- public override void Draw(ColorAttachment source, DrawContext context)
+ protected override void Drawing(ColorAttachment source, DrawContext context)
{
Arguments["_Scene"] = (TextureBase)source;
Arguments["_MVP"] = Mvp;
diff --git a/src/optionals/SM.Intergrations/ShaderTool/STPostProcessShader.cs b/src/optionals/SM.Intergrations/ShaderTool/STPostProcessShader.cs
index 35a1b4c..a8226cc 100644
--- a/src/optionals/SM.Intergrations/ShaderTool/STPostProcessShader.cs
+++ b/src/optionals/SM.Intergrations/ShaderTool/STPostProcessShader.cs
@@ -23,30 +23,30 @@ namespace SM.Intergrations.ShaderTool
STPCompositeNode composeNode = postProcessNode.OGLEffect;
- ShaderFileFiles.Vertex = new[] { new ShaderFile(composeNode.Vertex.ShaderCode) };
- ShaderFileFiles.Fragment = new[] { new ShaderFile(composeNode.Fragment.ShaderCode) };
+ ShaderFiles.Vertex = new[] { new ShaderFile(composeNode.Vertex.ShaderCode) };
+ ShaderFiles.Fragment = new[] { new ShaderFile(composeNode.Fragment.ShaderCode) };
if (composeNode.Geometry != null)
- ShaderFileFiles.Geometry = new[] { new ShaderFile(composeNode.Geometry.ShaderCode) };
+ ShaderFiles.Geometry = new[] { new ShaderFile(composeNode.Geometry.ShaderCode) };
foreach (KeyValuePair pair in postProcessNode.Variables)
{
switch (pair.Value.Type)
{
case STPBasisType.Bool:
- _uniforms += context => Uniforms[pair.Key].SetUniform1(context.Get(pair.Key, false));
+ _uniforms += context => Uniforms[pair.Key].SetBool(context.Get(pair.Key, false));
break;
case STPBasisType.Float:
- _uniforms += context => Uniforms[pair.Key].SetUniform1(context.Get(pair.Key, 0.0f));
+ _uniforms += context => Uniforms[pair.Key].SetFloat(context.Get(pair.Key, 0.0f));
break;
case STPBasisType.Vector2:
- _uniforms += context => Uniforms[pair.Key].SetUniform2(context.Get(pair.Key, Vector2.Zero));
+ _uniforms += context => Uniforms[pair.Key].SetVector2(context.Get(pair.Key, Vector2.Zero));
break;
case STPBasisType.Vector3:
- _uniforms += context => Uniforms[pair.Key].SetUniform3(context.Get(pair.Key, Vector3.Zero));
+ _uniforms += context => Uniforms[pair.Key].SetVector3(context.Get(pair.Key, Vector3.Zero));
break;
case STPBasisType.Vector4:
_uniforms += context =>
- Uniforms[pair.Key].SetUniform4(context.Get(pair.Key, Vector4.Zero));
+ Uniforms[pair.Key].SetVector4(context.Get(pair.Key, Vector4.Zero));
break;
case STPBasisType.Matrix:
_uniforms += context => Uniforms[pair.Key].SetMatrix4(context.Get(pair.Key, Matrix4.Identity));
diff --git a/src/optionals/SM.Utils/Controls/GameController.cs b/src/optionals/SM.Utils/Controls/GameController.cs
index abac97a..43570dc 100644
--- a/src/optionals/SM.Utils/Controls/GameController.cs
+++ b/src/optionals/SM.Utils/Controls/GameController.cs
@@ -1,38 +1,55 @@
using SharpDX.XInput;
+using SM.Base;
namespace SM.Utils.Controls
{
- public struct GameController
+ public class GameController
{
- public static float GlobalDeadband = 2500;
+ public static float GlobalDeadband = .1F;
private Controller _controller;
+ private ulong _lastFrame;
+
+ internal GamepadButtonFlags _lastPressedButtons;
public float Deadband { get; set; }
public bool IsConnected => _controller.IsConnected;
- public UserIndex Index { get; private set; }
+ public GameControllerState LastState { get; private set; }
+ public UserIndex Index { get; private set; }
+
public GameController(int id) : this((UserIndex)id)
{}
public GameController(UserIndex index = UserIndex.Any)
{
+ _lastPressedButtons = GamepadButtonFlags.None;
_controller = new Controller(index);
Index = index;
Deadband = GlobalDeadband;
}
- public GameControllerState GetState()
+ public GameControllerState GetState(bool force = false)
{
- if (!IsConnected)
+ if (!force && _lastFrame == SMRenderer.CurrentFrame)
{
- return new GameControllerState(true);
+ return LastState;
}
- Gamepad state = _controller.GetState().Gamepad;
+ GameControllerState st = new GameControllerState(true);
+ if (IsConnected)
+ {
+ Gamepad state = _controller.GetState().Gamepad;
+ st = new GameControllerState(state, this);
+ _lastPressedButtons = state.Buttons;
+ }
- return new GameControllerState(state, ref this);
+ LastState = st;
+
+ _lastFrame = SMRenderer.CurrentFrame;
+
+ return st;
}
}
diff --git a/src/optionals/SM.Utils/Controls/GameControllerState.cs b/src/optionals/SM.Utils/Controls/GameControllerState.cs
index d080ec3..7a20aa4 100644
--- a/src/optionals/SM.Utils/Controls/GameControllerState.cs
+++ b/src/optionals/SM.Utils/Controls/GameControllerState.cs
@@ -22,22 +22,11 @@ namespace SM.Utils.Controls
DPad = GameControllerStateDPad.Default;
Buttons = GameControllerStateButtons.Default;
}
- internal GameControllerState(Gamepad state, ref GameController controller)
+ internal GameControllerState(Gamepad state, GameController controller)
{
FromConnected = true;
- Thumbs = new GameControllerStateThumbs
- {
- Left = new Vector2(
- Math.Abs((float)state.LeftThumbX) < controller.Deadband ? 0 : (float)state.LeftThumbX / short.MaxValue,
- Math.Abs((float)state.LeftThumbY) < controller.Deadband ? 0 : (float)state.LeftThumbY / short.MaxValue),
- Right = new Vector2(
- Math.Abs((float)state.RightThumbX) < controller.Deadband ? 0 : (float)state.RightThumbX / short.MaxValue,
- Math.Abs((float)state.RightThumbY) < controller.Deadband ? 0 : (float)state.RightThumbY / short.MaxValue),
-
- PressedLeft = state.Buttons.HasFlag(GamepadButtonFlags.LeftThumb),
- PressedRight = state.Buttons.HasFlag(GamepadButtonFlags.RightThumb)
- };
+ Thumbs = new GameControllerStateThumbs(controller, state);
Triggers = new GameControllerStateTriggers()
{
@@ -46,7 +35,7 @@ namespace SM.Utils.Controls
};
DPad = new GameControllerStateDPad(state.Buttons);
- Buttons = new GameControllerStateButtons(state.Buttons);
+ Buttons = new GameControllerStateButtons(state.Buttons, controller);
}
public override string ToString()
diff --git a/src/optionals/SM.Utils/Controls/GameControllerStateButtons.cs b/src/optionals/SM.Utils/Controls/GameControllerStateButtons.cs
index 7feeb05..5bcd5f4 100644
--- a/src/optionals/SM.Utils/Controls/GameControllerStateButtons.cs
+++ b/src/optionals/SM.Utils/Controls/GameControllerStateButtons.cs
@@ -4,9 +4,14 @@ namespace SM.Utils.Controls
{
public struct GameControllerStateButtons
{
- public static GameControllerStateButtons Default = new GameControllerStateButtons(GamepadButtonFlags.None);
+ public static GameControllerStateButtons Default = new GameControllerStateButtons()
+ {
+ _buttonFlags = GamepadButtonFlags.None,
+ _lastButtonFlags = GamepadButtonFlags.None
+ };
private GamepadButtonFlags _buttonFlags;
+ private GamepadButtonFlags _lastButtonFlags;
public bool X;
public bool Y;
@@ -22,13 +27,14 @@ namespace SM.Utils.Controls
public bool Start;
public bool Back;
- public bool this[GamepadButtonFlags flags] => _buttonFlags.HasFlag(flags);
+ public bool this[GamepadButtonFlags flags, bool once = false] => _buttonFlags.HasFlag(flags) && !(once && _lastButtonFlags.HasFlag(flags));
public bool AnyInteraction { get; }
- internal GameControllerStateButtons(GamepadButtonFlags flags)
+ internal GameControllerStateButtons(GamepadButtonFlags flags, GameController controller)
{
_buttonFlags = flags;
+ _lastButtonFlags = controller._lastPressedButtons;
X = flags.HasFlag(GamepadButtonFlags.X);
Y = flags.HasFlag(GamepadButtonFlags.Y);
diff --git a/src/optionals/SM.Utils/Controls/GameControllerStateThumbs.cs b/src/optionals/SM.Utils/Controls/GameControllerStateThumbs.cs
index 5a63e45..6741a3c 100644
--- a/src/optionals/SM.Utils/Controls/GameControllerStateThumbs.cs
+++ b/src/optionals/SM.Utils/Controls/GameControllerStateThumbs.cs
@@ -1,4 +1,6 @@
-using OpenTK;
+using System;
+using OpenTK;
+using SharpDX.XInput;
namespace SM.Utils.Controls
{
@@ -15,6 +17,18 @@ namespace SM.Utils.Controls
public bool AnyInteraction => Left != Vector2.Zero || Right != Vector2.Zero || PressedLeft || PressedRight;
+ public GameControllerStateThumbs(GameController controller, Gamepad state)
+ {
+ Vector2 left = new Vector2(state.LeftThumbX, state.LeftThumbY) / short.MaxValue;
+ Vector2 right = new Vector2(state.RightThumbX, state.RightThumbY) / short.MaxValue;
+
+ Left = new Vector2(Math.Abs(left.X) < controller.Deadband ? 0 : left.X, Math.Abs(left.Y) < controller.Deadband ? 0 : left.Y);
+ Right = new Vector2(Math.Abs(right.X) < controller.Deadband ? 0 : right.X, Math.Abs(right.Y) < controller.Deadband ? 0 : right.Y);
+
+ PressedLeft = state.Buttons.HasFlag(GamepadButtonFlags.LeftThumb);
+ PressedRight = state.Buttons.HasFlag(GamepadButtonFlags.RightThumb);
+ }
+
public override string ToString()
{
return $"Left: ({Left.X}; {Left.Y}){(PressedLeft ? " Pressed" : "")}; Right: ({Right.X}; {Right.Y}){(PressedRight ? " Pressed" : "")}";
diff --git a/src/optionals/SM.Utils/Controls/GameKeybindActor.cs b/src/optionals/SM.Utils/Controls/GameKeybindActor.cs
index 1bbc8a5..7dfd976 100644
--- a/src/optionals/SM.Utils/Controls/GameKeybindActor.cs
+++ b/src/optionals/SM.Utils/Controls/GameKeybindActor.cs
@@ -12,16 +12,25 @@ namespace SM.Utils.Controls
public struct GameKeybindActor
{
private GameKeybindActorType _type;
- private GameController? _controller;
+ private GameController _controller;
private GameKeybindHost _keybindHost;
public GameKeybindActorType Type => _type;
- public GameController? Controller => _controller;
+ public GameController Controller => _controller;
public object[] Parameter;
- private GameKeybindActor(GameKeybindActorType type, GameController? controller)
+ private GameKeybindActor(GameKeybindActorType type, GameController controller)
+ {
+ _type = type;
+ _controller = controller;
+
+ _keybindHost = null;
+
+ Parameter = new object[0];
+ }
+ private GameKeybindActor(GameKeybindActorType type, ref GameController controller)
{
_type = type;
_controller = controller;
@@ -58,7 +67,7 @@ namespace SM.Utils.Controls
KeyboardState = Keyboard.GetState(),
MouseState = Mouse.GetState(),
- ControllerState = Controller?.GetState(),
+ ControllerState = Controller?.GetState() ?? new GameControllerState(true),
};
return keybind[Type].Invoke(context);
diff --git a/src/optionals/SM.Utils/Controls/GameKeybindContext.cs b/src/optionals/SM.Utils/Controls/GameKeybindContext.cs
index 189ec44..c08fe7c 100644
--- a/src/optionals/SM.Utils/Controls/GameKeybindContext.cs
+++ b/src/optionals/SM.Utils/Controls/GameKeybindContext.cs
@@ -6,7 +6,7 @@ namespace SM.Utils.Controls
{
public KeyboardState KeyboardState;
public MouseState MouseState;
- public GameControllerState? ControllerState;
+ public GameControllerState ControllerState;
public GameKeybindActor Actor;
public GameKeybindHost Host;
diff --git a/src/optionals/SM.Utils/SMRenderer.Utils.csproj b/src/optionals/SM.Utils/SMRenderer.Utils.csproj
index 92fd385..30b4822 100644
--- a/src/optionals/SM.Utils/SMRenderer.Utils.csproj
+++ b/src/optionals/SM.Utils/SMRenderer.Utils.csproj
@@ -9,9 +9,10 @@
Properties
SM.Utils
SM.Utils
- v4.5.2
+ v4.7.2
512
true
+
true
@@ -61,5 +62,11 @@
+
+
+ {8e733844-4204-43e7-b3dc-3913cddabb0d}
+ SM.Base
+
+
\ No newline at end of file
diff --git a/src/renderer/SM.Base/Controls/Mouse.cs b/src/renderer/SM.Base/Controls/Mouse.cs
index 1309818..0a18ce9 100644
--- a/src/renderer/SM.Base/Controls/Mouse.cs
+++ b/src/renderer/SM.Base/Controls/Mouse.cs
@@ -18,10 +18,20 @@ namespace SM.Base.Controls
private static MouseState? _mouseState;
private static List _lastButtonsPressed = new List();
+ private static Vector2 _inScreen;
+
///
- /// The current position of the mouse in the screen.
+ /// Gets or sets the current position of the mouse in the screen.
///
- public static Vector2 InScreen { get; private set; }
+ public static Vector2 InScreen
+ {
+ get => _inScreen;
+ set
+ {
+ _inScreen = value;
+ UpdateNormalized(SMRenderer.CurrentWindow);
+ }
+ }
///
/// The current position of the mouse in the screen from 0..1.
@@ -40,6 +50,16 @@ namespace SM.Base.Controls
///
public static bool RightClick => IsDown(MouseButton.Right, true);
+ ///
+ /// If true, it disables the tracking of the mouse, allowing you to change the value, without the system replacing it again.
+ ///
+ public static bool StopTracking { get; set; }
+
+ private static void UpdateNormalized(IGenericWindow window)
+ {
+ InScreenNormalized = new Vector2(_inScreen.X / (float)window.Width, _inScreen.Y / (float)window.Height);
+ }
+
///
/// The event to update the values.
///
@@ -47,8 +67,10 @@ namespace SM.Base.Controls
/// The window where the mouse is checked
internal static void MouseMoveEvent(MouseMoveEventArgs mmea, IGenericWindow window)
{
+ if (StopTracking) return;
+
InScreen = new Vector2(mmea.X, mmea.Y);
- InScreenNormalized = new Vector2(mmea.X / (float) window.Width, mmea.Y / (float) window.Height);
+ UpdateNormalized(window);
}
internal static void SetState()
diff --git a/src/renderer/SM.Base/Drawing/Material.cs b/src/renderer/SM.Base/Drawing/Material.cs
index dc8c8fb..c1d1663 100644
--- a/src/renderer/SM.Base/Drawing/Material.cs
+++ b/src/renderer/SM.Base/Drawing/Material.cs
@@ -39,6 +39,10 @@ namespace SM.Base.Drawing
///
public ShaderArguments ShaderArguments { get; internal set; } = new ShaderArguments();
+ ///
+ /// Draws the material with the provided context.
+ ///
+ ///
public virtual void Draw(DrawContext context)
{
context.Shader.Draw(context);
diff --git a/src/renderer/SM.Base/Drawing/Text/TextDrawingBasis.cs b/src/renderer/SM.Base/Drawing/Text/TextDrawingBasis.cs
index 206a63c..9879639 100644
--- a/src/renderer/SM.Base/Drawing/Text/TextDrawingBasis.cs
+++ b/src/renderer/SM.Base/Drawing/Text/TextDrawingBasis.cs
@@ -1,6 +1,8 @@
#region usings
using System;
+using System.Collections.Generic;
+using System.Linq;
using OpenTK;
using OpenTK.Graphics;
using SM.Base.Objects.Static;
@@ -130,9 +132,13 @@ namespace SM.Base.Drawing.Text
{
if (!Font.WasCompiled) Font.RegenerateTexture();
+ if (string.IsNullOrEmpty(_text)) return;
+
_text = _text.Replace("\r\n", "\n").Replace("\t", " ");
_instances = new Instance[_text.Length];
+ List> lines = new List>();
+ List currentLineInstances = new List();
float x = 0;
float y = 0;
@@ -146,8 +152,13 @@ namespace SM.Base.Drawing.Text
if (_text[i] == '\n')
{
+ if (currentLineInstances.Count > 0)
+ {
+ lines.Add(new Tuple(new Vector2(x, y), currentLineInstances.ToArray()));
+ currentLineInstances.Clear();
+ }
+
y += Font.Height;
- Width = Math.Max(Width, x);
x = 0;
continue;
}
@@ -170,32 +181,41 @@ namespace SM.Base.Drawing.Text
var matrix = Matrix4.CreateScale(parameter.Width, Font.Height, 1) *
Matrix4.CreateTranslation(x + parameter.Width / 2, -y, 0);
- _instances[i] = new Instance
+ currentLineInstances.Add(_instances[i] = new Instance
{
ModelMatrix = matrix,
TextureMatrix = parameter.TextureMatrix
- };
+ });
x += parameter.Advance;
}
+ if (currentLineInstances.Count > 0)
+ lines.Add(new Tuple(new Vector2(x, y), currentLineInstances.ToArray()));
+
Height = y + Font.Height;
- Width = x;
+ Width = lines.Max(a => a.Item1.X);
if (Origin != TextOrigin.Left)
{
- foreach (Instance i in _instances)
+ foreach (Tuple line in lines)
{
- if (i == null) continue;
- switch (Origin)
+
+ foreach (Instance i in line.Item2)
{
- case TextOrigin.Center:
- i.ModelMatrix *= Matrix4.CreateTranslation(-Width / 2, 0, 0);
- break;
- case TextOrigin.Right:
- i.ModelMatrix *= Matrix4.CreateTranslation(-Width, 0, 0);
- break;
+ if (i == null) continue;
+ switch (Origin)
+ {
+ case TextOrigin.Center:
+ i.ModelMatrix *= Matrix4.CreateTranslation(-line.Item1.X / 2, 0, 0);
+ break;
+ case TextOrigin.Right:
+ i.ModelMatrix *= Matrix4.CreateTranslation(-line.Item1.X, 0, 0);
+ break;
+ }
}
}
+
+
}
}
}
diff --git a/src/renderer/SM.Base/Legacy/Font.cs b/src/renderer/SM.Base/Legacy/Font.cs
deleted file mode 100644
index 1cebcb6..0000000
--- a/src/renderer/SM.Base/Legacy/Font.cs
+++ /dev/null
@@ -1,144 +0,0 @@
-#region usings
-
-using System.Collections.Generic;
-using System.Drawing;
-using System.Drawing.Text;
-using OpenTK.Graphics.OpenGL4;
-using SM.Base.Textures;
-
-#endregion
-
-namespace SM.Base.Drawing.Text
-{
- ///
- /// Represents a font.
- ///
- public class Font : Texture
- {
- ///
- /// The char set for the font.
- /// Default:
- ///
- public ICollection CharSet = FontCharStorage.SimpleUTF8;
-
- ///
- /// The font family, that is used to find the right font.
- ///
- public FontFamily FontFamily;
-
- ///
- /// The font size.
- /// Default: 12
- ///
- public float FontSize = 12;
-
- public float SpaceWidth { get; private set; }
-
- public float Spacing = 1;
-
- ///
- /// The font style.
- /// Default:
- ///
- public FontStyle FontStyle = FontStyle.Regular;
-
- ///
- /// This contains all information for the different font character.
- ///
- public Dictionary Positions = new Dictionary();
-
- ///
- /// Generates a font from a font family from the specified path.
- ///
- /// The specified path
- public Font(string path)
- {
- var pfc = new PrivateFontCollection();
- pfc.AddFontFile(path);
- FontFamily = pfc.Families[0];
- }
-
- ///
- /// Generates a font from a specified font family.
- ///
- /// Font-Family
- public Font(FontFamily font)
- {
- FontFamily = font;
- }
-
- ///
- public override TextureWrapMode WrapMode { get; set; } = TextureWrapMode.ClampToEdge;
-
- ///
- /// Regenerates the texture.
- ///
- public void RegenerateTexture()
- {
- Width = 0;
- Height = 0;
- Positions = new Dictionary();
-
-
- var map = new Bitmap(1000, 20);
- var charParams = new Dictionary();
- using (var f = new System.Drawing.Font(FontFamily, FontSize, FontStyle))
- {
- using (var g = Graphics.FromImage(map))
- {
- g.Clear(Color.Transparent);
-
- foreach (var c in CharSet)
- {
- var s = c.ToString();
- var size = g.MeasureString(s, f, 0, StringFormat.GenericTypographic);
- try
- {
- charParams.Add(c, new[] {size.Width, Width});
- }
- catch
- {
- // ignored
- }
-
- if (Height < size.Height) Height = (int) size.Height;
- Width += (int) size.Width + 1;
- }
-
- SpaceWidth = g.MeasureString("_", f, 0, StringFormat.GenericTypographic).Width;
- }
-
- map = new Bitmap(Width, Height);
- using (var g = Graphics.FromImage(map))
- {
- foreach (var keyValuePair in charParams)
- {
- var normalizedX = (keyValuePair.Value[1]+ 0.00001f) / Width;
- var normalizedWidth = keyValuePair.Value[0] / Width;
-
- CharParameter parameter;
- Positions.Add(keyValuePair.Key, parameter = new CharParameter
- {
- NormalizedWidth = normalizedWidth,
- NormalizedX = normalizedX,
- Width = keyValuePair.Value[0],
- X = (int) keyValuePair.Value[1]
- });
-
- g.DrawString(keyValuePair.Key.ToString(), f, Brushes.White, parameter.X, 0, StringFormat.GenericTypographic);
- }
- }
- }
-
- Map = map;
- Recompile();
- }
-
- ///
- public override void Compile()
- {
- RegenerateTexture();
- base.Compile();
- }
- }
-}
\ No newline at end of file
diff --git a/src/renderer/SM.Base/Legacy/PostProcessing/BloomEffectOld.cs b/src/renderer/SM.Base/Legacy/PostProcessing/BloomEffectOld.cs
new file mode 100644
index 0000000..4a7366c
--- /dev/null
+++ b/src/renderer/SM.Base/Legacy/PostProcessing/BloomEffectOld.cs
@@ -0,0 +1,216 @@
+#region usings
+
+using System;
+using System.Drawing;
+using OpenTK;
+using OpenTK.Graphics.OpenGL4;
+using SM.Base.Drawing;
+using SM.Base.PostProcess;
+using SM.Base.Utility;
+using SM.Base.Window;
+using SM.OGL.Framebuffer;
+using SM.OGL.Shaders;
+using SM.OGL.Texture;
+
+#endregion
+
+namespace SM.Base.Legacy.PostProcessing
+{
+ ///
+ /// A bloom post process effect.
+ ///
+ [Obsolete("This bloom effect isn't good. Please use SM.Base.PostEffects.BloomEffect, if you want a good bloom effect.")]
+ public class BloomEffectOld : PostProcessEffect
+ {
+ private static BezierCurve _defaultCurve = new BezierCurve(Vector2.UnitY, Vector2.Zero, new Vector2(0.4f, 0), new Vector2(.5f,0));
+ private static readonly PostProcessShader _mergeShader = new PostProcessShader(
+ new ShaderFile(AssemblyUtility.ReadAssemblyFile("SM.Base.Legacy.PostProcessing.bloom_merge.vert")),
+ AssemblyUtility.ReadAssemblyFile("SM.Base.Legacy.PostProcessing.bloom_merge.glsl"));
+
+ private static readonly PostProcessShader _shader =
+ new PostProcessShader(AssemblyUtility.ReadAssemblyFile("SM.Base.Legacy.PostProcessing.bloom_blur.glsl"));
+ private const float _defaultTextureScale = .75f;
+
+ private Framebuffer _source;
+
+ private Framebuffer _tempColorBuffer;
+ private Framebuffer _bloomBuffer1;
+ private Framebuffer _bloomBuffer2;
+
+ private readonly bool _hdr;
+
+ private readonly float _textureScale = .75f;
+
+ private BezierCurve _weightCurve;
+ private float[] _weights;
+
+ private ColorAttachment _xBuffer;
+ private ColorAttachment _yBuffer;
+
+ ///
+ /// A texture where you can define the amount of the bloom effect at each pixel.
+ ///
+ public TextureBase AmountMap;
+ ///
+ /// The transformation for the amount map.
+ ///
+ public TextureTransformation AmountTransform = new TextureTransformation();
+ ///
+ /// The maximal amount the amount map is clamped to.
+ /// Default: 1
+ ///
+ public float MaxAmount = 1;
+ ///
+ /// The minimal amount the amount map is clamped to.
+ /// Default: 0
+ ///
+ public float MinAmount = 0;
+
+ ///
+ /// The defines how often the x-y-flipflop happens.
+ /// Default: 8
+ ///
+ public int Iterations = 8;
+ ///
+ /// The Threshold for the bloom effect.
+ /// Default: .8f
+ ///
+ public float Threshold = .8f;
+ ///
+ /// Increases the brightness of the resulting effect.
+ /// Default: 1
+ ///
+ public float Power = 1;
+
+ ///
+ /// Radius of the effect
+ /// Default: 2
+ ///
+ public float Radius = 1;
+
+ ///
+ /// This defines the weight curve.
+ ///
+ public BezierCurve WeightCurve
+ {
+ get => _weightCurve;
+ set
+ {
+ _weightCurve = value;
+ UpdateWeights();
+ }
+ }
+
+ ///
+ /// This defines how many picks the effect should pick from the weight curve.
+ ///
+ public int WeightCurvePickAmount = 4;
+
+ ///
+ /// This creates a bloom effect.
+ ///
+ /// This can specify a own source framebuffer. If not set, it will take the Pipeline MainFramebuffer.
+ /// This allows to enable hdr returns.
+ /// This allows for a increase in performance, by lowering the calculating texture scale.
+ public BloomEffectOld(Framebuffer source = null, bool hdr = false, float? textureScale = null)
+ {
+ _source = source;
+ _hdr = hdr;
+ _textureScale = textureScale.GetValueOrDefault(_defaultTextureScale);
+
+ WeightCurve = _defaultCurve;
+ }
+
+
+ private void UpdateWeights()
+ {
+ _weights = new float[WeightCurvePickAmount];
+
+ for (int i = 0; i < WeightCurvePickAmount; i++)
+ _weights[i] = _weightCurve.CalculatePoint((float) (i + 1) / (WeightCurvePickAmount + 1)).Y;
+ }
+
+ ///
+ protected override void InitProcess()
+ {
+ _source ??= Pipeline.MainFramebuffer;
+
+ _source.ColorAttachments["color"].PixelInformation = PixelInformation.RGBA_HDR;
+
+ _tempColorBuffer = new Framebuffer(Pipeline.ConnectedWindow, 1);
+ _tempColorBuffer.Append("color", new ColorAttachment(0, PixelInformation.RGBA_HDR));
+ _tempColorBuffer.Compile();
+
+ _bloomBuffer1 = new Framebuffer(Pipeline.ConnectedWindow, _textureScale)
+ {
+ Name = "BloomX"
+ };
+ _bloomBuffer1.Append("xBuffer", _xBuffer = new ColorAttachment(0, PixelInformation.RGBA_HDR));
+ _bloomBuffer1.Compile();
+ _bloomBuffer2 = new Framebuffer(Pipeline.ConnectedWindow, _textureScale)
+ {
+ Name = "BloomY"
+ };
+ _bloomBuffer2.Append("yBuffer", _yBuffer = new ColorAttachment(0, PixelInformation.RGBA_HDR));
+ _bloomBuffer2.Compile();
+
+ Pipeline.Framebuffers.Add(_tempColorBuffer);
+ Pipeline.Framebuffers.Add(_bloomBuffer1);
+ Pipeline.Framebuffers.Add(_bloomBuffer2);
+ }
+
+ ///
+ protected override void Drawing(ColorAttachment source, DrawContext context)
+ {
+ GL.Viewport(0, 0, (int) (Pipeline.ConnectedWindow.Width * _textureScale),
+ (int) (Pipeline.ConnectedWindow.Height * _textureScale));
+
+ Framebuffer target = Framebuffer.GetCurrentlyActive();
+
+ source.ConnectedFramebuffer.CopyTo(_tempColorBuffer);
+
+ bool first = true, hoz = true;
+ int iter = Iterations * 2;
+ for (int i = 0; i < iter; i++)
+ {
+ (hoz ? _bloomBuffer1 : _bloomBuffer2).Activate(false);
+
+ _shader.Draw(collection =>
+ {
+ collection["renderedTexture"].SetTexture(first ? source : (hoz ? _yBuffer : _xBuffer));
+
+ collection["First"].SetBool(first);
+ collection["Threshold"].SetFloat(Threshold);
+
+ collection["Horizontal"].SetBool(hoz);
+
+ collection["Weights"].SetFloat(_weights);
+ collection["WeightCount"].SetFloat(WeightCurvePickAmount);
+ collection["Power"].SetFloat(Power);
+
+ collection["Radius"].SetFloat(_textureScale * Radius);
+ });
+
+ hoz = !hoz;
+ if (first) first = false;
+ }
+
+ GL.Viewport(Pipeline.ConnectedWindow.ClientRectangle);
+ target.Activate();
+
+ _mergeShader.Draw(collection =>
+ {
+ collection["Scene"].SetTexture(_tempColorBuffer["color"]);
+ collection["Bloom"].SetTexture(_yBuffer);
+
+ collection["MinAmount"].SetFloat(MinAmount);
+ collection["MaxAmount"].SetFloat(MaxAmount);
+ collection["AmountMap"].SetTexture(AmountMap, collection["HasAmountMap"]);
+ collection["TextureTransform"].SetMatrix3(AmountTransform.GetMatrix());
+
+ collection["Exposure"].SetFloat(context.UseCamera.Exposure);
+ collection["HDR"].SetBool(_hdr);
+ });
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/renderer/SM.Base/PostEffects/Shaders/bloom_blur.glsl b/src/renderer/SM.Base/Legacy/PostProcessing/bloom_blur.glsl
similarity index 92%
rename from src/renderer/SM.Base/PostEffects/Shaders/bloom_blur.glsl
rename to src/renderer/SM.Base/Legacy/PostProcessing/bloom_blur.glsl
index 834ad23..c6bb97a 100644
--- a/src/renderer/SM.Base/PostEffects/Shaders/bloom_blur.glsl
+++ b/src/renderer/SM.Base/Legacy/PostProcessing/bloom_blur.glsl
@@ -1,5 +1,4 @@
#version 330
-#define PI 3.14159265359
uniform sampler2D renderedTexture;
uniform float RenderScale;
@@ -16,6 +15,7 @@ uniform float Power;
uniform float Radius;
layout(location = 0) out vec4 color;
+layout(location = 1) out vec4 scene;
vec4 GetRenderColorOffset(vec2 offset);
@@ -31,6 +31,8 @@ float GetWeight(int dif) {
}
void main() {
+ if (First) scene = GetRenderColorOffset(vec2(0));
+
vec3 thres = vec3(First ? Threshold : 0);
vec2 tex_offset = 1.0 / textureSize(renderedTexture, 0) * vec2(Horizontal ? 1 : 0, Horizontal ? 0 : 1);
diff --git a/src/renderer/SM.Base/PostEffects/Shaders/bloom_merge.glsl b/src/renderer/SM.Base/Legacy/PostProcessing/bloom_merge.glsl
similarity index 79%
rename from src/renderer/SM.Base/PostEffects/Shaders/bloom_merge.glsl
rename to src/renderer/SM.Base/Legacy/PostProcessing/bloom_merge.glsl
index cef9313..77a8937 100644
--- a/src/renderer/SM.Base/PostEffects/Shaders/bloom_merge.glsl
+++ b/src/renderer/SM.Base/Legacy/PostProcessing/bloom_merge.glsl
@@ -18,7 +18,7 @@ layout(location = 0) out vec4 color;
void main() {
vec3 result = texture(Bloom, vTexture).rgb;
- if (HasAmountMap) result *= clamp(length(texture(AmountMap, TransformedTexture).rgb) * (MaxAmount - MinAmount) + MinAmount, 0, 1);
+ //if (HasAmountMap) result *= clamp(length(texture(AmountMap, TransformedTexture).rgb) * (MaxAmount - MinAmount) + MinAmount, 0, 1);
if (!HDR) {
result = vec3(1.0) - exp(-result * Exposure);
}
diff --git a/src/renderer/SM.Base/Legacy/PostProcessing/bloom_merge.vert b/src/renderer/SM.Base/Legacy/PostProcessing/bloom_merge.vert
new file mode 100644
index 0000000..5875eb3
--- /dev/null
+++ b/src/renderer/SM.Base/Legacy/PostProcessing/bloom_merge.vert
@@ -0,0 +1,18 @@
+#version 330
+
+layout(location = 0) in vec3 aPos;
+layout(location = 1) in vec2 aTex;
+
+uniform mat4 MVP;
+uniform mat3 TextureTransform;
+
+out vec2 vTexture;
+out vec2 TransformedTexture;
+
+
+void main() {
+ vTexture = aTex;
+ //TransformedTexture = vec2(TextureTransform * vec3(aTex, 1));
+
+ gl_Position = MVP * vec4(aPos, 1);
+}
\ No newline at end of file
diff --git a/src/renderer/SM.Base/Log.cs b/src/renderer/SM.Base/Log.cs
index 8477937..176a85c 100644
--- a/src/renderer/SM.Base/Log.cs
+++ b/src/renderer/SM.Base/Log.cs
@@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
+using System.Reflection;
using System.Windows.Forms;
using OpenTK.Graphics.OpenGL4;
using SM.OGL;
@@ -82,14 +83,14 @@ namespace SM.Base
///
/// Presets for the log targets.
///
- public static Dictionary Preset = new()
+ public static Dictionary Preset = new Dictionary()
{
{LogTarget.Console, "[%type%] %msg%"},
{LogTarget.Debugger, "[%type%] %msg%"},
{LogTarget.File, "<%date%, %time%> [%type%] %msg%"}
};
- private static readonly Dictionary Colors = new()
+ private static readonly Dictionary Colors = new Dictionary()
{
{LogType.Info, ConsoleColor.Green},
{LogType.Warning, ConsoleColor.Yellow},
@@ -145,7 +146,10 @@ namespace SM.Base
{
if (_init) return;
- AppDomain.CurrentDomain.UnhandledException += ExceptionHandler;
+ if (!Debugger.IsAttached)
+ {
+ AppDomain.CurrentDomain.UnhandledException += ExceptionHandler;
+ }
AppDomain.CurrentDomain.DomainUnload += (sender, args) =>
{
_logStream.WriteLine("Unload application");
@@ -172,9 +176,12 @@ namespace SM.Base
Write(e.IsTerminating ? "Terminating Error" : LogType.Error.ToString(),
e.IsTerminating ? ConsoleColor.DarkRed : ConsoleColor.Red, e.ExceptionObject);
+ MethodBase info = (e.ExceptionObject as Exception).TargetSite;
+ string name = $"{info.ReflectedType.Namespace}.{info.ReflectedType.Name}.{info.Name}".Replace(".", "::");
+
if (e.IsTerminating)
{
- MessageBox.Show($"Critical error occured.\n\n{e.ExceptionObject}",
+ MessageBox.Show($"Critical error occured at {name}.\n\n{e.ExceptionObject}",
$"Terminating Error: {e.ExceptionObject.GetType().Name}");
_logStream?.Close();
}
diff --git a/src/renderer/SM.Base/PostEffects/BloomEffect.cs b/src/renderer/SM.Base/PostEffects/BloomEffect.cs
index fe8426b..8c5cac7 100644
--- a/src/renderer/SM.Base/PostEffects/BloomEffect.cs
+++ b/src/renderer/SM.Base/PostEffects/BloomEffect.cs
@@ -1,212 +1,200 @@
-#region usings
-
-using System.Drawing;
-using OpenTK;
+using OpenTK;
+using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL4;
-using SM.Base.Drawing;
using SM.Base.PostProcess;
using SM.Base.Utility;
using SM.Base.Window;
using SM.OGL.Framebuffer;
+using SM.OGL.Shaders;
using SM.OGL.Texture;
-
-#endregion
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
namespace SM.Base.PostEffects
{
///
- /// A bloom post process effect.
+ /// The recommended bloom effect, that looks way better than the old one.
+ /// Based on Blender's implermentation, which is based on COD: Infinite Warfare.
///
- public class BloomEffect : PostProcessEffect
+ public class BloomEffect : PostProcess.PostProcessEffect
{
- private static BezierCurve _defaultCurve = new BezierCurve(Vector2.UnitY, Vector2.Zero, new Vector2(0.4f, 0), new Vector2(.5f,0));
- private static readonly PostProcessShader _mergeShader = new PostProcessShader(
- AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom_merge_vert.glsl"),
- AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom_merge.glsl"));
+ private static readonly ShaderFile samplingFile = new ShaderFile(AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom.sampling.frag"));
- private static readonly PostProcessShader _shader =
- new PostProcessShader(AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom_blur.glsl"));
- private const float _defaultTextureScale = .75f;
+ private static readonly PostProcessShader _filterShader = new PostProcessShader(
+ AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom.filter.frag")
+ );
+ private static readonly PostProcessShader _downsampleShader = new PostProcessShader(
+ AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom.downsample.frag")
+ );
+ private static readonly PostProcessShader _upsampleShader = new PostProcessShader(
+ AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom.upsample.frag")
+ );
+ private static readonly PostProcessShader _combineShader = new PostProcessShader(
+ AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom.combine.frag")
+ );
- private Framebuffer _source;
+ static BloomEffect()
+ {
+ _upsampleShader.ShaderFiles.Fragment[0].GLSLExtensions.Add(samplingFile);
+ _combineShader.ShaderFiles.Fragment[0].GLSLExtensions.Add(samplingFile);
+ }
- private Framebuffer _bloomBuffer1;
- private Framebuffer _bloomBuffer2;
+ const int MAXBLOOMSTEPS = 8;
+ const float INTENSITY = .1f;
private readonly bool _hdr;
- private readonly float _textureScale = .75f;
+ private List _downsampler;
+ private List _upsample;
- private BezierCurve _weightCurve;
- private float[] _weights;
-
- private ColorAttachment _xBuffer;
- private ColorAttachment _yBuffer;
+ private int _iterations;
+ private float _sampleSize;
+ private Vector4 _thresholdCurve;
+ private Color4 _bloomColor;
///
- /// A texture where you can define the amount of the bloom effect at each pixel.
- ///
- public TextureBase AmountMap;
- ///
- /// The transformation for the amount map.
- ///
- public TextureTransformation AmountTransform = new TextureTransformation();
- ///
- /// The maximal amount the amount map is clamped to.
- /// Default: 1
- ///
- public float MaxAmount = 1;
- ///
- /// The minimal amount the amount map is clamped to.
- /// Default: 0
- ///
- public float MinAmount = 0;
-
- ///
- /// The defines how often the x-y-flipflop happens.
- /// Default: 8
- ///
- public int Iterations = 8;
- ///
- /// The Threshold for the bloom effect.
- /// Default: .8f
+ /// The threshold, where the effect decided what is bright.
///
public float Threshold = .8f;
///
- /// Increases the brightness of the resulting effect.
- /// Default: 1
+ /// The radius of the effect.
///
- public float Power = 1;
+ public float Radius = 6.5f;
+ ///
+ /// Makes transition between under/over-threshold gradual.
+ ///
+ public float Knee = .5f;
+ ///
+ /// The intensity of the effect.
+ ///
+ public float Intensity = .5f;
+ ///
+ /// The tint of the effect.
+ ///
+ public Color4 Color = Color4.White;
///
- /// Radius of the effect
- /// Default: 2
+ /// This creates a more prettier bloom effect.
///
- public float Radius = 1;
-
- ///
- /// This can disable the bloom calculation.
- /// Default: true
- ///
- public bool Enable = true;
-
- ///
- /// This defines the weight curve.
- ///
- public BezierCurve WeightCurve
- {
- get => _weightCurve;
- set
- {
- _weightCurve = value;
- UpdateWeights();
- }
- }
- ///
- /// This defines how many picks the effect should pick from the weight curve.
- ///
- public int WeightCurvePickAmount = 4;
-
- ///
- /// This creates a bloom effect.
- ///
- /// This can specify a own source framebuffer. If not set, it will take the Pipeline MainFramebuffer.
/// This allows to enable hdr returns.
- /// This allows for a increase in performance, by lowering the calculating texture scale.
- public BloomEffect(Framebuffer source = null, bool hdr = false, float? textureScale = null)
+ public BloomEffect(bool hdr = false)
{
- _source = source;
_hdr = hdr;
- _textureScale = textureScale.GetValueOrDefault(_defaultTextureScale);
-
- WeightCurve = _defaultCurve;
}
+ ///
+ protected override void InitProcess() => CreateFramebuffers();
-
- private void UpdateWeights()
+ private void CreateFramebuffers()
{
- _weights = new float[WeightCurvePickAmount];
+ if (_downsampler != null) _downsampler.ForEach(a => a.Reset());
+ if (_upsample != null) _upsample.ForEach(a => a.Reset());
- for (int i = 0; i < WeightCurvePickAmount; i++)
- _weights[i] = _weightCurve.CalculatePoint((float) (i + 1) / (WeightCurvePickAmount + 1)).Y;
+ _downsampler = new List();
+ _upsample = new List();
+
+ Vector2 windowSize = Pipeline.ConnectedWindow.WindowSize;
+
+ float minDim = (float)Math.Min(windowSize.X, windowSize.Y);
+ float maxIter = (Radius - 8.0f) + (float)(Math.Log(minDim) / Math.Log(2));
+ int maxIterInt = (int)maxIter;
+
+ _iterations = Math.Max(Math.Min(MAXBLOOMSTEPS, maxIterInt), 1);
+
+ _sampleSize = .5f + maxIter - maxIterInt;
+ _thresholdCurve = new Vector4(
+ Threshold - Knee,
+ Knee * 2,
+ 0.25f / Math.Max(1e-5f, Knee),
+ Threshold);
+
+ float intens = (Intensity * INTENSITY);
+ _bloomColor = new Color4(Color.R * intens, Color.G * intens, Color.B * intens, 1f);
+
+ PixelInformation pixel = new PixelInformation(PixelInternalFormat.R11fG11fB10f, PixelFormat.Rgb, PixelType.Float);
+
+ Vector2 texSize = windowSize;
+ Framebuffer f = new Framebuffer(texSize);
+ f.Append("0", new ColorAttachment(0, pixel));
+ f.Append("1", new ColorAttachment(1, pixel));
+ _downsampler.Add(f);
+ for (int i = 0; i < _iterations; i++)
+ {
+ texSize /= 2;
+
+
+
+ f = new Framebuffer(texSize);
+ f.Append("0", new ColorAttachment(0, pixel));
+ _downsampler.Add(f);
+
+ if (i == _iterations - 1) break;
+ f = new Framebuffer(texSize);
+ f.Append("0", new ColorAttachment(0, pixel));
+ _upsample.Add(f);
+ }
}
///
- protected override void InitProcess()
+ public override void ScreenSizeChanged(IGenericWindow window)
{
- _source ??= Pipeline.MainFramebuffer;
-
- _source.ColorAttachments["color"].PixelInformation = PixelInformation.RGBA_HDR;
-
- _bloomBuffer1 = new Framebuffer(Pipeline.ConnectedWindow, _textureScale)
- {
- Name = "BloomX"
- };
- _bloomBuffer1.Append("xBuffer", _xBuffer = new ColorAttachment(0, PixelInformation.RGBA_HDR));
- _bloomBuffer1.Compile();
- _bloomBuffer2 = new Framebuffer(Pipeline.ConnectedWindow, _textureScale)
- {
- Name = "BloomY"
- };
- _bloomBuffer2.Append("yBuffer", _yBuffer = new ColorAttachment(0, PixelInformation.RGBA_HDR));
- _bloomBuffer2.Compile();
-
- Pipeline.Framebuffers.Add(_bloomBuffer1);
- Pipeline.Framebuffers.Add(_bloomBuffer2);
+ CreateFramebuffers();
}
///
- public override void Draw(ColorAttachment source, DrawContext context)
+ protected override void Drawing(ColorAttachment source, DrawContext context)
{
- if (Enable)
- {
- GL.Viewport(0, 0, (int) (Pipeline.ConnectedWindow.Width * _textureScale),
- (int) (Pipeline.ConnectedWindow.Height * _textureScale));
+ Framebuffer target = Framebuffer.GetCurrentlyActive();
- Framebuffer target = Framebuffer.GetCurrentlyActive();
- bool first = true, hoz = true;
- int iter = Iterations * 2;
- for (int i = 0; i < iter; i++)
+ // Filtering
+ _downsampler[0].Activate(true);
+ _filterShader.Draw(source, col =>
+ {
+ col["ThresholdCurve"].SetVector4(_thresholdCurve);
+ });
+
+ // Downsampling
+ ColorAttachment last = _downsampler[0]["0"];
+ for(int i = 1; i < _iterations; i++)
+ {
+ ColorAttachment downsampleSource = last;
+ Framebuffer downsampleTarget = _downsampler[i];
+ downsampleTarget.Activate(true);
+ _downsampleShader.Draw(downsampleSource);
+
+ last = downsampleTarget["0"];
+ }
+
+ // Upsampling
+ for (int i = _iterations - 2; i >= 0; i--)
+ {
+ ColorAttachment downsampleSource = _downsampler[i]["0"];
+ Framebuffer upsampleTarget = _upsample[i];
+
+ upsampleTarget.Activate(true);
+
+ _upsampleShader.Draw(last, (a) =>
{
- (hoz ? _bloomBuffer1 : _bloomBuffer2).Activate(false);
+ if (last != null) a["baseBuffer"].SetTexture(downsampleSource);
+ a["sampleSize"].SetFloat(_sampleSize);
+ });
- _shader.Draw(collection =>
- {
- collection["renderedTexture"].SetTexture(first ? source : (hoz ? _yBuffer : _xBuffer));
-
- collection["First"].SetUniform1(first);
- collection["Threshold"].SetUniform1(Threshold);
-
- collection["Horizontal"].SetUniform1(hoz);
-
- collection["Weights"].SetUniform1(_weights);
- collection["WeightCount"].SetUniform1(WeightCurvePickAmount);
- collection["Power"].SetUniform1(Power);
-
- collection["Radius"].SetUniform1(_textureScale * Radius);
- });
-
- hoz = !hoz;
- if (first) first = false;
- }
-
- GL.Viewport(Pipeline.ConnectedWindow.ClientRectangle);
- target.Activate();
+ last = upsampleTarget["0"];
}
- _mergeShader.Draw(collection =>
+ // combine
+ target.Activate(true);
+ _combineShader.Draw(last, (a) =>
{
- collection["Scene"].SetTexture(source);
- collection["Bloom"].SetTexture(_yBuffer);
+ a["sampleSize"].SetFloat(_sampleSize);
- collection["MinAmount"].SetUniform1(MinAmount);
- collection["MaxAmount"].SetUniform1(MaxAmount);
- collection["AmountMap"].SetTexture(AmountMap, collection["HasAmountMap"]);
- collection["TextureTransform"].SetMatrix3(AmountTransform.GetMatrix());
+ a["scene"].SetTexture(_downsampler[0]["1"]);
+ a["bloomColor"].SetColor(_bloomColor);
- collection["Exposure"].SetUniform1(context.UseCamera.Exposure);
- collection["HDR"].SetUniform1(_hdr);
+ a["HDR"].SetBool(_hdr);
});
}
}
-}
\ No newline at end of file
+}
diff --git a/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs b/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs
index 55bef36..c925965 100644
--- a/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs
+++ b/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs
@@ -52,8 +52,8 @@ namespace SM.Base.PostEffects
{
_hdrExposureShader.Draw(u =>
{
- u["Gamma"].SetUniform1(Gamma);
- u["Exposure"].SetUniform1(exposure);
+ u["Gamma"].SetFloat(Gamma);
+ u["Exposure"].SetFloat(exposure);
u["Scene"].SetTexture(attachment);
});
}
@@ -66,7 +66,7 @@ namespace SM.Base.PostEffects
{
_gammaShader.Draw(u =>
{
- u["Gamma"].SetUniform1(Gamma);
+ u["Gamma"].SetFloat(Gamma);
u["Scene"].SetTexture(attachment);
});
}
diff --git a/src/renderer/SM.Base/PostEffects/Shaders/bloom/combine.frag b/src/renderer/SM.Base/PostEffects/Shaders/bloom/combine.frag
new file mode 100644
index 0000000..e72ba87
--- /dev/null
+++ b/src/renderer/SM.Base/PostEffects/Shaders/bloom/combine.frag
@@ -0,0 +1,32 @@
+#version 330 core
+
+in vec2 vTexture;
+
+uniform sampler2D scene;
+uniform vec4 bloomColor;
+uniform bool HDR;
+
+vec3 safe_color(vec3 c) {
+ return clamp(c, vec3(0.0), vec3(1e20));
+}
+
+vec3 upsample_filter_high();
+
+layout(location = 0) out vec4 color;
+
+vec3 reinhardTone(vec3 col) {
+ return col / (col + vec3(1.0));
+}
+
+void main() {
+
+ vec3 scene = safe_color(texture2D(scene, vTexture).rgb);
+ vec3 blur = upsample_filter_high() * bloomColor.rgb;
+
+ if (HDR) {
+ color = vec4(scene + blur, 1);
+ return;
+ }
+
+ color = vec4(scene + reinhardTone(blur), 1);
+}
diff --git a/src/renderer/SM.Base/PostEffects/Shaders/bloom/downsample.frag b/src/renderer/SM.Base/PostEffects/Shaders/bloom/downsample.frag
new file mode 100644
index 0000000..b2fec34
--- /dev/null
+++ b/src/renderer/SM.Base/PostEffects/Shaders/bloom/downsample.frag
@@ -0,0 +1,41 @@
+#version 330 core
+
+uniform vec2 renderedTextureTexelSize;
+
+vec4 GetRenderColor();
+vec4 GetRenderColorOffset(vec2);
+
+float getBrightness(vec3 col) {
+ return max(col.r, max(col.g, col.b));
+ return (col.r + col.r + col.b + col.g + col.g + col.g) / 6.0;
+}
+
+layout(location = 0) out vec4 color;
+
+vec3 downsample_high() {
+ vec4 d = renderedTextureTexelSize.xyxy * vec4(-1,-1, +1, +1);
+ vec3 s1 = GetRenderColorOffset(d.xy).rgb; // - -
+ // X -
+
+ vec3 s2 = GetRenderColorOffset(d.zy).rgb; // - -
+ // - X
+
+ vec3 s3 = GetRenderColorOffset(d.xw).rgb; // X -
+ // - -
+
+ vec3 s4 = GetRenderColorOffset(d.zw).rgb; // X -
+ // - -
+
+ float s1w = 1.0 / (getBrightness(s1) + 1.0);
+ float s2w = 1.0 / (getBrightness(s2) + 1.0);
+ float s3w = 1.0 / (getBrightness(s3) + 1.0);
+ float s4w = 1.0 / (getBrightness(s4) + 1.0);
+ float one_div = 1.0 / (s1w + s2w + s3w + s4w);
+
+ return (s1 * s1w + s2 * s2w + s3 * s3w + s4 * s4w) * one_div;
+}
+
+void main() {
+
+ color = vec4(downsample_high(),1);
+}
diff --git a/src/renderer/SM.Base/PostEffects/Shaders/bloom/filter.frag b/src/renderer/SM.Base/PostEffects/Shaders/bloom/filter.frag
new file mode 100644
index 0000000..c14ccf8
--- /dev/null
+++ b/src/renderer/SM.Base/PostEffects/Shaders/bloom/filter.frag
@@ -0,0 +1,48 @@
+#version 330 core
+
+uniform vec4 ThresholdCurve;
+uniform vec2 renderedTextureTexelSize;
+
+vec4 GetRenderColorOffset(vec2);
+
+layout(location = 0) out vec4 color;
+layout(location = 1) out vec4 scene;
+
+vec3 safe_color(vec3 c) {
+ return clamp(c, vec3(0.0), vec3(1e20));
+}
+vec3 median(vec3 a, vec3 b, vec3 c)
+{
+ return a + b + c - min(min(a, b), c) - max(max(a, b), c);
+}
+
+float getBrightness(vec3 col) {
+
+ return max(col.r, max(col.g, col.b));
+ return (col.r + col.r + col.b + col.g + col.g + col.g) / 6.0;
+}
+
+void main() {
+ scene = vec4(safe_color(GetRenderColorOffset(vec2(0)).rgb), 1);
+
+ vec3 d = renderedTextureTexelSize.xyx * vec3(1,1,0);
+ vec3 s0 = scene.rgb + vec3(.1);
+ vec3 s1 = safe_color(GetRenderColorOffset(-d.xz).rgb) + vec3(.1);
+ vec3 s2 = safe_color(GetRenderColorOffset(+d.xz).rgb) + vec3(.1);
+ vec3 s3 = safe_color(GetRenderColorOffset(-d.zy).rgb) + vec3(.1);
+ vec3 s4 = safe_color(GetRenderColorOffset(+d.zy).rgb) + vec3(.1);
+ vec3 col = median(median(s0, s1, s2), s3, s4);
+ float br = getBrightness(col);
+
+ /*vec3 col = safe_color(GetRenderColor().rgb);
+ float br = getBrightness(col);*/
+
+
+ float rq = clamp(br - ThresholdCurve.x, 0, ThresholdCurve.y);
+ rq = ThresholdCurve.z * rq * rq;
+
+ float resultBr = max(rq, br - ThresholdCurve.w) / max(1e-5, br);
+ col *= resultBr;
+
+ color = vec4(col, 1);
+}
diff --git a/src/renderer/SM.Base/PostEffects/Shaders/bloom/sampling.frag b/src/renderer/SM.Base/PostEffects/Shaders/bloom/sampling.frag
new file mode 100644
index 0000000..46054ee
--- /dev/null
+++ b/src/renderer/SM.Base/PostEffects/Shaders/bloom/sampling.frag
@@ -0,0 +1,30 @@
+#version 330 core
+
+
+uniform vec2 renderedTextureTexelSize;
+uniform float sampleSize;
+
+vec4 GetRenderColorOffset(vec2);
+
+
+vec3 upsample_filter_high() {
+ vec4 d = renderedTextureTexelSize.xyxy * vec4(1, 1,-1,0);
+
+ vec3 s;
+ // Line + 1
+ s = GetRenderColorOffset(d.zy).rgb; // x - -
+ s += GetRenderColorOffset(d.wy).rgb * 2; // - X -
+ s += GetRenderColorOffset(d.xy).rgb; // - - X
+
+ // Line 0
+ s += GetRenderColorOffset(d.zw).rgb * 2; // X - -
+ s += GetRenderColorOffset(vec2(0)).rgb * 4; // - X -
+ s += GetRenderColorOffset(d.xw).rgb * 2; // - - X
+
+ // Line - 1
+ s += GetRenderColorOffset(d.zz).rgb; // X - -
+ s += GetRenderColorOffset(d.wz).rgb * 2; // - X -
+ s += GetRenderColorOffset(d.xz).rgb; // - - X
+
+ return s * 0.0625; // 1 / 16 = 0.0625
+}
\ No newline at end of file
diff --git a/src/renderer/SM.Base/PostEffects/Shaders/bloom/upsample.frag b/src/renderer/SM.Base/PostEffects/Shaders/bloom/upsample.frag
new file mode 100644
index 0000000..38c530f
--- /dev/null
+++ b/src/renderer/SM.Base/PostEffects/Shaders/bloom/upsample.frag
@@ -0,0 +1,13 @@
+#version 330 core
+
+in vec2 vTexture;
+
+uniform sampler2D baseBuffer;
+
+layout(location = 0) out vec4 color;
+
+vec3 upsample_filter_high();
+
+void main() {
+ color = vec4(texture2D(baseBuffer, vTexture).rgb + upsample_filter_high(),1);
+}
diff --git a/src/renderer/SM.Base/PostEffects/Shaders/bloom_merge_vert.glsl b/src/renderer/SM.Base/PostEffects/Shaders/bloom_merge_vert.glsl
deleted file mode 100644
index 127a8b5..0000000
--- a/src/renderer/SM.Base/PostEffects/Shaders/bloom_merge_vert.glsl
+++ /dev/null
@@ -1,11 +0,0 @@
-#version 330
-
-layout(location = 1) in vec2 aTex;
-
-uniform mat3 TextureTransform;
-
-out vec2 TransformedTexture;
-
-void vertex() {
- TransformedTexture = vec2(TextureTransform * vec3(aTex, 1));
-}
\ No newline at end of file
diff --git a/src/renderer/SM.Base/PostEffects/Shaders/finalize_hdr.glsl b/src/renderer/SM.Base/PostEffects/Shaders/finalize_hdr.glsl
index 59406bc..696e186 100644
--- a/src/renderer/SM.Base/PostEffects/Shaders/finalize_hdr.glsl
+++ b/src/renderer/SM.Base/PostEffects/Shaders/finalize_hdr.glsl
@@ -8,8 +8,28 @@ uniform float Gamma;
layout(location = 0) out vec4 color;
+vec3 ACES(vec3 x) {
+ const float a = 2.51;
+ const float b = 0.03;
+ const float c = 2.43;
+ const float d = 0.59;
+ const float e = 0.14;
+
+ return clamp((x * (a * x + b)) / (x * (c * x + d) + e), 0,1.0);
+}
+
+vec3 reinhardTone(vec3 col) {
+ return col / (col + vec3(1.0));
+}
+
+vec3 exposure(vec3 scene) {
+ return vec3(1) - exp(-texture(Scene, vTexture).rgb * Exposure);
+}
+
void main() {
- vec3 result = vec3(1) - exp(-texture(Scene, vTexture).rgb * Exposure);
+
+ vec3 scene = texture2D(Scene, vTexture).rgb;
+ vec3 result = reinhardTone(scene);
color = vec4(pow(result, vec3(1 / Gamma)), 1);
}
\ No newline at end of file
diff --git a/src/renderer/SM.Base/PostProcess/PostProcessEffect.cs b/src/renderer/SM.Base/PostProcess/PostProcessEffect.cs
index 3767ace..d60d22b 100644
--- a/src/renderer/SM.Base/PostProcess/PostProcessEffect.cs
+++ b/src/renderer/SM.Base/PostProcess/PostProcessEffect.cs
@@ -24,6 +24,12 @@ namespace SM.Base.PostProcess
///
protected RenderPipeline Pipeline;
+ ///
+ /// Enables the effect.
+ /// Default: true
+ ///
+ public bool Enable = true;
+
///
/// Initialize the effect.
///
@@ -41,11 +47,20 @@ namespace SM.Base.PostProcess
{
}
+ ///
+ /// This executes
+ ///
+ ///
+ ///
+ public void Draw(ColorAttachment source, DrawContext context)
+ {
+ if (Enable) Drawing(source, context);
+ }
///
/// Method to draw the actual effect.
///
- public abstract void Draw(ColorAttachment source, DrawContext context);
+ protected abstract void Drawing(ColorAttachment source, DrawContext context);
///
/// Event, when the scene changed.
@@ -53,5 +68,14 @@ namespace SM.Base.PostProcess
public virtual void SceneChanged(GenericScene scene)
{
}
+
+ ///
+ /// Event, when the screen size changed.
+ ///
+ /// Window that changed
+ public virtual void ScreenSizeChanged(IGenericWindow window)
+ {
+
+ }
}
}
\ No newline at end of file
diff --git a/src/renderer/SM.Base/PostProcess/PostProcessShader.cs b/src/renderer/SM.Base/PostProcess/PostProcessShader.cs
index c364588..e2477b8 100644
--- a/src/renderer/SM.Base/PostProcess/PostProcessShader.cs
+++ b/src/renderer/SM.Base/PostProcess/PostProcessShader.cs
@@ -5,6 +5,7 @@ using System.Collections.Generic;
using OpenTK.Graphics.OpenGL4;
using SM.Base.Objects.Static;
using SM.Base.Utility;
+using SM.OGL.Framebuffer;
using SM.OGL.Shaders;
#endregion
@@ -25,6 +26,20 @@ namespace SM.Base.PostProcess
private static readonly string _normalVertexWithExt =
AssemblyUtility.ReadAssemblyFile("SM.Base.PostProcess.DefaultFiles.vertexWithExt.vert");
+ ///
+ /// Generates an action for the texture handling.
+ ///
+ ///
+ ///
+ public static Action DefaultTextureAction(ColorAttachment renderedTexture)
+ {
+ return (col) =>
+ {
+ col["renderedTexture"].SetTexture(renderedTexture);
+ col["renderedTextureTexelSize"].SetVector2(renderedTexture.TexelSize);
+ };
+ }
+
///
/// Creates the shader with the default vertex shader and custom fragment.
///
@@ -44,6 +59,14 @@ namespace SM.Base.PostProcess
}, new ShaderFile(fragment))
{
}
+ ///
+ /// Creates the shader with an vertex extension and custom fragment.
+ ///
+ ///
+ ///
+ public PostProcessShader(ShaderFile vertex, string fragment) : this(vertex, new ShaderFile(fragment))
+ {
+ }
private PostProcessShader(ShaderFile vertex, ShaderFile fragment) : base(
new ShaderFileCollection(vertex, fragment))
@@ -51,10 +74,33 @@ namespace SM.Base.PostProcess
fragment.GLSLExtensions.Add(_fragExtensions);
}
+ ///
+ /// Draws the shader with the color attachment as texture.
+ ///
+ ///
+ public void Draw(ColorAttachment renderedTexture)
+ {
+ Draw(DefaultTextureAction(renderedTexture));
+ }
+
+ ///
+ /// Draws the shader with the color attachment as texture and provides access to the uniforms.
+ ///
+ ///
+ ///
+ public void Draw(ColorAttachment renderedTexture, Action setUniformAction)
+ {
+ var texAction = DefaultTextureAction(renderedTexture);
+ Draw((a) => {
+ texAction(a);
+ setUniformAction(a);
+ });
+ }
+
///
/// Draws the shader with special uniforms.
///
- ///
+ ///
public void Draw(Action setUniformAction)
{
Activate();
diff --git a/src/renderer/SM.Base/SM.Base.csproj b/src/renderer/SM.Base/SM.Base.csproj
index f0ea177..dd59076 100644
--- a/src/renderer/SM.Base/SM.Base.csproj
+++ b/src/renderer/SM.Base/SM.Base.csproj
@@ -13,11 +13,12 @@
Properties
SM.Base
SM.Base
- v4.5.2
+ v4.7.1
512
true
+
true
@@ -51,6 +52,7 @@
+
@@ -61,6 +63,7 @@
+
@@ -71,7 +74,7 @@
-
+
@@ -115,13 +118,12 @@
-
-
+
+
-
@@ -139,7 +141,6 @@
..\..\..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll
- True
..\..\..\packages\SharpFont.4.0.1\lib\net45\SharpFont.dll
@@ -159,8 +160,14 @@
+
+
+
+
+
+
diff --git a/src/renderer/SM.Base/Shaders/SimpleShader.cs b/src/renderer/SM.Base/Shaders/SimpleShader.cs
index e068e12..5db13b4 100644
--- a/src/renderer/SM.Base/Shaders/SimpleShader.cs
+++ b/src/renderer/SM.Base/Shaders/SimpleShader.cs
@@ -101,17 +101,19 @@ namespace SM.Base.Shaders
.SetMatrix4(context.Instances[0].ModelMatrix * context.ModelMatrix * context.View * context.World);
uniforms["MasterTextureMatrix"].SetMatrix3(context.Instances[0].TextureMatrix * context.TextureMatrix);
uniforms["HasVColor"]
- .SetUniform1(context.Mesh.Attributes.Has("color"));
+ .SetBool(context.Mesh.Attributes.Has("color"));
DrawObject(context.ForcedType.GetValueOrDefault(context.Mesh.PrimitiveType), context.Mesh);
}
private static void InstancedSetUniforms(UniformCollection uniforms, DrawContext context)
{
+ if (context.Instances == null || context.Instances.Count < 1) return;
+
uniforms["MVP"].SetMatrix4(context.ModelMatrix * context.View * context.World);
uniforms["MasterTextureMatrix"].SetMatrix3(context.TextureMatrix);
uniforms["HasVColor"]
- .SetUniform1(context.Mesh.Attributes.Has("color"));
+ .SetBool(context.Mesh.Attributes.Has("color"));
UniformArray instances = uniforms.GetArray("Instances");
diff --git a/src/renderer/SM.Base/Shaders/SimpleShaderPresets/basic_vertex.glsl b/src/renderer/SM.Base/Shaders/SimpleShaderPresets/basic_vertex.glsl
index 503fb5a..5dd3936 100644
--- a/src/renderer/SM.Base/Shaders/SimpleShaderPresets/basic_vertex.glsl
+++ b/src/renderer/SM.Base/Shaders/SimpleShaderPresets/basic_vertex.glsl
@@ -1,5 +1,4 @@
#version 330
-#define SM_SIMPLE_EXTENSION //!extension
layout(location = 0) in vec3 a_Position;
layout(location = 1) in vec2 a_Texture;
@@ -13,10 +12,6 @@ out vec3 v_VertexPosition;
out vec2 v_TexCoords;
out vec4 v_Color;
-#if (SM_SIMPLE_EXTENSION == 1)
-void v_Extension();
-#endif
-
void main() {
v_Color = vec4(1);
if (HasVColor) v_Color = a_Color;
@@ -26,7 +21,5 @@ void main() {
v_VertexPosition = a_Position;
gl_Position = MVP * vec4(a_Position, 1);
- #if (SM_SIMPLE_EXTENSION == 1)
- v_Extension();
- #endif
+
}
\ No newline at end of file
diff --git a/src/renderer/SM.Base/Shaders/SimpleShaderPresets/instanced_vertex.glsl b/src/renderer/SM.Base/Shaders/SimpleShaderPresets/instanced_vertex.glsl
index 3565cf6..1f594ae 100644
--- a/src/renderer/SM.Base/Shaders/SimpleShaderPresets/instanced_vertex.glsl
+++ b/src/renderer/SM.Base/Shaders/SimpleShaderPresets/instanced_vertex.glsl
@@ -1,6 +1,5 @@
#version 330
#define maxInstances //!instanceMax
-#define SM_SIMPLE_EXTENSION //!extension
struct Instance {
mat4 ModelMatrix;
@@ -20,10 +19,6 @@ out vec3 v_VertexPosition;
out vec2 v_TexCoords;
out vec4 v_Color;
-#if (SM_SIMPLE_EXTENSION == 1)
-void v_Extension();
-#endif
-
void main() {
v_Color = vec4(1);
if (HasVColor) v_Color = a_Color;
@@ -33,7 +28,4 @@ void main() {
v_VertexPosition = a_Position;
gl_Position = MVP * Instances[gl_InstanceID].ModelMatrix * vec4(a_Position, 1);
- #if (SM_SIMPLE_EXTENSION == 1)
- v_Extension();
- #endif
}
\ No newline at end of file
diff --git a/src/renderer/SM.Base/Types/CVector1.cs b/src/renderer/SM.Base/Types/CVector1.cs
index b2a80f9..891e8ea 100644
--- a/src/renderer/SM.Base/Types/CVector1.cs
+++ b/src/renderer/SM.Base/Types/CVector1.cs
@@ -28,21 +28,6 @@ namespace SM.Base.Types
///
public float X { get; set; }
- ///
- /// Interpolates the motion to the target.
- ///
- /// How long the interpolation should take.
- /// The value it should interpolate.
- /// The curve how he interpolates. Preset values can be found under . Default:
- /// A handle to control the interpolation process.
- public InterpolationProcess Interpolate(TimeSpan duration, float to, BezierCurve? interpolationCurve = null)
- {
- InterpolationProcess process = new InterpolationProcess(this, duration, ConvertToVector4(), new Vector4(to, 0, 0, 0), interpolationCurve.GetValueOrDefault(AnimationCurves.Linear));
- process.Start();
-
- return process;
- }
-
///
/// Sets the X-Component.
///
diff --git a/src/renderer/SM.Base/Types/CVector2.cs b/src/renderer/SM.Base/Types/CVector2.cs
index 8063c6b..5f89219 100644
--- a/src/renderer/SM.Base/Types/CVector2.cs
+++ b/src/renderer/SM.Base/Types/CVector2.cs
@@ -34,26 +34,7 @@ namespace SM.Base.Types
/// Y-component
///
public float Y { get; set; }
-
- ///
- /// Interpolates the motion to the target.
- ///
- /// How long the interpolation should take.
- /// The value it should interpolate.
- /// The curve how he interpolates.
- /// When creating a curve, its recommended the Y-component is always between 0 -> 1. But it could make cool effects if not...
- /// Preset curves can be found under .
- /// Default:
- ///
- /// A handle to control the interpolation process.
- public InterpolationProcess Interpolate(TimeSpan duration, Vector2 to, BezierCurve? interpolationCurve = null)
- {
- InterpolationProcess process = new InterpolationProcess(this, duration, ConvertToVector4(), new Vector4(to), interpolationCurve.GetValueOrDefault(AnimationCurves.Linear));
- process.Start();
-
- return process;
- }
-
+
///
public override string ToString()
{
diff --git a/src/renderer/SM.Base/Types/CVector3.cs b/src/renderer/SM.Base/Types/CVector3.cs
index 64231f0..e5dfd92 100644
--- a/src/renderer/SM.Base/Types/CVector3.cs
+++ b/src/renderer/SM.Base/Types/CVector3.cs
@@ -34,22 +34,7 @@ namespace SM.Base.Types
/// Z-component
///
public float Z { get; set; }
-
- ///
- /// Interpolates the motion to the target.
- ///
- /// How long the interpolation should take.
- /// The value it should interpolate.
- /// The curve how he interpolates. Preset values can be found under . Default:
- /// A handle to control the interpolation process.
- public InterpolationProcess Interpolate(TimeSpan duration, Vector3 to, BezierCurve? interpolationCurve = null)
- {
- InterpolationProcess process = new InterpolationProcess(this, duration, ConvertToVector4(), new Vector4(to, 0), interpolationCurve.GetValueOrDefault(AnimationCurves.Linear));
- process.Start();
-
- return process;
- }
-
+
///
public override string ToString()
diff --git a/src/renderer/SM.Base/Types/CVector4.cs b/src/renderer/SM.Base/Types/CVector4.cs
index 5429a41..90addab 100644
--- a/src/renderer/SM.Base/Types/CVector4.cs
+++ b/src/renderer/SM.Base/Types/CVector4.cs
@@ -23,22 +23,7 @@ namespace SM.Base.Types
{
W = w;
}
-
- ///
- /// Interpolates the motion to the target.
- ///
- /// How long the interpolation should take.
- /// The value it should interpolate.
- /// The curve how he interpolates. Preset values can be found under . Default:
- /// A handle to control the interpolation process.
- public InterpolationProcess Interpolate(TimeSpan duration, Vector4 to, BezierCurve? interpolationCurve = null)
- {
- InterpolationProcess process = new InterpolationProcess(this, duration, ConvertToVector4(), to, interpolationCurve.GetValueOrDefault(AnimationCurves.Linear));
- process.Start();
-
- return process;
- }
-
+
///
public override void Set(float uniform, bool triggerChanged = true)
{
diff --git a/src/renderer/SM.Base/Types/CVectorBase.cs b/src/renderer/SM.Base/Types/CVectorBase.cs
index 2340b84..39d5831 100644
--- a/src/renderer/SM.Base/Types/CVectorBase.cs
+++ b/src/renderer/SM.Base/Types/CVectorBase.cs
@@ -1,5 +1,8 @@
using System;
using OpenTK;
+using OpenTK.Audio.OpenAL;
+using OpenTK.Graphics.OpenGL;
+using SM.Base.Animation;
namespace SM.Base.Types
{
@@ -48,6 +51,62 @@ namespace SM.Base.Types
NormalizationProcess(length);
}
+ ///
+ /// Interpolates the motion to the target.
+ ///
+ /// How long the interpolation should take.
+ /// The value it should interpolate.
+ /// The curve how he interpolates. Preset values can be found under . Default:
+ /// Auto-starts the interpolation process.
+ /// A handle to control the interpolation process.
+ public InterpolationProcess Interpolate(TimeSpan duration, TInterpolateType to, BezierCurve? interpolationCurve = null, bool autoStart = true)
+ where TInterpolateType : struct
+ {
+ return Interpolate(duration, ConvertToVector4(), to, interpolationCurve, autoStart);
+ }
+
+ ///
+ /// Interpolates the motion to the target.
+ ///
+ /// How long the interpolation should take.
+ /// The value it should start with.
+ /// The value it should interpolate.
+ /// The curve how he interpolates. Preset values can be found under . Default:
+ /// Auto-starts the interpolation process.
+ /// A handle to control the interpolation process.
+ public InterpolationProcess Interpolate(TimeSpan duration, TInterpolateType from, TInterpolateType to, BezierCurve? interpolationCurve = null, bool autoStart = true)
+ where TInterpolateType : struct
+ {
+ Vector4 start = from switch
+ {
+ float f => new Vector4(f, 0, 0, 0),
+ Vector2 v2 => new Vector4(v2.X, v2.Y, 0, 0),
+ Vector3 v3 => new Vector4(v3.X, v3.Y, v3.Z, 0),
+ Vector4 v4 => v4,
+ _ => throw new Exception("[INTERPOLATION] Only float, OpenTK.Vector2, OpenTK.Vector3, OpenTK.Vector4 are allowed as types.")
+ };
+
+ return Interpolate(duration, start, to, interpolationCurve, autoStart);
+ }
+
+ internal InterpolationProcess Interpolate(TimeSpan duration, Vector4 from, TInterpolateType to, BezierCurve? interpolationCurve = null, bool autoStart = true)
+ where TInterpolateType : struct
+ {
+ Vector4 target = to switch
+ {
+ float f => new Vector4(f, 0, 0, 0),
+ Vector2 v2 => new Vector4(v2.X, v2.Y, 0, 0),
+ Vector3 v3 => new Vector4(v3.X, v3.Y, v3.Z, 0),
+ Vector4 v4 => v4,
+ _ => throw new Exception("[INTERPOLATION] Only float, OpenTK.Vector2, OpenTK.Vector3, OpenTK.Vector4 are allowed as types.")
+ };
+
+ InterpolationProcess process = new InterpolationProcess(this, duration, from, target, interpolationCurve.GetValueOrDefault(AnimationCurves.Linear));
+ if (autoStart) process.Start();
+
+ return process;
+ }
+
///
/// Sets the values of the vector, by providing the values over an array.
///
diff --git a/src/renderer/SM.Base/Utility/MathUtils.cs b/src/renderer/SM.Base/Utility/MathUtils.cs
new file mode 100644
index 0000000..0e92156
--- /dev/null
+++ b/src/renderer/SM.Base/Utility/MathUtils.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SM.Base.Utility
+{
+ class MathUtils
+ {
+ public static float Lerp(float start, float end, float t)
+ {
+ return start + t * (end - start);
+ }
+ }
+}
diff --git a/src/renderer/SM.Base/Window/RenderPipeline.cs b/src/renderer/SM.Base/Window/RenderPipeline.cs
index b9f89dd..906a288 100644
--- a/src/renderer/SM.Base/Window/RenderPipeline.cs
+++ b/src/renderer/SM.Base/Window/RenderPipeline.cs
@@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Threading;
using SM.Base.Drawing;
+using SM.Base.PostProcess;
using SM.Base.Shaders;
using SM.Base.Utility;
using SM.OGL.Framebuffer;
@@ -17,6 +18,11 @@ namespace SM.Base.Window
///
public abstract class RenderPipeline : IInitializable
{
+ ///
+ /// All post processing effects should go here, that should be automaticly managed.
+ ///
+ protected List PostProcessEffects = new List();
+
///
/// This contains the windows its connected to.
///
@@ -47,9 +53,7 @@ namespace SM.Base.Window
///
public virtual void Activate()
- {
- }
-
+ { }
///
public virtual void Initialization()
{
@@ -73,11 +77,26 @@ namespace SM.Base.Window
///
/// The event when resizing.
///
- public virtual void Resize()
+ public virtual void Resize(IGenericWindow window)
{
Recompile();
+
+ foreach (PostProcessEffect effect in PostProcessEffects)
+ {
+ effect.ScreenSizeChanged(window);
+ }
}
+ ///
+ /// Initilizes the collected post processing effects.
+ ///
+ protected void InitizePostProcessing()
+ {
+ foreach (PostProcessEffect effect in PostProcessEffects)
+ {
+ effect.Initilize(this);
+ }
+ }
///
/// Compiles the framebuffers.
@@ -116,11 +135,11 @@ namespace SM.Base.Window
public Framebuffer CreateWindowFramebuffer(int multisamples = 0, PixelInformation? pixelInformation = null, bool depth = true)
{
Framebuffer framebuffer = new(ConnectedWindow);
- framebuffer.Append("color", new ColorAttachment(0, pixelInformation.GetValueOrDefault(PixelInformation.RGBA_LDR), multisamples));
+ framebuffer.Append("color", new ColorAttachment(0, pixelInformation.GetValueOrDefault(PixelInformation.RGBA_LDR), multisamples:multisamples));
if (depth)
{
- RenderbufferAttachment depthAttach = RenderbufferAttachment.Depth;
+ RenderbufferAttachment depthAttach = RenderbufferAttachment.GenerateDepth();
depthAttach.Multisample = multisamples;
framebuffer.AppendRenderbuffer(depthAttach);
}
diff --git a/src/renderer/SM.Base/Window/WindowCode.cs b/src/renderer/SM.Base/Window/WindowCode.cs
index 6270a52..8cdd501 100644
--- a/src/renderer/SM.Base/Window/WindowCode.cs
+++ b/src/renderer/SM.Base/Window/WindowCode.cs
@@ -60,14 +60,17 @@ namespace SM.Base.Window
{
window.WindowSize = new Vector2(window.Width, window.Height);
window.AspectRatio = (float) window.Width / window.Height;
- GL.Viewport(window.ClientRectangle);
- window.CurrentRenderPipeline?.Resize();
+ if (window.WindowSize.LengthSquared == 0) return;
+
+ GL.Viewport(window.ClientRectangle);
+
PostProcessEffect.Mvp = Matrix4.CreateScale(window.Width, -window.Height, 1) *
Matrix4.LookAt(Vector3.UnitZ, Vector3.Zero, Vector3.UnitY) *
Matrix4.CreateOrthographic(window.Width, window.Height, .1f, 100f);
+ window.CurrentRenderPipeline?.Resize(window);
window.AppliedSetup?.Resize(window);
}
diff --git a/src/renderer/SM.Base/packages.config b/src/renderer/SM.Base/packages.config
index e8dfb8b..85e4bbb 100644
--- a/src/renderer/SM.Base/packages.config
+++ b/src/renderer/SM.Base/packages.config
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/src/renderer/SM.OGL/Framebuffer/ColorAttachment.cs b/src/renderer/SM.OGL/Framebuffer/ColorAttachment.cs
index cf3678a..d95c6e1 100644
--- a/src/renderer/SM.OGL/Framebuffer/ColorAttachment.cs
+++ b/src/renderer/SM.OGL/Framebuffer/ColorAttachment.cs
@@ -1,6 +1,7 @@
#region usings
using System;
+using OpenTK;
using OpenTK.Graphics.OpenGL4;
using SM.OGL.Texture;
@@ -21,6 +22,14 @@ namespace SM.OGL.Framebuffer
///
public int AttachmentID { get; }
+ ///
+ /// Contains the framebuffer its connected.
+ /// Usually the last framebuffer, that called the Compile-method.
+ ///
+ public Framebuffer ConnectedFramebuffer { get; private set; }
+
+ public Vector2? AttachmentSize = null;
+
///
/// Returns the of this ColorAttachment.
///
@@ -47,7 +56,7 @@ namespace SM.OGL.Framebuffer
/// Creates a attachment with a specific id.
///
///
- public ColorAttachment(int attachmentId) : this(attachmentId, PixelInformation.RGBA_LDR)
+ public ColorAttachment(int attachmentId, Vector2? size = null) : this(attachmentId, PixelInformation.RGBA_LDR, size)
{ }
///
@@ -56,12 +65,16 @@ namespace SM.OGL.Framebuffer
///
///
///
- public ColorAttachment(int attachmentID, PixelInformation pixelInformation, int multisamples = 0)
+ public ColorAttachment(int attachmentID, PixelInformation pixelInformation, Vector2? size = null, int multisamples = 0)
{
AttachmentID = attachmentID;
PixelInformation = pixelInformation;
+ AttachmentSize = size;
+
_multisamples = multisamples;
Target = IsMultisampled ? TextureTarget.Texture2DMultisample : TextureTarget.Texture2D;
+
+ WrapMode = TextureWrapMode.ClampToEdge;
}
///
/// Generates the attachment.
@@ -70,6 +83,7 @@ namespace SM.OGL.Framebuffer
public void Generate(Framebuffer f)
{
_id = GL.GenTexture();
+ ConnectedFramebuffer = f;
if (IsMultisampled) GenerateMultisampledTexture(f);
else GenerateTexture(f);
@@ -77,29 +91,33 @@ namespace SM.OGL.Framebuffer
private void GenerateTexture(Framebuffer f)
{
- GL.BindTexture(TextureTarget.Texture2D, _id);
- GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInformation.InternalFormat,
- (int)f.Size.X, (int)f.Size.Y,
- 0, PixelInformation.Format, PixelInformation.DataType, IntPtr.Zero);
+ Vector2 size = AttachmentSize.GetValueOrDefault(f.Size);
- GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter,
- (int)TextureMinFilter.Linear);
- GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter,
-
- (int)TextureMinFilter.Linear);
- GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS,
- (int)TextureParameterName.ClampToEdge);
- GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT,
- (int)TextureParameterName.ClampToEdge);
-
- GL.BindTexture(TextureTarget.Texture2D, 0);
+ GenerateBaseTexture(size);
}
private void GenerateMultisampledTexture(Framebuffer f)
{
- GL.BindTexture(TextureTarget.Texture2DMultisample, _id);
- GL.TexImage2DMultisample(TextureTargetMultisample.Texture2DMultisample, _multisamples, PixelInformation.InternalFormat, (int)f.Size.X, (int)f.Size.Y, true);
- GL.BindTexture(TextureTarget.Texture2DMultisample, 0);
+ Vector2 size = AttachmentSize.GetValueOrDefault(f.Size);
+
+ Width = (int)size.X;
+ Height = (int)size.Y;
+
+ const TextureTarget target = TextureTarget.Texture2DMultisample;
+
+ GL.BindTexture(target, _id);
+ GL.TexImage2DMultisample((TextureTargetMultisample)target, _multisamples, PixelInformation.InternalFormat,
+ Width, Height, true);
+ /*
+ GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)Filter);
+ GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)Filter);
+
+ GL.TexParameter(target, TextureParameterName.TextureWrapS,
+ (int)WrapMode);
+ GL.TexParameter(target, TextureParameterName.TextureWrapT,
+ (int)WrapMode);*/
+
+ GL.BindTexture(target, 0);
}
}
}
\ No newline at end of file
diff --git a/src/renderer/SM.OGL/Framebuffer/Framebuffer.cs b/src/renderer/SM.OGL/Framebuffer/Framebuffer.cs
index 628e807..da98b79 100644
--- a/src/renderer/SM.OGL/Framebuffer/Framebuffer.cs
+++ b/src/renderer/SM.OGL/Framebuffer/Framebuffer.cs
@@ -15,6 +15,10 @@ namespace SM.OGL.Framebuffer
///
public class Framebuffer : GLObject
{
+ static Framebuffer CurrentlyActiveFramebuffer;
+ static Framebuffer CurrentlyActiveDrawFramebuffer;
+ static Framebuffer CurrentlyActiveReadFramebuffer;
+
///
protected override bool AutoCompile { get; set; } = true;
@@ -48,6 +52,8 @@ namespace SM.OGL.Framebuffer
public bool DefaultApplyViewport { get; set; } = true;
+ public ColorAttachment FirstColorAttachment { get; private set; }
+
///
/// Contains all color attachments.
///
@@ -56,7 +62,7 @@ namespace SM.OGL.Framebuffer
///
/// Contains the current renderbuffer attachments of the framebuffer.
///
- public Dictionary RenderbufferAttachments { get; } = new Dictionary();
+ public List RenderbufferAttachments { get; } = new List();
///
/// Gets the color attachment with the specified color name.
@@ -116,15 +122,19 @@ namespace SM.OGL.Framebuffer
foreach (var pair in ColorAttachments)
GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, pair.Value.FramebufferAttachment, pair.Value.Target, pair.Value.ID,
0);
+ FramebufferErrorCode err;
- foreach (RenderbufferAttachment attachment in RenderbufferAttachments.Keys.ToArray())
+ err = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer);
+ if (err != FramebufferErrorCode.FramebufferComplete)
+ throw new Exception("Failed loading framebuffer.\nProblem: " + err);
+
+ foreach (RenderbufferAttachment attachment in RenderbufferAttachments)
{
- int att = attachment.Generate(this);
- GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, attachment.FramebufferAttachment, RenderbufferTarget.Renderbuffer, att);
- RenderbufferAttachments[attachment] = att;
+ attachment.Generate(this);
+ GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, attachment.FramebufferAttachment, RenderbufferTarget.Renderbuffer, attachment.ID);
}
- var err = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer);
+ err = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer);
if (err != FramebufferErrorCode.FramebufferComplete)
throw new Exception("Failed loading framebuffer.\nProblem: " + err);
@@ -132,15 +142,25 @@ namespace SM.OGL.Framebuffer
GL.BindTexture(TextureTarget.Texture2D, 0);
}
+ ///
+ /// Disposes and clears the attachment
+ ///
+ public void Reset()
+ {
+ Dispose();
+ ColorAttachments.Clear();
+ RenderbufferAttachments.Clear();
+ }
+
///
public override void Dispose()
{
-
+
foreach (var attachment in ColorAttachments.Values) attachment.Dispose();
- foreach (KeyValuePair pair in RenderbufferAttachments.ToArray())
+ FirstColorAttachment = null;
+ foreach (RenderbufferAttachment pair in RenderbufferAttachments.ToArray())
{
- GL.DeleteRenderbuffer(pair.Value);
- RenderbufferAttachments[pair.Key] = -1;
+ GL.DeleteRenderbuffer(pair.ID);
}
GL.DeleteFramebuffer(this);
base.Dispose();
@@ -150,12 +170,14 @@ namespace SM.OGL.Framebuffer
///
/// Appends a color attachment.
///
- public void Append(string key, int pos) => Append(key, new ColorAttachment(pos));
+ public void Append(string key, int pos) => Append(key, new ColorAttachment(pos, null));
+ public void Append(string key, Vector2 size, int pos) => Append(key, new ColorAttachment(pos, size));
///
/// Appends a color attachment.
///
public void Append(string key, ColorAttachment value)
{
+ if (ColorAttachments.Count == 0) FirstColorAttachment = value;
ColorAttachments.Add(key, value);
}
@@ -165,7 +187,8 @@ namespace SM.OGL.Framebuffer
///
public void AppendRenderbuffer(RenderbufferAttachment attachment)
{
- RenderbufferAttachments.Add(attachment, -1);
+ if (RenderbufferAttachments.Contains(attachment)) return;
+ RenderbufferAttachments.Add(attachment);
}
///
@@ -201,17 +224,55 @@ namespace SM.OGL.Framebuffer
///
public void Activate(FramebufferTarget target, ClearBufferMask clear, bool? applyViewport = null)
{
+ switch (target)
+ {
+ case FramebufferTarget.ReadFramebuffer:
+ CurrentlyActiveReadFramebuffer = this;
+ break;
+ case FramebufferTarget.DrawFramebuffer:
+ CurrentlyActiveDrawFramebuffer = this;
+ break;
+ case FramebufferTarget.Framebuffer:
+ CurrentlyActiveFramebuffer = this;
+ break;
+ }
+
GL.BindFramebuffer(target, this);
- if (applyViewport.GetValueOrDefault(DefaultApplyViewport)) GL.Viewport(0, 0, (int)Size.X, (int)Size.Y);
+ if (applyViewport.GetValueOrDefault(DefaultApplyViewport))
+ GL.Viewport(0, 0, (int)Size.X, (int)Size.Y);
GL.Clear(clear);
}
+ ///
+ /// Copies content to the specified Framebuffer.
+ ///
+ public void CopyTo(Framebuffer target, ClearBufferMask clear = ClearBufferMask.ColorBufferBit, BlitFramebufferFilter filter = BlitFramebufferFilter.Linear)
+ {
+ Activate(FramebufferTarget.ReadFramebuffer, false);
+ target.Activate(FramebufferTarget.DrawFramebuffer, false);
+
+ GL.BlitFramebuffer(0, 0, (int)Size.X, (int)Size.Y, 0, 0, (int)Size.X, (int)Size.Y, clear, filter);
+ }
+
///
/// Returns a handle of the current framebuffer.
///
///
///
public static Framebuffer GetCurrentlyActive(FramebufferTarget target = FramebufferTarget.Framebuffer)
+ {
+ switch (target)
+ {
+ case FramebufferTarget.ReadFramebuffer:
+ return CurrentlyActiveReadFramebuffer ??= getCurrentlyActive(target);
+ case FramebufferTarget.DrawFramebuffer:
+ return CurrentlyActiveDrawFramebuffer ??= getCurrentlyActive(target);
+ case FramebufferTarget.Framebuffer:
+ return CurrentlyActiveFramebuffer ??= getCurrentlyActive(target);
+ }
+ return null;
+ }
+ static Framebuffer getCurrentlyActive(FramebufferTarget target = FramebufferTarget.Framebuffer)
{
Framebuffer buffer = new Framebuffer()
{
@@ -232,6 +293,8 @@ namespace SM.OGL.Framebuffer
break;
}
+
+
return buffer;
}
}
diff --git a/src/renderer/SM.OGL/Framebuffer/RenderbufferAttachment.cs b/src/renderer/SM.OGL/Framebuffer/RenderbufferAttachment.cs
index 3988bb4..aa35c13 100644
--- a/src/renderer/SM.OGL/Framebuffer/RenderbufferAttachment.cs
+++ b/src/renderer/SM.OGL/Framebuffer/RenderbufferAttachment.cs
@@ -5,12 +5,12 @@ namespace SM.OGL.Framebuffer
///
/// Describes a renderbuffer attachment.
///
- public struct RenderbufferAttachment
+ public class RenderbufferAttachment
{
///
/// Preset for the depthbuffer attachment.
///
- public static readonly RenderbufferAttachment Depth = new RenderbufferAttachment(RenderbufferStorage.Depth24Stencil8, FramebufferAttachment.DepthStencilAttachment);
+ public static RenderbufferAttachment GenerateDepth() => new RenderbufferAttachment(RenderbufferStorage.Depth24Stencil8, FramebufferAttachment.DepthStencilAttachment);
///
/// Storage describes the internal format for the renderbuffer.
@@ -26,6 +26,11 @@ namespace SM.OGL.Framebuffer
///
public int Multisample;
+ ///
+ /// The id that was given to the renderbuffer.
+ ///
+ public int ID;
+
///
/// Constructor
///
@@ -34,6 +39,8 @@ namespace SM.OGL.Framebuffer
Storage = storage;
FramebufferAttachment = framebufferAttachment;
Multisample = multisample;
+
+ ID = -1;
}
///
@@ -41,18 +48,38 @@ namespace SM.OGL.Framebuffer
///
/// The framebuffer
/// The ID of the renderbuffer.
- public int Generate(Framebuffer f)
+ public void Generate(Framebuffer f)
{
- int rb = GL.GenRenderbuffer();
+ ID = GL.GenRenderbuffer();
- GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, rb);
+ GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, ID);
if (Multisample != 0)
GL.RenderbufferStorageMultisample(RenderbufferTarget.Renderbuffer, Multisample, Storage, (int)f.Size.X, (int)f.Size.Y);
else
GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, Storage, (int)f.Size.X, (int)f.Size.Y);
GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, 0);
+ }
+ ///
+ /// Disposes the renderbuffer.
+ ///
+ public void Dispose()
+ {
- return rb;
+ GL.DeleteRenderbuffer(ID);
+ ID = -1;
+ }
+
+ ///
+ public override bool Equals(object obj)
+ {
+ if (obj is RenderbufferAttachment ra)
+ {
+ if (ra.FramebufferAttachment == FramebufferAttachment) return true;
+
+ return false;
+ }
+
+ return false;
}
}
}
\ No newline at end of file
diff --git a/src/renderer/SM.OGL/GLObject.cs b/src/renderer/SM.OGL/GLObject.cs
index 89b0fbe..a0538e6 100644
--- a/src/renderer/SM.OGL/GLObject.cs
+++ b/src/renderer/SM.OGL/GLObject.cs
@@ -136,7 +136,7 @@ namespace SM.OGL
///
public static void DisposeMarkedObjects()
{
- foreach (GLObject o in _disposableObjects)
+ foreach (GLObject o in _disposableObjects.ToArray())
{
o.Dispose();
}
diff --git a/src/renderer/SM.OGL/SM.OGL.csproj b/src/renderer/SM.OGL/SM.OGL.csproj
index fcd5e49..432a51b 100644
--- a/src/renderer/SM.OGL/SM.OGL.csproj
+++ b/src/renderer/SM.OGL/SM.OGL.csproj
@@ -9,9 +9,10 @@
Properties
SM.OGL
SM.OGL
- v4.5.2
+ v4.7.1
512
true
+
true
diff --git a/src/renderer/SM.OGL/Shaders/GenericShader.cs b/src/renderer/SM.OGL/Shaders/GenericShader.cs
index 27d74e7..fb1df8c 100644
--- a/src/renderer/SM.OGL/Shaders/GenericShader.cs
+++ b/src/renderer/SM.OGL/Shaders/GenericShader.cs
@@ -19,7 +19,7 @@ namespace SM.OGL.Shaders
///
/// Contains the different files for the shader.
///
- protected ShaderFileCollection ShaderFileFiles;
+ public ShaderFileCollection ShaderFiles;
///
/// Contains and manage the uniforms from the shader.
@@ -67,7 +67,7 @@ namespace SM.OGL.Shaders
Console.WriteLine();
- ShaderFileFiles = new ShaderFileCollection(vertex,fragment, geometry);
+ ShaderFiles = new ShaderFileCollection(vertex,fragment, geometry);
}
///
@@ -80,7 +80,7 @@ namespace SM.OGL.Shaders
///
protected GenericShader(ShaderFileCollection shaderFileFiles)
{
- ShaderFileFiles = shaderFileFiles;
+ ShaderFiles = shaderFileFiles;
}
///
@@ -92,7 +92,7 @@ namespace SM.OGL.Shaders
///
public void Update(ShaderFileCollection newShaderFiles)
{
- ShaderFileFiles = newShaderFiles;
+ ShaderFiles = newShaderFiles;
Recompile();
}
@@ -103,9 +103,9 @@ namespace SM.OGL.Shaders
{
_id = GL.CreateProgram();
- ShaderFileFiles.Append(this);
+ ShaderFiles.Append(this);
GL.LinkProgram(_id);
- ShaderFileFiles.Detach(this);
+ ShaderFiles.Detach(this);
Uniforms = new UniformCollection {ParentShader = this};
Uniforms.Import(this);
diff --git a/src/renderer/SM.OGL/Shaders/Uniform.cs b/src/renderer/SM.OGL/Shaders/Uniform.cs
index 6b498ac..5b5810e 100644
--- a/src/renderer/SM.OGL/Shaders/Uniform.cs
+++ b/src/renderer/SM.OGL/Shaders/Uniform.cs
@@ -24,6 +24,7 @@ namespace SM.OGL.Shaders
///
public UniformCollection Parent { get; }
+ #region Constructors
///
/// This creates a new uniform manager, that has a null parent.
///
@@ -63,289 +64,372 @@ namespace SM.OGL.Shaders
Parent = parent;
}
+ #endregion
+
#region Uniform1
- public void SetUniform1(bool value)
+ ///
+ /// Set a boolean as value.
+ ///
+ ///
+ public void SetBool(bool value)
{
GL.Uniform1(Location, value ? 1 : 0);
}
- public void SetUniform1(int value)
+ ///
+ /// Sets a integer.
+ ///
+ ///
+ public void SetInt(int value)
{
GL.Uniform1(Location, value);
}
- public void SetUniform1(params int[] values)
+ ///
+ /// Sets an array of integers.
+ ///
+ ///
+ public void SetInt(params int[] values)
{
GL.Uniform1(Location, values.Length, values);
}
- public void SetUniform1(int count, ref int values)
- {
- GL.Uniform1(Location, count, ref values);
- }
-
-
- public void SetUniform1(uint value)
+ ///
+ /// Set a unsigned integer.
+ ///
+ ///
+ public void SetUInt(uint value)
{
GL.Uniform1(Location, value);
}
- public void SetUniform1(params uint[] values)
+ ///
+ /// Set an array of unsigned integers.
+ ///
+ ///
+ public void SetUInt(params uint[] values)
{
GL.Uniform1(Location, values.Length, values);
}
- public void SetUniform1(int count, ref uint values)
- {
- GL.Uniform1(Location, count, ref values);
- }
-
-
- public void SetUniform1(float value)
+ ///
+ /// Sets a float.
+ ///
+ ///
+ public void SetFloat(float value)
{
GL.Uniform1(Location, value);
}
- public void SetUniform1(params float[] values)
+ ///
+ /// Sets an array of floats.
+ ///
+ ///
+ public void SetFloat(params float[] values)
{
GL.Uniform1(Location, values.Length, values);
}
- public void SetUniform1(int count, ref float value)
- {
- GL.Uniform1(Location, count, ref value);
- }
-
-
- public void SetUniform1(double value)
- {
- GL.Uniform1(Location, value);
- }
-
- public void SetUniform1(params double[] values)
- {
- GL.Uniform1(Location, values.Length, values);
- }
-
- public void SetUniform1(int count, ref double value)
- {
- GL.Uniform1(Location, count, ref value);
- }
-
#endregion
#region Uniform2
- public void SetUniform2(float x, float y)
+ ///
+ /// Sets a float vector2 by providing the values.
+ ///
+ ///
+ ///
+ public void SetVector2(float x, float y)
{
GL.Uniform2(Location, x, y);
}
- public void SetUniform2(double x, double y)
+ ///
+ /// Sets a unsigned integer vector2 by providing the values.
+ ///
+ ///
+ ///
+ public void SetVector2(uint x, uint y)
{
GL.Uniform2(Location, x, y);
}
- public void SetUniform2(uint x, uint y)
+ ///
+ /// Sets a integer vector2 by providing the values.
+ ///
+ ///
+ ///
+ public void SetVector2(int x, int y)
{
GL.Uniform2(Location, x, y);
}
- public void SetUniform2(int x, int y)
- {
- GL.Uniform2(Location, x, y);
- }
-
- public void SetUniform2(params float[] values)
- {
- GL.Uniform2(Location, values.Length / 2, values);
- }
-
- public void SetUniform2(params double[] values)
- {
- GL.Uniform2(Location, values.Length / 2, values);
- }
-
- public void SetUniform2(params int[] values)
- {
- GL.Uniform2(Location, values.Length / 2, values);
- }
-
- public void SetUniform2(params uint[] values)
- {
- GL.Uniform2(Location, values.Length / 2, values);
- }
-
- public void SetUniform2(int count, ref float values)
- {
- GL.Uniform2(Location, count, ref values);
- }
-
- public void SetUniform2(int count, ref double values)
- {
- GL.Uniform2(Location, count, ref values);
- }
-
- public void SetUniform2(int count, ref uint values)
- {
- GL.Uniform2(Location, count, ref values);
- }
-
- public void SetUniform2(Vector2 vector2)
+ ///
+ /// Sets a float vector2.
+ ///
+ ///
+ public void SetVector2(Vector2 vector2)
{
GL.Uniform2(Location, vector2);
}
- public void SetUniform2(ref Vector2 vector2)
+ ///
+ /// Sets a float vector2 by refencing.
+ ///
+ ///
+ public void SetVector2(ref Vector2 vector2)
{
GL.Uniform2(Location, ref vector2);
}
+ ///
+ /// Sets a array of vector2.
+ ///
+ ///
+ public void SetVector2(params Vector2[] values)
+ {
+ float[] newValues = new float[values.Length * 2];
+ for(int i = 0; i < values.Length; i++)
+ {
+ Vector2 val = values[i];
+ int newi = i * 2;
+ newValues[newi] = val.X;
+ newValues[newi + 1] = val.Y;
+ }
+ GL.Uniform2(Location, values.Length, newValues);
+ }
+
+ ///
+ /// Sets a float array that get converted to a vector2 array.
+ ///
+ ///
+ public void SetVector2(params float[] values)
+ {
+ GL.Uniform2(Location, values.Length / 2, values);
+ }
+
+ ///
+ /// Sets a integer array that get converted to a ivector2 array.
+ ///
+ ///
+ public void SetVector2(params int[] values)
+ {
+ GL.Uniform2(Location, values.Length / 2, values);
+ }
+
+ ///
+ /// Sets a unsigned integer array that get converted to a unsigned integer vector2 array.
+ ///
+ ///
+ public void SetVector2(params uint[] values)
+ {
+ GL.Uniform2(Location, values.Length / 2, values);
+ }
+
#endregion
#region Uniform3
- public void SetUniform3(float x, float y, float z)
+ ///
+ /// Sets a float vector3 by providing the values.
+ ///
+ ///
+ ///
+ ///
+ public void SetVector3(float x, float y, float z)
{
GL.Uniform3(Location, x, y, z);
}
- public void SetUniform3(double x, double y, double z)
+ ///
+ /// Sets a unsigned integer vector3 by providing the values.
+ ///
+ ///
+ ///
+ ///
+ public void SetVector3(uint x, uint y, uint z)
{
GL.Uniform3(Location, x, y, z);
}
- public void SetUniform3(uint x, uint y, uint z)
+ ///
+ /// Sets a integer vector3 by providing the values.
+ ///
+ ///
+ ///
+ ///
+ public void SetVector3(int x, int y, int z)
{
GL.Uniform3(Location, x, y, z);
}
- public void SetUniform3(int x, int y, int z)
- {
- GL.Uniform3(Location, x, y, z);
- }
-
- public void SetUniform3(params float[] values)
- {
- GL.Uniform3(Location, values.Length / 3, values);
- }
-
- public void SetUniform3(params double[] values)
- {
- GL.Uniform3(Location, values.Length / 3, values);
- }
-
- public void SetUniform3(params int[] values)
- {
- GL.Uniform3(Location, values.Length / 3, values);
- }
-
- public void SetUniform3(params uint[] values)
- {
- GL.Uniform3(Location, values.Length / 3, values);
- }
-
- public void SetUniform3(int count, ref float values)
- {
- GL.Uniform3(Location, count, ref values);
- }
-
- public void SetUniform3(int count, ref double values)
- {
- GL.Uniform3(Location, count, ref values);
- }
-
- public void SetUniform3(int count, ref uint values)
- {
- GL.Uniform3(Location, count, ref values);
- }
-
- public void SetUniform3(Vector3 vector)
+ ///
+ /// Sets a vector3.
+ ///
+ ///
+ public void SetVector3(Vector3 vector)
{
GL.Uniform3(Location, vector);
}
-
- public void SetUniform3(ref Vector3 vector)
+ ///
+ /// Sets a vector3 by reference.
+ ///
+ ///
+ public void SetVector3(ref Vector3 vector)
{
GL.Uniform3(Location, ref vector);
}
+ ///
+ /// Sets a array of vector3.
+ ///
+ ///
+ public void SetVector3(params Vector3[] values)
+ {
+ float[] newValues = new float[values.Length * 3];
+ for (int i = 0; i < values.Length; i++)
+ {
+ Vector3 val = values[i];
+ int newi = i * 3;
+ newValues[newi] = val.X;
+ newValues[newi + 1] = val.Y;
+ newValues[newi + 2] = val.Z;
+ }
+ GL.Uniform3(Location, values.Length, newValues);
+ }
+
+ ///
+ /// Sets a array by providing the components.
+ ///
+ ///
+ public void SetVector3(params float[] values)
+ {
+ GL.Uniform3(Location, values.Length / 3, values);
+ }
+ ///
+ /// Sets a array by providing the components.
+ ///
+ ///
+ public void SetVector3(params int[] values)
+ {
+ GL.Uniform3(Location, values.Length / 3, values);
+ }
+ ///
+ /// Sets a array by providing the components.
+ ///
+ ///
+ public void SetVector3(params uint[] values)
+ {
+ GL.Uniform3(Location, values.Length / 3, values);
+ }
+
+
#endregion
#region Uniform4
- public void SetUniform4(float x, float y, float z, float w)
+ ///
+ /// Sets a vector4 by providing the values.
+ ///
+ ///
+ ///
+ ///
+ ///
+ public void SetVector4(float x, float y, float z, float w)
+ {
+ GL.Uniform4(Location, x, y, z, w);
+ }
+ ///
+ /// Sets a vector4 by providing the values.
+ ///
+ ///
+ ///
+ ///
+ ///
+ public void SetVector4(uint x, uint y, uint z, uint w)
+ {
+ GL.Uniform4(Location, x, y, z, w);
+ }
+ ///
+ /// Sets a vector4 by providing the values.
+ ///
+ ///
+ ///
+ ///
+ ///
+ public void SetVector4(int x, int y, int z, int w)
{
GL.Uniform4(Location, x, y, z, w);
}
- public void SetUniform4(double x, double y, double z, double w)
- {
- GL.Uniform4(Location, x, y, z, w);
- }
-
- public void SetUniform4(uint x, uint y, uint z, uint w)
- {
- GL.Uniform4(Location, x, y, z, w);
- }
-
- public void SetUniform4(int x, int y, int z, int w)
- {
- GL.Uniform4(Location, x, y, z, w);
- }
-
- public void SetUniform4(params float[] values)
- {
- GL.Uniform4(Location, values.Length / 4, values);
- }
-
- public void SetUniform4(params double[] values)
- {
- GL.Uniform4(Location, values.Length / 4, values);
- }
-
- public void SetUniform4(params int[] values)
- {
- GL.Uniform4(Location, values.Length / 4, values);
- }
-
- public void SetUniform4(params uint[] values)
- {
- GL.Uniform4(Location, values.Length / 4, values);
- }
-
- public void SetUniform4(int count, ref float values)
- {
- GL.Uniform4(Location, count, ref values);
- }
-
- public void SetUniform4(int count, ref double values)
- {
- GL.Uniform4(Location, count, ref values);
- }
-
- public void SetUniform4(int count, ref uint values)
- {
- GL.Uniform4(Location, count, ref values);
- }
-
- public void SetUniform4(Vector4 vector)
+ ///
+ /// Sets a vector4.
+ ///
+ ///
+ public void SetVector4(Vector4 vector)
{
GL.Uniform4(Location, vector);
}
- public void SetUniform4(ref Vector4 vector)
+ ///
+ /// Sets a vector4.
+ ///
+ ///
+ public void SetVector4(ref Vector4 vector)
{
GL.Uniform4(Location, ref vector);
}
- public void SetUniform4(Color4 color)
+ ///
+ /// Sets a array of Vector4.
+ ///
+ ///
+ public void SetVector4(params Vector4[] values)
{
- GL.Uniform4(Location, color);
+ float[] newValues = new float[values.Length * 4];
+ for (int i = 0; i < values.Length; i++)
+ {
+ Vector4 val = values[i];
+ int newi = i * 3;
+ newValues[newi] = val.X;
+ newValues[newi + 1] = val.Y;
+ newValues[newi + 2] = val.Z;
+ newValues[newi + 3] = val.W;
+ }
+ GL.Uniform3(Location, values.Length, newValues);
}
- public void SetUniform4(Quaternion quaternion)
+ ///
+ /// Sets a array by providing the components.
+ ///
+ ///
+ public void SetVector4(params float[] values)
+ {
+ GL.Uniform4(Location, values.Length / 4, values);
+ }
+ ///
+ /// Sets a array by providing the components.
+ ///
+ ///
+ public void SetVector4(params int[] values)
+ {
+ GL.Uniform4(Location, values.Length / 4, values);
+ }
+ ///
+ /// Sets a array by providing the components.
+ ///
+ ///
+ public void SetVector4(params uint[] values)
+ {
+ GL.Uniform4(Location, values.Length / 4, values);
+ }
+
+ ///
+ /// Sets a quaternion.
+ ///
+ ///
+ public void SetQuaternion(Quaternion quaternion)
{
GL.Uniform4(Location, quaternion);
}
@@ -354,26 +438,22 @@ namespace SM.OGL.Shaders
#region Matrix2
+ ///
+ /// Sets a matrix2.
+ ///
+ ///
+ /// If true, the matrix will be transposed.
public void SetMatrix2(Matrix2 matrix, bool transpose = false)
{
GL.UniformMatrix2(Location, transpose, ref matrix);
}
- public void SetMatrix2(int count, ref double value, bool transpose = false)
- {
- GL.UniformMatrix2(Location, count, transpose, ref value);
- }
-
- public void SetMatrix2(int count, ref float value, bool transpose = false)
- {
- GL.UniformMatrix2(Location, count, transpose, ref value);
- }
-
- public void SetMatrix2(int count, double[] value, bool transpose = false)
- {
- GL.UniformMatrix2(Location, count, transpose, value);
- }
-
+ ///
+ /// Sets a matrix2 array.
+ ///
+ ///
+ ///
+ /// If true, the matrix will be transposed.
public void SetMatrix2(int count, float[] value, bool transpose = false)
{
GL.UniformMatrix2(Location, count, transpose, value);
@@ -382,27 +462,22 @@ namespace SM.OGL.Shaders
#endregion
#region Matrix3
-
+ ///
+ /// Sets a matrix3.
+ ///
+ ///
+ /// If true, the matrix will be transposed.
public void SetMatrix3(Matrix3 matrix, bool transpose = false)
{
GL.UniformMatrix3(Location, transpose, ref matrix);
}
- public void SetMatrix3(int count, ref double value, bool transpose = false)
- {
- GL.UniformMatrix3(Location, count, transpose, ref value);
- }
-
- public void SetMatrix3(int count, ref float value, bool transpose = false)
- {
- GL.UniformMatrix3(Location, count, transpose, ref value);
- }
-
- public void SetMatrix3(int count, double[] value, bool transpose = false)
- {
- GL.UniformMatrix3(Location, count, transpose, value);
- }
-
+ ///
+ /// Sets a matrix3 array.
+ ///
+ ///
+ ///
+ /// If true, the matrix will be transposed.
public void SetMatrix3(int count, float[] value, bool transpose = false)
{
GL.UniformMatrix3(Location, count, transpose, value);
@@ -412,31 +487,31 @@ namespace SM.OGL.Shaders
#region Matrix4
+ ///
+ /// Sets a matrix4.
+ ///
+ ///
+ /// If true, the matrix will be transposed.
public void SetMatrix4(Matrix4 matrix, bool transpose = false)
{
GL.UniformMatrix4(Location, transpose, ref matrix);
}
-
+ ///
+ /// Sets a matrix4 by reference.
+ ///
+ ///
+ /// If true, the matrix will be transposed.
public void SetMatrix4(ref Matrix4 matrix, bool transpose = false)
{
GL.UniformMatrix4(Location, transpose, ref matrix);
}
- public void SetMatrix4(int count, ref double value, bool transpose = false)
- {
- GL.UniformMatrix4(Location, count, transpose, ref value);
- }
-
- public void SetMatrix4(int count, ref float value, bool transpose = false)
- {
- GL.UniformMatrix4(Location, count, transpose, ref value);
- }
-
- public void SetMatrix4(int count, double[] value, bool transpose = false)
- {
- GL.UniformMatrix4(Location, count, transpose, value);
- }
-
+ ///
+ /// Sets a matrix4 array.
+ ///
+ ///
+ ///
+ /// If true, the matrix will be transposed.
public void SetMatrix4(int count, float[] value, bool transpose = false)
{
GL.UniformMatrix4(Location, count, transpose, value);
@@ -444,6 +519,15 @@ namespace SM.OGL.Shaders
#endregion
+ ///
+ /// Sets the color.
+ ///
+ ///
+ public void SetColor(Color4 color)
+ {
+ GL.Uniform4(Location, color);
+ }
+
///
/// Try to sets the texture at the next possible position and tells the checkUniform, if worked or not.
///
@@ -451,7 +535,7 @@ namespace SM.OGL.Shaders
/// The check uniform.
public void SetTexture(TextureBase texture, Uniform checkUniform)
{
- checkUniform.SetUniform1(texture != null);
+ checkUniform.SetBool(texture != null);
if (texture != null) SetTexture(texture);
}
@@ -463,7 +547,7 @@ namespace SM.OGL.Shaders
/// The check uniform.
public void SetTexture(TextureBase texture, int pos, Uniform checkUniform)
{
- checkUniform.SetUniform1(texture != null);
+ checkUniform.SetBool(texture != null);
if (texture != null) SetTexture(texture);
}
@@ -486,7 +570,7 @@ namespace SM.OGL.Shaders
Parent.NextTexture = texturePos + 1;
GL.ActiveTexture(TextureUnit.Texture0 + texturePos);
GL.BindTexture(texture.Target, texture);
- SetUniform1(texturePos);
+ SetInt(texturePos);
}
///
diff --git a/src/renderer/SM.OGL/Texture/TextureBase.cs b/src/renderer/SM.OGL/Texture/TextureBase.cs
index 495fe74..b496f6d 100644
--- a/src/renderer/SM.OGL/Texture/TextureBase.cs
+++ b/src/renderer/SM.OGL/Texture/TextureBase.cs
@@ -1,6 +1,8 @@
#region usings
+using OpenTK;
using OpenTK.Graphics.OpenGL4;
+using System;
#endregion
@@ -10,6 +12,7 @@ namespace SM.OGL.Texture
/// Works as a basis for textures.
///
public abstract class TextureBase : GLObject
+
{
///
protected override bool AutoCompile { get; set; } = true;
@@ -50,11 +53,35 @@ namespace SM.OGL.Texture
///
public virtual int Height { get; protected set; }
+ public Vector2 Size => new Vector2(Width, Height);
+ public Vector2 TexelSize => new Vector2(1f / Width, 1f / Height);
+
///
public override void Dispose()
{
GL.DeleteTexture(_id);
base.Dispose();
}
+
+ protected void GenerateBaseTexture(Vector2 size)
+ {
+ Width = (int)size.X;
+ Height = (int)size.Y;
+
+ GL.BindTexture(TextureTarget.Texture2D, _id);
+ GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInformation.InternalFormat,
+ Width, Height, 0,
+ PixelInformation.Format, PixelInformation.DataType, IntPtr.Zero);
+
+ GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)Filter);
+ GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)Filter);
+
+ GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS,
+ (int)WrapMode);
+ GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT,
+ (int)WrapMode);
+
+ GL.BindTexture(TextureTarget.Texture2D, 0);
+ }
}
}
\ No newline at end of file
diff --git a/src/renderer/SM.OGL/packages.config b/src/renderer/SM.OGL/packages.config
index 82cdaeb..1f65eab 100644
--- a/src/renderer/SM.OGL/packages.config
+++ b/src/renderer/SM.OGL/packages.config
@@ -1,4 +1,4 @@
-
+
\ No newline at end of file
diff --git a/src/renderer/SM2D/SM2D.csproj b/src/renderer/SM2D/SM2D.csproj
index 67ed6ca..384bc93 100644
--- a/src/renderer/SM2D/SM2D.csproj
+++ b/src/renderer/SM2D/SM2D.csproj
@@ -8,9 +8,10 @@
Properties
SM2D
SMRenderer2D
- v4.5.2
+ v4.7.1
512
true
+
true
@@ -30,9 +31,13 @@
prompt
4
+
+ false
+
..\..\..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll
+ True
diff --git a/src/renderer/SM2D/Shader/ShaderCollection.cs b/src/renderer/SM2D/Shader/ShaderCollection.cs
index e7dacf8..2886b20 100644
--- a/src/renderer/SM2D/Shader/ShaderCollection.cs
+++ b/src/renderer/SM2D/Shader/ShaderCollection.cs
@@ -18,7 +18,7 @@ namespace SM2D.Shader
static void SetUniforms(UniformCollection uniforms, DrawContext context)
{
- uniforms["Tint"].SetUniform4(context.Material.Tint);
+ uniforms["Tint"].SetColor(context.Material.Tint);
uniforms["Texture"].SetTexture(context.Material.Texture, uniforms["UseTexture"]);
}
}
diff --git a/src/renderer/SM2D/packages.config b/src/renderer/SM2D/packages.config
index 82cdaeb..1f65eab 100644
--- a/src/renderer/SM2D/packages.config
+++ b/src/renderer/SM2D/packages.config
@@ -1,4 +1,4 @@
-
+
\ No newline at end of file
diff --git a/tests/SM_TEST/App.config b/tests/SM_TEST/App.config
index 88fa402..ecdcf8a 100644
--- a/tests/SM_TEST/App.config
+++ b/tests/SM_TEST/App.config
@@ -1,6 +1,6 @@
-
+
-
+
-
\ No newline at end of file
+
diff --git a/tests/SM_TEST/Default Fragment Shader1.frag b/tests/SM_TEST/Default Fragment Shader1.frag
new file mode 100644
index 0000000..e97c5eb
--- /dev/null
+++ b/tests/SM_TEST/Default Fragment Shader1.frag
@@ -0,0 +1,10 @@
+#version 330 core
+
+uniform vec4 Color;
+uniform float Scale;
+
+layout(location = 0) out vec4 color;
+
+void main() {
+ color = Color * Scale;
+}
diff --git a/tests/SM_TEST/Program.cs b/tests/SM_TEST/Program.cs
index 70bd0b0..be64d6a 100644
--- a/tests/SM_TEST/Program.cs
+++ b/tests/SM_TEST/Program.cs
@@ -3,15 +3,20 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
+using System.Runtime.InteropServices.WindowsRuntime;
using OpenTK;
using OpenTK.Graphics;
using OpenTK.Graphics.OpenGL;
using ShaderToolParser;
+using SharpDX.XInput;
using SM.Base;
using SM.Base.Animation;
using SM.Base.Controls;
using SM.Base.Drawing;
+using SM.Base.Drawing.Text;
+using SM.Base.Shaders;
using SM.Base.Time;
+using SM.Base.Utility;
using SM.Base.Window;
using SM.Intergrations.ShaderTool;
using SM.Utils.Controls;
@@ -28,25 +33,25 @@ namespace SM_TEST
{
static Scene scene;
private static GLWindow window;
- private static PolyLine line;
+ private static GameController controller;
- private static ItemCollection test;
- private static DrawParticles particles;
-
- private static InterpolationProcess interpolation;
+ private static GameKeybindActor actor;
public static STPProject portal;
- static void Main(string[] args)
- {
+ static void Main(string[] args){
Font font = new Font(@".\GapSansBold.ttf")
{
FontSize = 51,
- CharSet = new char[]
- {
- 'I', 'A','M','T','W','O'
- }
};
- font.RegenerateTexture();
+
+ controller = new GameController(0);
+ GameKeybindHost host = new GameKeybindHost(new GameKeybindList()
+ {
+ {"g_test", context => Keyboard.IsAnyKeyPressed, context => context.ControllerState.Buttons[GamepadButtonFlags.A, true]}
+ });
+ actor = GameKeybindActor.CreateControllerActor(controller);
+ actor.ConnectHost(host);
+
portal = STPProject.CreateFromZIP("portal.zip");
@@ -58,18 +63,45 @@ namespace SM_TEST
{
ShowAxisHelper = true
});
- scene.Background.Color = Color4.Red;
+ //scene.Background.Color = Color4.Red;
scene.Camera = new Camera()
{
};
- DrawText obj = new DrawText(font, "I AM\n\tTWO")
- {};
+ SimpleShader shader = new SimpleShader("basic", AssemblyUtility.ReadAssemblyFile("SM_TEST.Default Fragment Shader1.frag"), (a, b) => {
+ a["Color"].SetColor(b.Material.Tint);
+ a["Scale"].SetFloat(b.Material.ShaderArguments.Get("Scale", 1f));
+
+ });
+ DrawObject2D obj = new DrawObject2D()
+ {
+ Material =
+ {
+ CustomShader = shader,
+ Tint = new Color4(1f, 0.151217f, 0.050313f, 1),
+ ShaderArguments =
+ {
+ ["Scale"] = 50f
+ }
+ }
+ };/*
+ DrawObject2D obj2 = new DrawObject2D()
+ {
+ Material =
+ {
+ Tint = Color4.Aqua,
+ CustomShader = shader,
+ ShaderArguments =
+ {
+ ["Scale"] = 1000f
+ }
+ }
+ };
+ obj2.Transform.Position.Set(300);*/
scene.Objects.Add(obj);
- window.UpdateFrame += WindowOnUpdateFrame;
window.RenderFrame += Window_RenderFrame;
window.Run();
@@ -80,11 +112,5 @@ namespace SM_TEST
{
window.Title = Math.Floor(e.Time * 1000) + "ms";
}
-
- private static void WindowOnUpdateFrame(object sender, FrameEventArgs e)
- {
- bool interactions = new GameController(0).GetState().AnyInteraction;
- Console.WriteLine();
- }
}
}
\ No newline at end of file
diff --git a/tests/SM_TEST/SM_TEST.csproj b/tests/SM_TEST/SM_TEST.csproj
index a520d91..479cccf 100644
--- a/tests/SM_TEST/SM_TEST.csproj
+++ b/tests/SM_TEST/SM_TEST.csproj
@@ -10,12 +10,13 @@
WinExe
SM_TEST
SM_TEST
- v4.5.2
+ v4.7.2
512
true
true
+
AnyCPU
@@ -66,6 +67,7 @@
+
diff --git a/tests/SM_TEST/TestRenderPipeline.cs b/tests/SM_TEST/TestRenderPipeline.cs
index 5eecd9c..fea1bc0 100644
--- a/tests/SM_TEST/TestRenderPipeline.cs
+++ b/tests/SM_TEST/TestRenderPipeline.cs
@@ -1,4 +1,5 @@
using OpenTK.Graphics.OpenGL4;
+using SM.Base.Legacy.PostProcessing;
using SM.Base.PostEffects;
using SM.Base.Window;
using SM.Intergrations.ShaderTool;
@@ -9,6 +10,7 @@ namespace SM_TEST
{
public class TestRenderPipeline : RenderPipeline
{
+ private BloomEffectOld _bloomObsolete;
private BloomEffect _bloom;
private STPostProcessEffect _vittage;
@@ -17,16 +19,15 @@ namespace SM_TEST
public override void Initialization()
{
- MainFramebuffer = CreateWindowFramebuffer(16, PixelInformation.RGBA_HDR);
+ MainFramebuffer = CreateWindowFramebuffer(0, PixelInformation.RGBA_HDR, true);
- _postBuffer = CreateWindowFramebuffer(0, PixelInformation.RGBA_HDR, depth: true);
- Framebuffers.Add(_postBuffer);
- _bloom = new BloomEffect(_postBuffer, hdr: true, .75f)
+ _bloom = new BloomEffect(true)
{
+ Radius = 20,
};
- _bloom.Initilize(this);
+ PostProcessEffects.Add(_bloom);
- _vittage = new STPostProcessEffect(Program.portal.DrawNodes.Find(a => a.Variables.ContainsKey("_ViewportSize")))
+ /*_vittage = new STPostProcessEffect(Program.portal.DrawNodes.Find(a => a.Variables.ContainsKey("_ViewportSize")))
{
Arguments =
{
@@ -36,7 +37,8 @@ namespace SM_TEST
{"Move", 3.33f}
}
};
- _vittage.Initilize(this);
+ _vittage.Initilize(this);*/
+ InitizePostProcessing();
base.Initialization();
}
@@ -50,16 +52,17 @@ namespace SM_TEST
context.Scene.DrawHUD(context);
GL.Disable(EnableCap.DepthTest);
- _postBuffer.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
- PostProcessUtility.ResolveMultisampledBuffers(MainFramebuffer, _postBuffer);
+ //_postBuffer.Activate(ClearBufferMask.ColorBufferBit);
+ //PostProcessUtility.ResolveMultisampledBuffers(MainFramebuffer, _postBuffer);
- _vittage.Draw(_postBuffer["color"], context);
- _bloom.Draw(_postBuffer["color"], context);
+ //_vittage.Draw(MainFramebuffer["color"], context);
+ //_bloom.Draw(MainFramebuffer["color"], context);
+ _bloomObsolete.Draw(MainFramebuffer["color"], context);
Framebuffer.Screen.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
- PostProcessUtility.FinalizeHDR(_postBuffer["color"], .1f);
+ PostProcessUtility.FinalizeHDR(MainFramebuffer["color"], 1f);
- context.Scene.DrawDebug(context);
+ //context.Scene.DrawDebug(context);
}
}
}
\ No newline at end of file