diff --git a/README.md b/README.md new file mode 100644 index 0000000..1ada262 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# SMRendererV3 +A performant and simple to use OpenGL-renderer. +It allows you to extend/changing the renderer as you wish, without changing the source file. + +## Installation +The distribution happens over the NuGet.org. + +You should be able to find the SMRenderer**2D** over your Nuget Package Manager. diff --git a/SMCode/SM.Base/Drawing/Particles/ParticleContext.cs b/SMCode/SM.Base/Drawing/Particles/ParticleContext.cs deleted file mode 100644 index 67f6e47..0000000 --- a/SMCode/SM.Base/Drawing/Particles/ParticleContext.cs +++ /dev/null @@ -1,24 +0,0 @@ -#region usings - -using SM.Base.Time; - -#endregion - -namespace SM.Base.Drawing.Particles -{ - /// - /// A context, with that the particle system sends the information for the movement function. - /// - public struct ParticleContext - { - /// - /// The Timer of the particles - /// - public Timer Timer; - - /// - /// The current speed of the particles. - /// - public float Speed; - } -} \ No newline at end of file diff --git a/SMCode/SM.Base/Drawing/Particles/ParticleDrawingBasis.cs b/SMCode/SM.Base/Drawing/Particles/ParticleDrawingBasis.cs deleted file mode 100644 index 24643db..0000000 --- a/SMCode/SM.Base/Drawing/Particles/ParticleDrawingBasis.cs +++ /dev/null @@ -1,139 +0,0 @@ -#region usings - -using System; -using System.Collections.Generic; -using OpenTK; -using SM.Base.Scene; -using SM.Base.Time; -using SM.Base.Window; - -#endregion - -namespace SM.Base.Drawing.Particles -{ - /// - /// The (drawing) basis for particles - /// - public abstract class ParticleDrawingBasis : DrawingBasis, IScriptable - where TTransform : GenericTransformation, new() - where TDirection : struct - { - - /// - /// The amount of particles - /// - public int Amount = 32; - - /// - /// This contains the different instances for the particles. - /// - protected List instances; - - /// - /// The maximum speed of the particles - /// - public float MaxSpeed = 50; - - /// - /// This contains all important information for each particle. - /// - protected ParticleStruct[] particleStructs; - - /// - /// The stopwatch of the particles. - /// - protected Timer timer; - - /// - /// Sets up the timer. - /// - /// Duration how long the particles should live - protected ParticleDrawingBasis(TimeSpan duration) - { - timer = new Timer(duration); - } - - /// - /// Get/Sets the state of pausing. - /// - public bool Paused - { - get => timer.Paused; - set => timer.Paused = value; - } - - /// - /// Controls the movement of each particles. - /// - public abstract Func MovementCalculation { get; set; } - - /// - public bool UpdateActive { - get => timer.Active; - set { return; } - } - - /// - public void Update(UpdateContext context) - { - ParticleContext particleContext = new ParticleContext - { - Timer = timer - }; - - for (int i = 0; i < Amount; i++) - { - particleContext.Speed = particleStructs[i].Speed; - instances[i].ModelMatrix = CreateMatrix(particleStructs[i], - MovementCalculation(particleStructs[i].Direction, particleContext)); - } - } - - /// - /// Triggers the particles. - /// - public void Trigger() - { - timer.Start(); - - CreateParticles(); - } - - /// - protected override void DrawContext(ref DrawContext context) - { - if (!timer.Active) return; - - base.DrawContext(ref context); - - context.Instances = instances; - - context.Shader.Draw(context); - } - - /// - /// Creates the particles. - /// - protected virtual void CreateParticles() - { - particleStructs = new ParticleStruct[Amount]; - instances = new List(); - for (int i = 0; i < Amount; i++) - { - particleStructs[i] = CreateObject(i); - - instances.Add(new Instance()); - } - } - - /// - /// Creates a particle. - /// - protected abstract ParticleStruct CreateObject(int index); - - /// - /// Generates the desired matrix for drawing. - /// - protected abstract Matrix4 CreateMatrix(ParticleStruct Struct, TDirection relativePosition); - } -} \ No newline at end of file diff --git a/SMCode/SM.Base/Drawing/Particles/ParticleStruct.cs b/SMCode/SM.Base/Drawing/Particles/ParticleStruct.cs deleted file mode 100644 index eef2b53..0000000 --- a/SMCode/SM.Base/Drawing/Particles/ParticleStruct.cs +++ /dev/null @@ -1,30 +0,0 @@ -#region usings - -using OpenTK; - -#endregion - -namespace SM.Base.Drawing.Particles -{ - /// - /// A particle... - /// - public struct ParticleStruct - where TDirection : struct - { - /// - /// A direction, that the particle should travel. - /// - public TDirection Direction; - - /// - /// A matrix to store rotation and scale. - /// - public Matrix4 Matrix; - - /// - /// Speeeeeeeeeed - /// - public float Speed; - } -} \ No newline at end of file diff --git a/SMCode/SM.Base/Legacy/Font.cs b/SMCode/SM.Base/Legacy/Font.cs deleted file mode 100644 index 1cebcb6..0000000 --- a/SMCode/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/SMCode/SM.Base/PostEffects/Shaders/finalize_hdr.glsl b/SMCode/SM.Base/PostEffects/Shaders/finalize_hdr.glsl deleted file mode 100644 index 59406bc..0000000 --- a/SMCode/SM.Base/PostEffects/Shaders/finalize_hdr.glsl +++ /dev/null @@ -1,15 +0,0 @@ -#version 330 - -in vec2 vTexture; - -uniform sampler2D Scene; -uniform float Exposure; -uniform float Gamma; - -layout(location = 0) out vec4 color; - -void main() { - vec3 result = vec3(1) - exp(-texture(Scene, vTexture).rgb * Exposure); - - color = vec4(pow(result, vec3(1 / Gamma)), 1); -} \ No newline at end of file diff --git a/SMCode/SM.Base/PostProcess/PostProcessShader.cs b/SMCode/SM.Base/PostProcess/PostProcessShader.cs deleted file mode 100644 index c364588..0000000 --- a/SMCode/SM.Base/PostProcess/PostProcessShader.cs +++ /dev/null @@ -1,72 +0,0 @@ -#region usings - -using System; -using System.Collections.Generic; -using OpenTK.Graphics.OpenGL4; -using SM.Base.Objects.Static; -using SM.Base.Utility; -using SM.OGL.Shaders; - -#endregion - -namespace SM.Base.PostProcess -{ - /// - /// Specific shader for post processing. - /// - public class PostProcessShader : GenericShader - { - private static readonly ShaderFile _fragExtensions = - new ShaderFile(AssemblyUtility.ReadAssemblyFile("SM.Base.PostProcess.DefaultFiles.extensions.frag")); - - private static readonly ShaderFile _normalVertex = - new ShaderFile(AssemblyUtility.ReadAssemblyFile("SM.Base.PostProcess.DefaultFiles.vertexFile.vert")); - - private static readonly string _normalVertexWithExt = - AssemblyUtility.ReadAssemblyFile("SM.Base.PostProcess.DefaultFiles.vertexWithExt.vert"); - - /// - /// Creates the shader with the default vertex shader and custom fragment. - /// - public PostProcessShader(string fragment) : this(_normalVertex, - new ShaderFile(fragment)) - { - } - - /// - /// Creates the shader with an vertex extension and custom fragment. - /// - /// - /// - public PostProcessShader(string vertexExt, string fragment) : this(new ShaderFile(_normalVertexWithExt) - { - GLSLExtensions = new List {new ShaderFile(vertexExt)} - }, new ShaderFile(fragment)) - { - } - - private PostProcessShader(ShaderFile vertex, ShaderFile fragment) : base( - new ShaderFileCollection(vertex, fragment)) - { - fragment.GLSLExtensions.Add(_fragExtensions); - } - - /// - /// Draws the shader with special uniforms. - /// - /// - public void Draw(Action setUniformAction) - { - Activate(); - Plate.Object.Activate(); - - Uniforms["MVP"].SetMatrix4(PostProcessEffect.Mvp); - - setUniformAction(Uniforms); - - GL.DrawArrays(PrimitiveType.Quads, 0, 4); - - CleanUp(); - } - } -} \ No newline at end of file diff --git a/SMCode/SM.Base/Types/CVectorBase.cs b/SMCode/SM.Base/Types/CVectorBase.cs deleted file mode 100644 index 2340b84..0000000 --- a/SMCode/SM.Base/Types/CVectorBase.cs +++ /dev/null @@ -1,83 +0,0 @@ -using System; -using OpenTK; - -namespace SM.Base.Types -{ - /// - /// Basis for the CVector classes - /// - public abstract class CVectorBase - { - /// - /// This event triggers when a component changed. - /// - public event Action Changed; - - /// - /// The length/magnitute of the vector. - /// - public float Length => GetLength(); - - /// - /// Gets the square of the vector length (magnitude). - /// - /// - /// This property avoids the costly square root operation required by the Length property. This makes it more suitable - /// for comparisons. - /// - public float LengthSquared => GetLength(true); - - /// - /// Get the length of the vector. - /// - /// If true, it will return the squared product. - /// - public float GetLength(bool squared = false) - { - float length = GetLengthProcess(); - if (squared) return length; - return (float)Math.Sqrt(length); - } - - /// - /// Normalizes the vector. - /// - public void Normalize() - { - float length = GetLength(); - NormalizationProcess(length); - } - - /// - /// Sets the values of the vector, by providing the values over an array. - /// - /// - public abstract void SetRaw(params float[] parameters); - - /// - /// This triggers the event. - /// - protected void TriggerChanged() - { - Changed?.Invoke(); - } - - /// - /// Conversion from to One-dimensional Vector. - /// - /// - protected abstract float GetLengthProcess(); - - /// - /// Normalizes the vector. - /// - /// - protected abstract void NormalizationProcess(float length); - - /// - /// Converts the vector to a - /// - /// - protected abstract Vector4 ConvertToVector4(); - } -} \ No newline at end of file diff --git a/SMCode/SM.OGL/Shaders/Uniform.cs b/SMCode/SM.OGL/Shaders/Uniform.cs deleted file mode 100644 index 6b498ac..0000000 --- a/SMCode/SM.OGL/Shaders/Uniform.cs +++ /dev/null @@ -1,501 +0,0 @@ -#region usings - -using OpenTK; -using OpenTK.Graphics; -using OpenTK.Graphics.OpenGL4; -using SM.OGL.Texture; - -#endregion - -namespace SM.OGL.Shaders -{ - /// - /// Manages the uniforms. - /// - public struct Uniform : IUniform - { - /// - /// This contains the location for the uniform. - /// - public int Location { get; internal set; } - - /// - /// This contains the Parent collection of this uniform. - /// - public UniformCollection Parent { get; } - - /// - /// This creates a new uniform manager, that has a null parent. - /// - /// - public Uniform(int location) : this(location, null) - { - } - - /// - /// This creates a new uniform manager, that get the location from the provided shader and with a null parent. - /// - /// - /// - public Uniform(string name, GenericShader shader) : this(GL.GetUniformLocation(shader, name), null) - { - - } - /// - /// This creates a new uniform manager, that get the location from the provided shader and with a parent. - /// - /// - /// - /// - public Uniform(string name, GenericShader shader, UniformCollection parent) : this(GL.GetUniformLocation(shader, name), parent) - { - - } - - /// - /// This create a new uniform manager - /// - /// Location id - /// Parent collection - public Uniform(int location, UniformCollection parent) - { - Location = location; - Parent = parent; - } - - #region Uniform1 - - public void SetUniform1(bool value) - { - GL.Uniform1(Location, value ? 1 : 0); - } - - public void SetUniform1(int value) - { - GL.Uniform1(Location, value); - } - - public void SetUniform1(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) - { - GL.Uniform1(Location, value); - } - - public void SetUniform1(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) - { - GL.Uniform1(Location, value); - } - - public void SetUniform1(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) - { - GL.Uniform2(Location, x, y); - } - - public void SetUniform2(double x, double y) - { - GL.Uniform2(Location, x, y); - } - - public void SetUniform2(uint x, uint 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) - { - GL.Uniform2(Location, vector2); - } - - public void SetUniform2(ref Vector2 vector2) - { - GL.Uniform2(Location, ref vector2); - } - - #endregion - - #region Uniform3 - - public void SetUniform3(float x, float y, float z) - { - GL.Uniform3(Location, x, y, z); - } - - public void SetUniform3(double x, double y, double z) - { - GL.Uniform3(Location, x, y, z); - } - - public void SetUniform3(uint x, uint y, uint 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) - { - GL.Uniform3(Location, vector); - } - - public void SetUniform3(ref Vector3 vector) - { - GL.Uniform3(Location, ref vector); - } - - #endregion - - #region Uniform4 - - public void SetUniform4(float x, float y, float z, float 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) - { - GL.Uniform4(Location, vector); - } - - public void SetUniform4(ref Vector4 vector) - { - GL.Uniform4(Location, ref vector); - } - - public void SetUniform4(Color4 color) - { - GL.Uniform4(Location, color); - } - - public void SetUniform4(Quaternion quaternion) - { - GL.Uniform4(Location, quaternion); - } - - #endregion - - #region Matrix2 - - 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); - } - - public void SetMatrix2(int count, float[] value, bool transpose = false) - { - GL.UniformMatrix2(Location, count, transpose, value); - } - - #endregion - - #region Matrix3 - - 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); - } - - public void SetMatrix3(int count, float[] value, bool transpose = false) - { - GL.UniformMatrix3(Location, count, transpose, value); - } - - #endregion - - #region Matrix4 - - public void SetMatrix4(Matrix4 matrix, bool transpose = false) - { - GL.UniformMatrix4(Location, transpose, ref matrix); - } - - 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); - } - - public void SetMatrix4(int count, float[] value, bool transpose = false) - { - GL.UniformMatrix4(Location, count, transpose, value); - } - - #endregion - - /// - /// Try to sets the texture at the next possible position and tells the checkUniform, if worked or not. - /// - /// The texture you want to add - /// The check uniform. - public void SetTexture(TextureBase texture, Uniform checkUniform) - { - checkUniform.SetUniform1(texture != null); - if (texture != null) SetTexture(texture); - } - - /// - /// Try to sets the texture at the specified position and tells the checkUniform, if worked or not. - /// - /// The texture you want to add - /// The position - /// The check uniform. - public void SetTexture(TextureBase texture, int pos, Uniform checkUniform) - { - checkUniform.SetUniform1(texture != null); - if (texture != null) SetTexture(texture); - } - - /// - /// Sets the texture to the next possible position. - /// - /// - public void SetTexture(TextureBase texture) - { - if (Parent != null) SetTexture(texture, Parent.NextTexture); - } - - /// - /// Sets the texture to the specified position. - /// - /// - /// - public void SetTexture(TextureBase texture, int texturePos) - { - Parent.NextTexture = texturePos + 1; - GL.ActiveTexture(TextureUnit.Texture0 + texturePos); - GL.BindTexture(texture.Target, texture); - SetUniform1(texturePos); - } - - /// - /// Returns the location from the uniform - /// - /// - public static implicit operator int(Uniform u) - { - return u.Location; - } - } -} \ No newline at end of file diff --git a/SMCode/SM3D/SM3D.csproj b/SMCode/SM3D/SM3D.csproj deleted file mode 100644 index 447701a..0000000 --- a/SMCode/SM3D/SM3D.csproj +++ /dev/null @@ -1,41 +0,0 @@ - - - - - Debug - AnyCPU - {9BECA849-E6E9-4E15-83A6-ADD8C18065CB} - Library - Properties - SM3D - SM3D - v4.5.2 - 512 - true - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - \ No newline at end of file diff --git a/SMOptionals/SM.Game/Controls/GameController.cs b/SMOptionals/SM.Game/Controls/GameController.cs deleted file mode 100644 index 65f41dd..0000000 --- a/SMOptionals/SM.Game/Controls/GameController.cs +++ /dev/null @@ -1,39 +0,0 @@ -using SharpDX.XInput; - -namespace SM.Game.Controls -{ - public struct GameController - { - public static float GlobalDeadband = 2500; - - private Controller _controller; - - public float Deadband { get; set; } - public bool IsConnected => _controller.IsConnected; - - public UserIndex Index { get; private set; } - - public GameController(int id) : this((UserIndex)id) - {} - - public GameController(UserIndex index = UserIndex.Any) - { - _controller = new Controller(index); - Index = index; - Deadband = GlobalDeadband; - } - - public GameControllerState GetState() - { - if (!IsConnected) - { - return new GameControllerState(true); - } - - Gamepad state = _controller.GetState().Gamepad; - - return new GameControllerState(state, ref this); - } - - } -} \ No newline at end of file diff --git a/SMOptionals/SM.Game/Controls/GameControllerStateThumbs.cs b/SMOptionals/SM.Game/Controls/GameControllerStateThumbs.cs deleted file mode 100644 index 1d4eefd..0000000 --- a/SMOptionals/SM.Game/Controls/GameControllerStateThumbs.cs +++ /dev/null @@ -1,21 +0,0 @@ -using OpenTK; - -namespace SM.Game.Controls -{ - public struct GameControllerStateThumbs - { - public static GameControllerStateThumbs Default = new GameControllerStateThumbs() - {Left = Vector2.Zero, Right = Vector2.Zero}; - - public Vector2 Left; - public Vector2 Right; - - public bool PressedLeft; - public bool PressedRight; - - public override string ToString() - { - return $"Left: ({Left.X}; {Left.Y}){(PressedLeft ? " Pressed" : "")}; Right: ({Right.X}; {Right.Y}){(PressedRight ? " Pressed" : "")}"; - } - } -} \ No newline at end of file diff --git a/SMRendererV3.sln b/SMRendererV3.sln index 93ce3e3..fecf2a6 100644 --- a/SMRendererV3.sln +++ b/SMRendererV3.sln @@ -3,23 +3,23 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.30413.136 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SMRenderer", "SMRenderer", "{47EA2879-1D40-4683-BA6C-AB51F286EBDE}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SM.OGL", "src\renderer\SM.OGL\SM.OGL.csproj", "{F604D684-BC1D-4819-88B5-8B5D03A17BE0}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SM.OGL", "SMCode\SM.OGL\SM.OGL.csproj", "{F604D684-BC1D-4819-88B5-8B5D03A17BE0}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SM.Base", "src\renderer\SM.Base\SM.Base.csproj", "{8E733844-4204-43E7-B3DC-3913CDDABB0D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SM.Base", "SMCode\SM.Base\SM.Base.csproj", "{8E733844-4204-43E7-B3DC-3913CDDABB0D}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SM2D", "src\renderer\SM2D\SM2D.csproj", "{A4565538-625A-42C6-A330-DD4F1ABB3986}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SM3D", "SMCode\SM3D\SM3D.csproj", "{9BECA849-E6E9-4E15-83A6-ADD8C18065CB}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SM_TEST", "tests\SM_TEST\SM_TEST.csproj", "{6D4FB8E6-4D0B-4928-8F9E-EF5C2FBF44E8}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SM2D", "SMCode\SM2D\SM2D.csproj", "{A4565538-625A-42C6-A330-DD4F1ABB3986}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SMRenderer.Utils", "src\optionals\SM.Utils\SMRenderer.Utils.csproj", "{079BAB31-3DC4-40DA-90C7-EFAA8517C647}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SM_TEST", "SM_TEST\SM_TEST.csproj", "{6D4FB8E6-4D0B-4928-8F9E-EF5C2FBF44E8}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SMRenderer.Intergrations", "src\optionals\SM.Intergrations\SMRenderer.Intergrations.csproj", "{4CB351F4-B3F2-4F77-ACC2-02F21DBF5EC2}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Optionals", "Optionals", "{AE5B181B-BD8F-4F36-A64E-32C4FF7B6FD6}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Renderer", "Renderer", "{62ED6240-4DEC-4535-95EB-AE3D90A3FDF5}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SM.Game", "SMOptionals\SM.Game\SM.Game.csproj", "{079BAB31-3DC4-40DA-90C7-EFAA8517C647}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Optionals", "Optionals", "{CC0E5493-29E8-4ACB-8462-5724A6F636DE}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SM_WPF_TEST", "SM_WPF_TEST\SM_WPF_TEST.csproj", "{6F5367D3-B7E9-40CE-A692-29F9892B6F2A}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{2D2EDE5F-6610-4DF9-AAFD-664F4023A99D}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -35,10 +35,6 @@ Global {8E733844-4204-43E7-B3DC-3913CDDABB0D}.Debug|Any CPU.Build.0 = Debug|Any CPU {8E733844-4204-43E7-B3DC-3913CDDABB0D}.Release|Any CPU.ActiveCfg = Release|Any CPU {8E733844-4204-43E7-B3DC-3913CDDABB0D}.Release|Any CPU.Build.0 = Release|Any CPU - {9BECA849-E6E9-4E15-83A6-ADD8C18065CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9BECA849-E6E9-4E15-83A6-ADD8C18065CB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9BECA849-E6E9-4E15-83A6-ADD8C18065CB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9BECA849-E6E9-4E15-83A6-ADD8C18065CB}.Release|Any CPU.Build.0 = Release|Any CPU {A4565538-625A-42C6-A330-DD4F1ABB3986}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {A4565538-625A-42C6-A330-DD4F1ABB3986}.Debug|Any CPU.Build.0 = Debug|Any CPU {A4565538-625A-42C6-A330-DD4F1ABB3986}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -51,20 +47,21 @@ Global {079BAB31-3DC4-40DA-90C7-EFAA8517C647}.Debug|Any CPU.Build.0 = Debug|Any CPU {079BAB31-3DC4-40DA-90C7-EFAA8517C647}.Release|Any CPU.ActiveCfg = Release|Any CPU {079BAB31-3DC4-40DA-90C7-EFAA8517C647}.Release|Any CPU.Build.0 = Release|Any CPU - {6F5367D3-B7E9-40CE-A692-29F9892B6F2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6F5367D3-B7E9-40CE-A692-29F9892B6F2A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6F5367D3-B7E9-40CE-A692-29F9892B6F2A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6F5367D3-B7E9-40CE-A692-29F9892B6F2A}.Release|Any CPU.Build.0 = Release|Any CPU + {4CB351F4-B3F2-4F77-ACC2-02F21DBF5EC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4CB351F4-B3F2-4F77-ACC2-02F21DBF5EC2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4CB351F4-B3F2-4F77-ACC2-02F21DBF5EC2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4CB351F4-B3F2-4F77-ACC2-02F21DBF5EC2}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {F604D684-BC1D-4819-88B5-8B5D03A17BE0} = {47EA2879-1D40-4683-BA6C-AB51F286EBDE} - {8E733844-4204-43E7-B3DC-3913CDDABB0D} = {47EA2879-1D40-4683-BA6C-AB51F286EBDE} - {9BECA849-E6E9-4E15-83A6-ADD8C18065CB} = {47EA2879-1D40-4683-BA6C-AB51F286EBDE} - {A4565538-625A-42C6-A330-DD4F1ABB3986} = {47EA2879-1D40-4683-BA6C-AB51F286EBDE} - {079BAB31-3DC4-40DA-90C7-EFAA8517C647} = {AE5B181B-BD8F-4F36-A64E-32C4FF7B6FD6} + {F604D684-BC1D-4819-88B5-8B5D03A17BE0} = {62ED6240-4DEC-4535-95EB-AE3D90A3FDF5} + {8E733844-4204-43E7-B3DC-3913CDDABB0D} = {62ED6240-4DEC-4535-95EB-AE3D90A3FDF5} + {A4565538-625A-42C6-A330-DD4F1ABB3986} = {62ED6240-4DEC-4535-95EB-AE3D90A3FDF5} + {6D4FB8E6-4D0B-4928-8F9E-EF5C2FBF44E8} = {2D2EDE5F-6610-4DF9-AAFD-664F4023A99D} + {079BAB31-3DC4-40DA-90C7-EFAA8517C647} = {CC0E5493-29E8-4ACB-8462-5724A6F636DE} + {4CB351F4-B3F2-4F77-ACC2-02F21DBF5EC2} = {CC0E5493-29E8-4ACB-8462-5724A6F636DE} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {51C827AB-3306-4EE6-9E60-B7BF84854469} diff --git a/SM_TEST/Program.cs b/SM_TEST/Program.cs deleted file mode 100644 index 940dcf7..0000000 --- a/SM_TEST/Program.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Drawing; -using OpenTK; -using OpenTK.Graphics; -using OpenTK.Graphics.OpenGL; -using SM.Base; -using SM.Base.Animation; -using SM.Base.Controls; -using SM.Base.Drawing; -using SM.Base.Time; -using SM.Base.Window; -using SM2D; -using SM2D.Drawing; -using SM2D.Object; -using SM2D.Scene; -using Font = SM.Base.Drawing.Text.Font; - -namespace SM_TEST -{ - class Program - { - static Scene scene; - private static GLWindow window; - private static PolyLine line; - private static DrawParticles particles; - - private static InterpolationProcess interpolation; - static void Main(string[] args) - { - Font font = new Font(@"C:\Windows\Fonts\Arial.ttf") - { - FontSize = 30, - }; - font.RegenerateTexture(); - - window = new GLWindow(1280, 720, "0ms", WindowFlags.Window, VSyncMode.Off); - window.ApplySetup(new Window2DSetup()); - - window.SetScene(scene = new Scene() - { - ShowAxisHelper = true - }); - scene.Background.Color = Color4.Blue; - scene.Camera = new Camera() - { - - }; - - DrawObject2D test = new DrawObject2D() - { - Texture = new Bitmap("test.png") - }; - test.Material.Blending = true; - test.Transform.Size.Set(100); - test.TextureTransform.SetRectangleRelative(test.Texture, new Vector2(234, 0), new Vector2(220, 201)); - test.Transform.AdjustSizeToTextureTransform(test.TextureTransform); - - scene.Objects.Add(test); - - window.UpdateFrame += WindowOnUpdateFrame; - window.RenderFrame += Window_RenderFrame; - window.Run(); - - Debug.WriteLine("Window Closed"); - } - - private static void Window_RenderFrame(object sender, FrameEventArgs e) - { - window.Title = Math.Floor(e.Time * 1000) + "ms"; - } - - private static void WindowOnUpdateFrame(object sender, FrameEventArgs e) - { - if (Mouse.LeftClick) - interpolation.Stop(); - if (Mouse.RightClick) - interpolation.Stop(false); - } - } -} \ No newline at end of file diff --git a/SM_TEST/TestRenderPipeline.cs b/SM_TEST/TestRenderPipeline.cs deleted file mode 100644 index 5c4edfb..0000000 --- a/SM_TEST/TestRenderPipeline.cs +++ /dev/null @@ -1,48 +0,0 @@ -using OpenTK.Graphics.OpenGL4; -using SM.Base.PostEffects; -using SM.Base.Window; -using SM.OGL.Framebuffer; -using SM.OGL.Texture; - -namespace SM_TEST -{ - public class TestRenderPipeline : RenderPipeline - { - private BloomEffect _bloom; - private Framebuffer _postBuffer; - - public override void Initialization() - { - - MainFramebuffer = CreateWindowFramebuffer(16, PixelInformation.RGBA_HDR); - - _postBuffer = CreateWindowFramebuffer(0, PixelInformation.RGBA_HDR, depth: false); - Framebuffers.Add(_postBuffer); - _bloom = new BloomEffect(_postBuffer, hdr: true, .5f) - { - Threshold = .5f, - }; - - - _bloom.Initilize(this); - base.Initialization(); - } - - protected override void RenderProcess(ref DrawContext context) - { - MainFramebuffer.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); - context.Scene.DrawBackground(context); - context.Scene.DrawMainObjects(context); - context.Scene.DrawHUD(context); - - PostProcessUtility.ResolveMultisampledBuffers(MainFramebuffer, _postBuffer); - - // _bloom.Draw(context); - Framebuffer.Screen.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); - - PostProcessUtility.FinalizeHDR(_postBuffer["color"], .5f); - - context.Scene.DrawDebug(context); - } - } -} \ No newline at end of file diff --git a/SM_WPF_TEST/App.config b/SM_WPF_TEST/App.config deleted file mode 100644 index 88fa402..0000000 --- a/SM_WPF_TEST/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/SM_WPF_TEST/App.xaml b/SM_WPF_TEST/App.xaml deleted file mode 100644 index c032034..0000000 --- a/SM_WPF_TEST/App.xaml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - diff --git a/SM_WPF_TEST/App.xaml.cs b/SM_WPF_TEST/App.xaml.cs deleted file mode 100644 index e481a44..0000000 --- a/SM_WPF_TEST/App.xaml.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Windows; - -namespace SM_WPF_TEST -{ - /// - /// Interaction logic for App.xaml - /// - public partial class App : Application - { - } -} diff --git a/SM_WPF_TEST/MainWindow.xaml b/SM_WPF_TEST/MainWindow.xaml deleted file mode 100644 index be260a8..0000000 --- a/SM_WPF_TEST/MainWindow.xaml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - diff --git a/SM_WPF_TEST/MainWindow.xaml.cs b/SM_WPF_TEST/MainWindow.xaml.cs deleted file mode 100644 index 5ee0f90..0000000 --- a/SM_WPF_TEST/MainWindow.xaml.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Windows; - -namespace SM_WPF_TEST -{ - /// - /// Interaction logic for MainWindow.xaml - /// - public partial class MainWindow : Window - { - public MainWindow() - { - InitializeComponent(); - /* - GLWPFWindow2D gl; - Scene scene; - gl = new GLWPFWindow2D(); - Grid.SetColumn(gl, 1); - grid.Children.Add(gl); - - gl.Start(); - - gl.SetScene(scene = new Scene()); - gl.SetRenderPipeline(Default2DPipeline.Pipeline); - - DrawObject2D cube = new DrawObject2D(); - cube.Color = Color4.Blue; - scene.Objects.Add(cube); - - new Window1().Show();*/ - } - } -} diff --git a/SM_WPF_TEST/Properties/AssemblyInfo.cs b/SM_WPF_TEST/Properties/AssemblyInfo.cs deleted file mode 100644 index 499ad94..0000000 --- a/SM_WPF_TEST/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; -using System.Windows; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("SM_WPF_TEST")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("SM_WPF_TEST")] -[assembly: AssemblyCopyright("Copyright © 2021")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -//In order to begin building localizable applications, set -//CultureYouAreCodingWith in your .csproj file -//inside a . For example, if you are using US english -//in your source files, set the to en-US. Then uncomment -//the NeutralResourceLanguage attribute below. Update the "en-US" in -//the line below to match the UICulture setting in the project file. - -//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] - - -[assembly: ThemeInfo( - ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located - //(used if a resource is not found in the page, - // or application resource dictionaries) - ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located - //(used if a resource is not found in the page, - // app, or any theme specific resource dictionaries) -)] - - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/SM_WPF_TEST/Properties/Resources.Designer.cs b/SM_WPF_TEST/Properties/Resources.Designer.cs deleted file mode 100644 index 9cf796e..0000000 --- a/SM_WPF_TEST/Properties/Resources.Designer.cs +++ /dev/null @@ -1,70 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -namespace SM_WPF_TEST.Properties -{ - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources - { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() - { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager - { - get - { - if ((resourceMan == null)) - { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SM_WPF_TEST.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture - { - get - { - return resourceCulture; - } - set - { - resourceCulture = value; - } - } - } -} diff --git a/SM_WPF_TEST/Properties/Resources.resx b/SM_WPF_TEST/Properties/Resources.resx deleted file mode 100644 index af7dbeb..0000000 --- a/SM_WPF_TEST/Properties/Resources.resx +++ /dev/null @@ -1,117 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/SM_WPF_TEST/Properties/Settings.Designer.cs b/SM_WPF_TEST/Properties/Settings.Designer.cs deleted file mode 100644 index a1c90c7..0000000 --- a/SM_WPF_TEST/Properties/Settings.Designer.cs +++ /dev/null @@ -1,29 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - - -namespace SM_WPF_TEST.Properties -{ - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase - { - - private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default - { - get - { - return defaultInstance; - } - } - } -} diff --git a/SM_WPF_TEST/Properties/Settings.settings b/SM_WPF_TEST/Properties/Settings.settings deleted file mode 100644 index 033d7a5..0000000 --- a/SM_WPF_TEST/Properties/Settings.settings +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/SM_WPF_TEST/SM_WPF_TEST.csproj b/SM_WPF_TEST/SM_WPF_TEST.csproj deleted file mode 100644 index 3d7484c..0000000 --- a/SM_WPF_TEST/SM_WPF_TEST.csproj +++ /dev/null @@ -1,102 +0,0 @@ - - - - - Debug - AnyCPU - {6F5367D3-B7E9-40CE-A692-29F9892B6F2A} - WinExe - SM_WPF_TEST - SM_WPF_TEST - v4.5.2 - 512 - {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 4 - true - true - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - 4.0 - - - - - - - - MSBuild:Compile - Designer - - - Window1.xaml - - - MSBuild:Compile - Designer - - - App.xaml - Code - - - MainWindow.xaml - Code - - - Designer - MSBuild:Compile - - - - - Code - - - True - True - Resources.resx - - - True - Settings.settings - True - - - ResXFileCodeGenerator - Resources.Designer.cs - - - - - SettingsSingleFileGenerator - Settings.Designer.cs - - - - - - - \ No newline at end of file diff --git a/SM_WPF_TEST/Window1.xaml b/SM_WPF_TEST/Window1.xaml deleted file mode 100644 index 70408e6..0000000 --- a/SM_WPF_TEST/Window1.xaml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - diff --git a/SM_WPF_TEST/Window1.xaml.cs b/SM_WPF_TEST/Window1.xaml.cs deleted file mode 100644 index d5d3271..0000000 --- a/SM_WPF_TEST/Window1.xaml.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Windows; - -namespace SM_WPF_TEST -{ - /// - /// Interaction logic for Window1.xaml - /// - public partial class Window1 : Window - { - public Window1() - { - InitializeComponent(); - - /*GLWPFWindow2D gl; - Scene scene; - Content = gl = new GLWPFWindow2D(); - gl.Start(); - - gl.SetScene(scene = new Scene()); - gl.SetRenderPipeline(Basic2DPipeline.Pipeline); - - DrawObject2D obj = new DrawObject2D() - { - Color = Color4.Red - }; - obj.ApplyCircle(); - scene.Objects.Add(obj);*/ - } - } -} diff --git a/SMCode/SM.Base/OpenTK.dll.config b/src/optionals/SM.Intergrations/OpenTK.dll.config similarity index 100% rename from SMCode/SM.Base/OpenTK.dll.config rename to src/optionals/SM.Intergrations/OpenTK.dll.config diff --git a/SMCode/SM3D/Properties/AssemblyInfo.cs b/src/optionals/SM.Intergrations/Properties/AssemblyInfo.cs similarity index 75% rename from SMCode/SM3D/Properties/AssemblyInfo.cs rename to src/optionals/SM.Intergrations/Properties/AssemblyInfo.cs index f2e6bad..eeec0f3 100644 --- a/SMCode/SM3D/Properties/AssemblyInfo.cs +++ b/src/optionals/SM.Intergrations/Properties/AssemblyInfo.cs @@ -1,19 +1,16 @@ -#region usings - -using System.Reflection; +using System.Reflection; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -#endregion - // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("SM3D")] +[assembly: AssemblyTitle("SM.Intergrations")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("SM3D")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2020")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SM.Intergrations")] +[assembly: AssemblyCopyright("Copyright © 2021")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -23,7 +20,7 @@ using System.Runtime.InteropServices; [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("9beca849-e6e9-4e15-83a6-add8c18065cb")] +[assembly: Guid("4cb351f4-b3f2-4f77-acc2-02f21dbf5ec2")] // Version information for an assembly consists of the following four values: // @@ -36,4 +33,4 @@ using System.Runtime.InteropServices; // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/SM_TEST/SM_TEST.csproj b/src/optionals/SM.Intergrations/SMRenderer.Intergrations.csproj similarity index 63% rename from SM_TEST/SM_TEST.csproj rename to src/optionals/SM.Intergrations/SMRenderer.Intergrations.csproj index 5cd19ac..aeea189 100644 --- a/SM_TEST/SM_TEST.csproj +++ b/src/optionals/SM.Intergrations/SMRenderer.Intergrations.csproj @@ -4,17 +4,17 @@ Debug AnyCPU - {6D4FB8E6-4D0B-4928-8F9E-EF5C2FBF44E8} - WinExe - SM_TEST - SM_TEST + {4CB351F4-B3F2-4F77-ACC2-02F21DBF5EC2} + Library + Properties + SM.Intergrations + SM.Intergrations v4.5.2 512 - true true + - AnyCPU true full false @@ -24,7 +24,6 @@ 4 - AnyCPU pdbonly true bin\Release\ @@ -32,43 +31,43 @@ prompt 4 - - - - ..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll + ..\..\..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll + + + ..\..\..\packages\ShaderToolParser.1.0.0-pre3\lib\net450\ShaderToolParser.dll + + + + + + - - + + + + - - - - - - - - - + {8e733844-4204-43e7-b3dc-3913cddabb0d} SM.Base - + {f604d684-bc1d-4819-88b5-8b5d03a17be0} SM.OGL - - {a4565538-625a-42c6-a330-dd4f1abb3986} - SM2D - + + + + \ No newline at end of file diff --git a/src/optionals/SM.Intergrations/ShaderTool/STMaterial.cs b/src/optionals/SM.Intergrations/ShaderTool/STMaterial.cs new file mode 100644 index 0000000..5f52732 --- /dev/null +++ b/src/optionals/SM.Intergrations/ShaderTool/STMaterial.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.IO.Pipes; +using OpenTK; +using OpenTK.Graphics; +using ShaderToolParser.Nodes; +using ShaderToolParser.Nodes.Textures; +using ShaderToolParser.Variables; +using SM.Base.Drawing; +using SM.Base.Textures; +using SM.Base.Window; + +namespace SM.Intergrations.ShaderTool +{ + public class STMaterial : Material + { + private Vector4 _tintVector = Vector4.One; + + public override Color4 Tint + { + get => Color4.FromXyz(_tintVector); + set => _tintVector = Color4.ToXyz(value); + } + + public STMaterial(STPDrawNode node) + { + if (node.OGLEffect == null) + throw new Exception("[ERROR AT IMPORTING MATERIAL] DrawNode didn't contain a OpenGL-shader."); + + CustomShader = new STMaterialShader(node); + + foreach (KeyValuePair pair in node.Variables) + { + if (pair.Value.Type == STPBasisType.Texture) + ShaderArguments[pair.Key] = new Texture(((STPTextureNode) pair.Value.Texture).Bitmap); + } + } + + public override void Draw(DrawContext context) + { + ShaderArguments["MVP"] = context.Instances[0].ModelMatrix * context.ModelMatrix * context.View * context.World; + ShaderArguments["MasterTextureMatrix"] = context.Instances[0].TextureMatrix * context.TextureMatrix; + ShaderArguments["HasVColor"] = context.Mesh.Attributes.Has("color"); + + ShaderArguments["_MATColor"] = _tintVector; + + base.Draw(context); + } + } +} \ No newline at end of file diff --git a/src/optionals/SM.Intergrations/ShaderTool/STMaterialShader.cs b/src/optionals/SM.Intergrations/ShaderTool/STMaterialShader.cs new file mode 100644 index 0000000..dbc876e --- /dev/null +++ b/src/optionals/SM.Intergrations/ShaderTool/STMaterialShader.cs @@ -0,0 +1,70 @@ + +using System; +using System.Collections.Generic; +using OpenTK; +using ShaderToolParser.Nodes; +using ShaderToolParser.Variables; +using SM.Base.Shaders; +using SM.Base.Textures; +using SM.Base.Window; +using SM.OGL.Shaders; +using SM.OGL.Texture; + +namespace SM.Intergrations.ShaderTool +{ + public class STMaterialShader : MaterialShader + { + private event Action _uniforms; + + public STMaterialShader(STPDrawNode drawNode) : base(new ShaderFileCollection()) + { + if (drawNode.OGLEffect == null) + throw new Exception("[ERROR AT IMPORTING SHADER] DrawNode didn't contain a OpenGL-shader."); + + STPCompositeNode composeNode = drawNode.OGLEffect; + + ShaderFiles.Vertex = new[] { new ShaderFile(composeNode.Vertex.ShaderCode) }; + ShaderFiles.Fragment = new [] {new ShaderFile(composeNode.Fragment.ShaderCode)}; + if (composeNode.Geometry != null) + 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].SetBool(context.Material.ShaderArguments.Get(pair.Key, false)); + break; + case STPBasisType.Float: + _uniforms += context => Uniforms[pair.Key].SetFloat(context.Material.ShaderArguments.Get(pair.Key, 0.0f)); + break; + case STPBasisType.Vector2: + _uniforms += context => Uniforms[pair.Key].SetVector2(context.Material.ShaderArguments.Get(pair.Key, Vector2.Zero)); + break; + case STPBasisType.Vector3: + _uniforms += context => Uniforms[pair.Key].SetVector3(context.Material.ShaderArguments.Get(pair.Key, Vector3.Zero)); + break; + case STPBasisType.Vector4: + _uniforms += context => + 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)); + break; + case STPBasisType.Texture: + _uniforms += context => Uniforms[pair.Key].SetTexture(context.Material.ShaderArguments.Get(pair.Key, null)); + break; + default: + throw new ArgumentOutOfRangeException(); + } + } + } + + protected override void DrawProcess(DrawContext context) + { + _uniforms.Invoke(context); + + DrawObject(context.ForcedType.GetValueOrDefault(context.Mesh.PrimitiveType), context.Mesh); + } + } +} \ No newline at end of file diff --git a/src/optionals/SM.Intergrations/ShaderTool/STPostProcessEffect.cs b/src/optionals/SM.Intergrations/ShaderTool/STPostProcessEffect.cs new file mode 100644 index 0000000..6b70f88 --- /dev/null +++ b/src/optionals/SM.Intergrations/ShaderTool/STPostProcessEffect.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using OpenTK.Graphics.OpenGL4; +using ShaderToolParser.Nodes; +using ShaderToolParser.Nodes.Textures; +using ShaderToolParser.Variables; +using SM.Base.Drawing; +using SM.Base.PostProcess; +using SM.Base.Textures; +using SM.Base.Window; +using SM.OGL.Framebuffer; +using SM.OGL.Texture; + +namespace SM.Intergrations.ShaderTool +{ + public class STPostProcessEffect : PostProcessEffect + { + private STPostProcessShader _shader; + private Framebuffer tempFramebuffer; + + public ShaderArguments Arguments; + + public STPostProcessEffect(STPDrawNode postEffectNode) + { + Arguments = Arguments ?? new ShaderArguments(); + + if (postEffectNode.OGLEffect == null) + throw new Exception("[ERROR AT IMPORTING EFFECT] DrawNode didn't contain a OpenGL-shader."); + + _shader = new STPostProcessShader(postEffectNode); + + foreach (KeyValuePair pair in postEffectNode.Variables) + { + + if (pair.Value.Type == STPBasisType.Texture) + { + if (pair.Value.Texture == null) continue; + Arguments[pair.Key] = new Texture(((STPTextureNode)pair.Value.Texture).Bitmap); + } + } + } + + protected override void InitProcess() + { + base.InitProcess(); + tempFramebuffer = Pipeline.CreateWindowFramebuffer(0, PixelInformation.RGB_HDR, false); + tempFramebuffer.Compile(); + } + + public override void ScreenSizeChanged(IGenericWindow window) + { + tempFramebuffer.Recompile(); + } + + protected override void Drawing(ColorAttachment source, DrawContext context) + { + Arguments["_Scene"] = (TextureBase)source; + Arguments["_MVP"] = Mvp; + Arguments["_ViewportSize"] = context.Window.WindowSize; + + source.ConnectedFramebuffer.CopyTo(tempFramebuffer); + tempFramebuffer.Activate(); + + _shader.Draw(Arguments); + tempFramebuffer.CopyTo(source.ConnectedFramebuffer); + } + } +} \ No newline at end of file diff --git a/src/optionals/SM.Intergrations/ShaderTool/STPostProcessShader.cs b/src/optionals/SM.Intergrations/ShaderTool/STPostProcessShader.cs new file mode 100644 index 0000000..a8226cc --- /dev/null +++ b/src/optionals/SM.Intergrations/ShaderTool/STPostProcessShader.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using OpenTK; +using OpenTK.Graphics.OpenGL4; +using ShaderToolParser.Nodes; +using ShaderToolParser.Variables; +using SM.Base.Drawing; +using SM.Base.Objects.Static; +using SM.Base.Textures; +using SM.OGL.Shaders; +using SM.OGL.Texture; + +namespace SM.Intergrations.ShaderTool +{ + public class STPostProcessShader : GenericShader + { + private event Action _uniforms; + + public STPostProcessShader(STPDrawNode postProcessNode) : base(new ShaderFileCollection()) + { + if (postProcessNode.OGLEffect == null) + throw new Exception("[ERROR AT IMPORTING SHADER] DrawNode didn't contain a OpenGL-shader."); + + STPCompositeNode composeNode = postProcessNode.OGLEffect; + + ShaderFiles.Vertex = new[] { new ShaderFile(composeNode.Vertex.ShaderCode) }; + ShaderFiles.Fragment = new[] { new ShaderFile(composeNode.Fragment.ShaderCode) }; + if (composeNode.Geometry != null) + 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].SetBool(context.Get(pair.Key, false)); + break; + case STPBasisType.Float: + _uniforms += context => Uniforms[pair.Key].SetFloat(context.Get(pair.Key, 0.0f)); + break; + case STPBasisType.Vector2: + _uniforms += context => Uniforms[pair.Key].SetVector2(context.Get(pair.Key, Vector2.Zero)); + break; + case STPBasisType.Vector3: + _uniforms += context => Uniforms[pair.Key].SetVector3(context.Get(pair.Key, Vector3.Zero)); + break; + case STPBasisType.Vector4: + _uniforms += context => + 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)); + break; + case STPBasisType.Texture: + _uniforms += context => Uniforms[pair.Key].SetTexture(context.Get(pair.Key, null)); + break; + default: + throw new ArgumentOutOfRangeException(); + } + } + } + + public void Draw(ShaderArguments arguments) + { + Activate(); + Plate.Object.Activate(); + + _uniforms.Invoke(arguments); + + GL.DrawArrays(PrimitiveType.Quads, 0, 4); + CleanUp(); + } + } +} \ No newline at end of file diff --git a/SMCode/SM.OGL/packages.config b/src/optionals/SM.Intergrations/packages.config similarity index 61% rename from SMCode/SM.OGL/packages.config rename to src/optionals/SM.Intergrations/packages.config index 82cdaeb..12fbc5b 100644 --- a/SMCode/SM.OGL/packages.config +++ b/src/optionals/SM.Intergrations/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file diff --git a/src/optionals/SM.Utils/Controls/GameController.cs b/src/optionals/SM.Utils/Controls/GameController.cs new file mode 100644 index 0000000..43570dc --- /dev/null +++ b/src/optionals/SM.Utils/Controls/GameController.cs @@ -0,0 +1,56 @@ +using SharpDX.XInput; +using SM.Base; + +namespace SM.Utils.Controls +{ + public class GameController + { + 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 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(bool force = false) + { + if (!force && _lastFrame == SMRenderer.CurrentFrame) + { + return LastState; + } + + GameControllerState st = new GameControllerState(true); + if (IsConnected) + { + Gamepad state = _controller.GetState().Gamepad; + st = new GameControllerState(state, this); + _lastPressedButtons = state.Buttons; + } + + LastState = st; + + _lastFrame = SMRenderer.CurrentFrame; + + return st; + } + + } +} \ No newline at end of file diff --git a/SMOptionals/SM.Game/Controls/GameControllerState.cs b/src/optionals/SM.Utils/Controls/GameControllerState.cs similarity index 58% rename from SMOptionals/SM.Game/Controls/GameControllerState.cs rename to src/optionals/SM.Utils/Controls/GameControllerState.cs index 414a2ae..7a20aa4 100644 --- a/SMOptionals/SM.Game/Controls/GameControllerState.cs +++ b/src/optionals/SM.Utils/Controls/GameControllerState.cs @@ -2,7 +2,7 @@ using OpenTK; using SharpDX.XInput; -namespace SM.Game.Controls +namespace SM.Utils.Controls { public struct GameControllerState { @@ -12,7 +12,7 @@ namespace SM.Game.Controls public GameControllerStateButtons Buttons; public bool FromConnected { get; } - + public bool AnyInteraction => Buttons.AnyInteraction || DPad.AnyInteraction || Triggers.AnyInteraction || Thumbs.AnyInteraction; internal GameControllerState(bool empty) { FromConnected = false; @@ -22,22 +22,11 @@ namespace SM.Game.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.Game.Controls }; DPad = new GameControllerStateDPad(state.Buttons); - Buttons = new GameControllerStateButtons(state.Buttons); + Buttons = new GameControllerStateButtons(state.Buttons, controller); } public override string ToString() diff --git a/SMOptionals/SM.Game/Controls/GameControllerStateButtons.cs b/src/optionals/SM.Utils/Controls/GameControllerStateButtons.cs similarity index 63% rename from SMOptionals/SM.Game/Controls/GameControllerStateButtons.cs rename to src/optionals/SM.Utils/Controls/GameControllerStateButtons.cs index 57aca8c..5bcd5f4 100644 --- a/SMOptionals/SM.Game/Controls/GameControllerStateButtons.cs +++ b/src/optionals/SM.Utils/Controls/GameControllerStateButtons.cs @@ -1,12 +1,17 @@ using SharpDX.XInput; -namespace SM.Game.Controls +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; @@ -19,11 +24,17 @@ namespace SM.Game.Controls public bool LeftThumb; public bool RightThumb; - public bool this[GamepadButtonFlags flags] => _buttonFlags.HasFlag(flags); + public bool Start; + public bool Back; - internal GameControllerStateButtons(GamepadButtonFlags flags) + public bool this[GamepadButtonFlags flags, bool once = false] => _buttonFlags.HasFlag(flags) && !(once && _lastButtonFlags.HasFlag(flags)); + + public bool AnyInteraction { get; } + + internal GameControllerStateButtons(GamepadButtonFlags flags, GameController controller) { _buttonFlags = flags; + _lastButtonFlags = controller._lastPressedButtons; X = flags.HasFlag(GamepadButtonFlags.X); Y = flags.HasFlag(GamepadButtonFlags.Y); @@ -35,6 +46,11 @@ namespace SM.Game.Controls LeftThumb = flags.HasFlag(GamepadButtonFlags.LeftThumb); RightThumb = flags.HasFlag(GamepadButtonFlags.RightThumb); + + Start = flags.HasFlag(GamepadButtonFlags.Start); + Back = flags.HasFlag(GamepadButtonFlags.Back); + + AnyInteraction = (int) flags >= 16; } public override string ToString() diff --git a/SMOptionals/SM.Game/Controls/GameControllerStateDPad.cs b/src/optionals/SM.Utils/Controls/GameControllerStateDPad.cs similarity index 85% rename from SMOptionals/SM.Game/Controls/GameControllerStateDPad.cs rename to src/optionals/SM.Utils/Controls/GameControllerStateDPad.cs index 5385e60..ff3b30e 100644 --- a/SMOptionals/SM.Game/Controls/GameControllerStateDPad.cs +++ b/src/optionals/SM.Utils/Controls/GameControllerStateDPad.cs @@ -1,6 +1,6 @@ using SharpDX.XInput; -namespace SM.Game.Controls +namespace SM.Utils.Controls { public struct GameControllerStateDPad { @@ -11,12 +11,16 @@ namespace SM.Game.Controls public bool Left; public bool Right; + public bool AnyInteraction { get; } + internal GameControllerStateDPad(GamepadButtonFlags flags) { Up = flags.HasFlag(GamepadButtonFlags.DPadUp); Down = flags.HasFlag(GamepadButtonFlags.DPadDown); Left = flags.HasFlag(GamepadButtonFlags.DPadLeft); Right = flags.HasFlag(GamepadButtonFlags.DPadRight); + + AnyInteraction = (int)flags > 0 && (int) flags < 16; } public override string ToString() diff --git a/src/optionals/SM.Utils/Controls/GameControllerStateThumbs.cs b/src/optionals/SM.Utils/Controls/GameControllerStateThumbs.cs new file mode 100644 index 0000000..6741a3c --- /dev/null +++ b/src/optionals/SM.Utils/Controls/GameControllerStateThumbs.cs @@ -0,0 +1,37 @@ +using System; +using OpenTK; +using SharpDX.XInput; + +namespace SM.Utils.Controls +{ + public struct GameControllerStateThumbs + { + public static GameControllerStateThumbs Default = new GameControllerStateThumbs() + {Left = Vector2.Zero, Right = Vector2.Zero}; + + public Vector2 Left; + public Vector2 Right; + + public bool PressedLeft; + public bool PressedRight; + + 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" : "")}"; + } + } +} \ No newline at end of file diff --git a/SMOptionals/SM.Game/Controls/GameControllerStateTriggers.cs b/src/optionals/SM.Utils/Controls/GameControllerStateTriggers.cs similarity index 78% rename from SMOptionals/SM.Game/Controls/GameControllerStateTriggers.cs rename to src/optionals/SM.Utils/Controls/GameControllerStateTriggers.cs index 3c99852..3d3f41c 100644 --- a/SMOptionals/SM.Game/Controls/GameControllerStateTriggers.cs +++ b/src/optionals/SM.Utils/Controls/GameControllerStateTriggers.cs @@ -1,4 +1,4 @@ -namespace SM.Game.Controls +namespace SM.Utils.Controls { public struct GameControllerStateTriggers { @@ -6,6 +6,9 @@ public float Left; public float Right; + + public bool AnyInteraction => Left != 0f || Right != 0f; + public override string ToString() { return $"Left: {Left}; Right: {Right}"; diff --git a/SMOptionals/SM.Game/Controls/GameKeybind.cs b/src/optionals/SM.Utils/Controls/GameKeybind.cs similarity index 90% rename from SMOptionals/SM.Game/Controls/GameKeybind.cs rename to src/optionals/SM.Utils/Controls/GameKeybind.cs index eb306c8..b8a683d 100644 --- a/SMOptionals/SM.Game/Controls/GameKeybind.cs +++ b/src/optionals/SM.Utils/Controls/GameKeybind.cs @@ -1,6 +1,6 @@ using System; -namespace SM.Game.Controls +namespace SM.Utils.Controls { public class GameKeybind { @@ -18,10 +18,8 @@ namespace SM.Game.Controls return AI; case GameKeybindActorType.Keyboard: return Keyboard; - break; case GameKeybindActorType.Controller: return Controller; - break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } diff --git a/SMOptionals/SM.Game/Controls/GameKeybindActor.cs b/src/optionals/SM.Utils/Controls/GameKeybindActor.cs similarity index 81% rename from SMOptionals/SM.Game/Controls/GameKeybindActor.cs rename to src/optionals/SM.Utils/Controls/GameKeybindActor.cs index c0527c3..7dfd976 100644 --- a/SMOptionals/SM.Game/Controls/GameKeybindActor.cs +++ b/src/optionals/SM.Utils/Controls/GameKeybindActor.cs @@ -1,6 +1,6 @@ using OpenTK.Input; -namespace SM.Game.Controls +namespace SM.Utils.Controls { public enum GameKeybindActorType { @@ -12,16 +12,25 @@ namespace SM.Game.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.Game.Controls KeyboardState = Keyboard.GetState(), MouseState = Mouse.GetState(), - ControllerState = Controller?.GetState(), + ControllerState = Controller?.GetState() ?? new GameControllerState(true), }; return keybind[Type].Invoke(context); diff --git a/SMOptionals/SM.Game/Controls/GameKeybindContext.cs b/src/optionals/SM.Utils/Controls/GameKeybindContext.cs similarity index 79% rename from SMOptionals/SM.Game/Controls/GameKeybindContext.cs rename to src/optionals/SM.Utils/Controls/GameKeybindContext.cs index 08b6cb4..c08fe7c 100644 --- a/SMOptionals/SM.Game/Controls/GameKeybindContext.cs +++ b/src/optionals/SM.Utils/Controls/GameKeybindContext.cs @@ -1,12 +1,12 @@ using OpenTK.Input; -namespace SM.Game.Controls +namespace SM.Utils.Controls { public struct GameKeybindContext { public KeyboardState KeyboardState; public MouseState MouseState; - public GameControllerState? ControllerState; + public GameControllerState ControllerState; public GameKeybindActor Actor; public GameKeybindHost Host; diff --git a/SMOptionals/SM.Game/Controls/GameKeybindHost.cs b/src/optionals/SM.Utils/Controls/GameKeybindHost.cs similarity index 97% rename from SMOptionals/SM.Game/Controls/GameKeybindHost.cs rename to src/optionals/SM.Utils/Controls/GameKeybindHost.cs index c1d57f6..30c9832 100644 --- a/SMOptionals/SM.Game/Controls/GameKeybindHost.cs +++ b/src/optionals/SM.Utils/Controls/GameKeybindHost.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace SM.Game.Controls +namespace SM.Utils.Controls { public class GameKeybindHost { diff --git a/SMOptionals/SM.Game/Controls/GameKeybindList.cs b/src/optionals/SM.Utils/Controls/GameKeybindList.cs similarity index 96% rename from SMOptionals/SM.Game/Controls/GameKeybindList.cs rename to src/optionals/SM.Utils/Controls/GameKeybindList.cs index 97662e1..b5db7ed 100644 --- a/SMOptionals/SM.Game/Controls/GameKeybindList.cs +++ b/src/optionals/SM.Utils/Controls/GameKeybindList.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace SM.Game.Controls +namespace SM.Utils.Controls { public class GameKeybindList : List> { diff --git a/SMCode/SM.OGL/OpenTK.dll.config b/src/optionals/SM.Utils/OpenTK.dll.config similarity index 100% rename from SMCode/SM.OGL/OpenTK.dll.config rename to src/optionals/SM.Utils/OpenTK.dll.config diff --git a/SMOptionals/SM.Game/Properties/AssemblyInfo.cs b/src/optionals/SM.Utils/Properties/AssemblyInfo.cs similarity index 100% rename from SMOptionals/SM.Game/Properties/AssemblyInfo.cs rename to src/optionals/SM.Utils/Properties/AssemblyInfo.cs diff --git a/SMOptionals/SM.Game/SM.Game.csproj b/src/optionals/SM.Utils/SMRenderer.Utils.csproj similarity index 83% rename from SMOptionals/SM.Game/SM.Game.csproj rename to src/optionals/SM.Utils/SMRenderer.Utils.csproj index cf248b4..3e2f80f 100644 --- a/SMOptionals/SM.Game/SM.Game.csproj +++ b/src/optionals/SM.Utils/SMRenderer.Utils.csproj @@ -7,11 +7,12 @@ {079BAB31-3DC4-40DA-90C7-EFAA8517C647} Library Properties - SM.Game - SM.Game + SM.Utils + SM.Utils v4.5.2 512 true + true @@ -32,13 +33,13 @@ - ..\..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll + ..\..\..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll - ..\..\packages\SharpDX.4.2.0\lib\net45\SharpDX.dll + ..\..\..\packages\SharpDX.4.2.0\lib\net45\SharpDX.dll - ..\..\packages\SharpDX.XInput.4.2.0\lib\net45\SharpDX.XInput.dll + ..\..\..\packages\SharpDX.XInput.4.2.0\lib\net45\SharpDX.XInput.dll @@ -61,5 +62,11 @@ + + + {8e733844-4204-43e7-b3dc-3913cddabb0d} + SM.Base + + \ No newline at end of file diff --git a/SMOptionals/SM.Game/packages.config b/src/optionals/SM.Utils/packages.config similarity index 100% rename from SMOptionals/SM.Game/packages.config rename to src/optionals/SM.Utils/packages.config diff --git a/SMCode/SM.Base/Animation/AnimationCurves.cs b/src/renderer/SM.Base/Animation/AnimationCurves.cs similarity index 100% rename from SMCode/SM.Base/Animation/AnimationCurves.cs rename to src/renderer/SM.Base/Animation/AnimationCurves.cs diff --git a/SMCode/SM.Base/Animation/InterpolationProcess.cs b/src/renderer/SM.Base/Animation/InterpolationProcess.cs similarity index 100% rename from SMCode/SM.Base/Animation/InterpolationProcess.cs rename to src/renderer/SM.Base/Animation/InterpolationProcess.cs diff --git a/SMCode/SM.Base/Controls/Keyboard.cs b/src/renderer/SM.Base/Controls/Keyboard.cs similarity index 100% rename from SMCode/SM.Base/Controls/Keyboard.cs rename to src/renderer/SM.Base/Controls/Keyboard.cs diff --git a/SMCode/SM.Base/Controls/Mouse.cs b/src/renderer/SM.Base/Controls/Mouse.cs similarity index 76% rename from SMCode/SM.Base/Controls/Mouse.cs rename to src/renderer/SM.Base/Controls/Mouse.cs index 1309818..0a18ce9 100644 --- a/SMCode/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/SMCode/SM.Base/Drawing/DrawingBasis.cs b/src/renderer/SM.Base/Drawing/DrawingBasis.cs similarity index 100% rename from SMCode/SM.Base/Drawing/DrawingBasis.cs rename to src/renderer/SM.Base/Drawing/DrawingBasis.cs diff --git a/SMCode/SM.Base/Drawing/GenericTransformation.cs b/src/renderer/SM.Base/Drawing/GenericTransformation.cs similarity index 86% rename from SMCode/SM.Base/Drawing/GenericTransformation.cs rename to src/renderer/SM.Base/Drawing/GenericTransformation.cs index 3d3325a..8a3bcdf 100644 --- a/SMCode/SM.Base/Drawing/GenericTransformation.cs +++ b/src/renderer/SM.Base/Drawing/GenericTransformation.cs @@ -39,9 +39,16 @@ namespace SM.Base.Drawing /// /// Returns the current model matrix. /// + /// If set to true, it will always (re-)calculate the model matrix. /// - public Matrix4 GetMatrix() + public Matrix4 GetMatrix(bool force = false) { + if (force) + { + _lastFrame = SMRenderer.CurrentFrame; + return _modelMatrix = RequestMatrix(); + } + if (Ignore) return Matrix4.Identity; if (_lastFrame != SMRenderer.CurrentFrame) diff --git a/SMCode/SM.Base/Drawing/Instance.cs b/src/renderer/SM.Base/Drawing/Instance.cs similarity index 100% rename from SMCode/SM.Base/Drawing/Instance.cs rename to src/renderer/SM.Base/Drawing/Instance.cs diff --git a/SMCode/SM.Base/Drawing/Material.cs b/src/renderer/SM.Base/Drawing/Material.cs similarity index 61% rename from SMCode/SM.Base/Drawing/Material.cs rename to src/renderer/SM.Base/Drawing/Material.cs index 3f14675..c1d1663 100644 --- a/SMCode/SM.Base/Drawing/Material.cs +++ b/src/renderer/SM.Base/Drawing/Material.cs @@ -2,6 +2,7 @@ using OpenTK.Graphics; using SM.Base.Shaders; +using SM.Base.Window; using SM.OGL.Texture; #endregion @@ -16,26 +17,35 @@ namespace SM.Base.Drawing /// /// A setting to enable Blending. /// - public bool Blending = false; + public virtual bool Blending { get; set; } = false; /// /// A custom shader, that is used to draw this material. /// - public MaterialShader CustomShader; + public virtual MaterialShader CustomShader { get; set; } /// /// The base texture. (aka. Diffuse Texture) /// - public TextureBase Texture; + public virtual TextureBase Texture { get; set; } /// /// The tint or color. /// - public Color4 Tint = Color4.White; + public virtual Color4 Tint { get; set; } = Color4.White; /// /// This allows custom shaders to use own shader arguments. /// 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); + } } } \ No newline at end of file diff --git a/src/renderer/SM.Base/Drawing/Particles/ParticleDrawingBasis.cs b/src/renderer/SM.Base/Drawing/Particles/ParticleDrawingBasis.cs new file mode 100644 index 0000000..8461927 --- /dev/null +++ b/src/renderer/SM.Base/Drawing/Particles/ParticleDrawingBasis.cs @@ -0,0 +1,212 @@ +#region usings + +using System; +using System.Collections.Generic; +using OpenTK; +using SM.Base.Scene; +using SM.Base.Time; +using SM.Base.Window; +using Stopwatch = System.Diagnostics.Stopwatch; + +#endregion + +namespace SM.Base.Drawing.Particles +{ + /// + /// The (drawing) basis for particles + /// + public abstract class ParticleDrawingBasis : DrawingBasis, IScriptable + where TTransform : GenericTransformation, new() + where TDirection : struct + { + private float? _continuesIntervalSeconds = null; + private Interval _continuesInterval; + + /// + /// The stopwatch of the particles. + /// + protected Timer timer; + + /// + /// This contains the different instances for the particles. + /// + protected List> instances; + + /// + /// The amount of particles + /// + public int Amount = 32; + + /// + /// The base lifetime for particles in seconds. + /// + public float Lifetime; + /// + /// Randomizes the lifetime for particles. + /// + public float LifetimeRandomize = 0; + + /// + /// If set to any value (except null), it will create the particles continuously. + /// + public float? ContinuousInterval + { + get => _continuesIntervalSeconds; + set + { + if (value.HasValue) + { + _continuesInterval.Target = value.Value; + } + + _continuesIntervalSeconds = value; + } + } + + /// + /// If true, the particles will spawn in Worldspace and can't be moved by the transformation. + /// + public bool DetachedParticles; + + /// + /// The maximum speed of the particles + /// Default: 25 + /// + public float MaxSpeed = 25; + + /// + /// Sets up the timer. + /// + /// Duration how long the particles should live + protected ParticleDrawingBasis(TimeSpan duration) + { + timer = new Timer(duration); + _continuesInterval = new Interval(0); + _continuesInterval.End += CreateContinuesParticles; + + Lifetime = (float) duration.TotalSeconds; + } + + /// + /// Get/Sets the state of pausing. + /// + public bool Paused + { + get => timer.Paused; + set => timer.Paused = value; + } + + /// + /// Controls the movement of each particles. + /// + public abstract Func, TDirection> MovementCalculation { get; set; } + + /// + public bool UpdateActive { + get => timer.Active || _continuesInterval.Active; + set { return; } + } + + /// + public void Update(UpdateContext context) + { + Stopwatch stp = new Stopwatch(); + stp.Start(); + for (int i = 0; i < instances.Count; i++) + { + instances[i].Lifetime -= context.Deltatime; + if (instances[i].Lifetime <= 0) + { + instances.Remove(instances[i]); + break; + } + + instances[i].ModelMatrix = CreateMatrix(instances[i], MovementCalculation(instances[i])); + } + + Console.WriteLine(); + } + + /// + /// Triggers the particles. + /// + public void Trigger() + { + instances = new List>(); + if (_continuesIntervalSeconds.HasValue) + { + _continuesInterval.Target = _continuesIntervalSeconds.Value; + _continuesInterval.Start(); + + return; + } + + timer.Start(); + + CreateParticles(); + } + + /// + /// Stops the particles. + /// + public void Stop() + { + if (_continuesInterval.Active) + { + _continuesInterval.Stop(); + } + + timer.Stop(); + } + + /// + public override void OnRemoved(object sender) + { + base.OnRemoved(sender); + + Stop(); + } + + /// + protected override void DrawContext(ref DrawContext context) + { + if (!timer.Active && _continuesInterval != null && !_continuesInterval.Active) return; + + base.DrawContext(ref context); + + if (DetachedParticles) context.ModelMatrix = Matrix4.Identity; + + context.Instances = instances.ConvertAll(a => (Instance)a); + + Material.Draw(context); + } + + /// + /// Creates the particles. + /// + protected virtual void CreateParticles() + { + + + for (int i = 0; i < Amount; i++) + { + instances.Add(CreateObject(i)); + } + } + + private void CreateContinuesParticles(Timer arg1, UpdateContext arg2) + { + instances.Add(CreateObject(0)); + } + + /// + /// Creates a particle. + /// + protected abstract ParticleInstance CreateObject(int index); + + /// + /// Generates the desired matrix for drawing. + /// + protected abstract Matrix4 CreateMatrix(ParticleInstance Struct, TDirection relativePosition); + } +} \ No newline at end of file diff --git a/src/renderer/SM.Base/Drawing/Particles/ParticleInstance.cs b/src/renderer/SM.Base/Drawing/Particles/ParticleInstance.cs new file mode 100644 index 0000000..9b94926 --- /dev/null +++ b/src/renderer/SM.Base/Drawing/Particles/ParticleInstance.cs @@ -0,0 +1,40 @@ +using OpenTK; + +namespace SM.Base.Drawing.Particles +{ + /// + /// This describes a instance of a particle + /// + public class ParticleInstance : Instance + { + /// + /// The lifetime the particle started with. + /// + public float StartLifetime = 0; + + /// + /// The lifetime this particular particle still has. + /// + public float Lifetime = 0; + + /// + /// A additional matrix to store rotation and scale. + /// + public Matrix4 Matrix; + + /// + /// Speeeeeeeeeed + /// + public float Speed; + } + + /// + public class ParticleInstance : ParticleInstance + where TValue : struct + { + /// + /// A direction, that the particle should travel. + /// + public TValue Direction; + } +} \ No newline at end of file diff --git a/SMCode/SM.Base/Drawing/Particles/ParticleMovement.cs b/src/renderer/SM.Base/Drawing/Particles/ParticleMovement.cs similarity index 54% rename from SMCode/SM.Base/Drawing/Particles/ParticleMovement.cs rename to src/renderer/SM.Base/Drawing/Particles/ParticleMovement.cs index 6fdad6a..cccd773 100644 --- a/SMCode/SM.Base/Drawing/Particles/ParticleMovement.cs +++ b/src/renderer/SM.Base/Drawing/Particles/ParticleMovement.cs @@ -14,17 +14,17 @@ namespace SM.Base.Drawing.Particles /// /// Default movement for 2D. /// - public static Vector2 Default2D(Vector2 direction, ParticleContext context) + public static Vector2 Default2D(ParticleInstance particle) { - return direction * (context.Timer.Elapsed * context.Speed); + return particle.Direction * ((particle.StartLifetime - particle.Lifetime) * particle.Speed); } /// /// Default movement for 3D. /// - public static Vector3 Default3D(Vector3 direction, ParticleContext context) + public static Vector3 Default3D(ParticleInstance particle) { - return direction * (context.Timer.Elapsed * context.Speed); + return particle.Direction * ((particle.StartLifetime - particle.Lifetime) * particle.Speed); } } } \ No newline at end of file diff --git a/SMCode/SM.Base/Drawing/ShaderArguments.cs b/src/renderer/SM.Base/Drawing/ShaderArguments.cs similarity index 100% rename from SMCode/SM.Base/Drawing/ShaderArguments.cs rename to src/renderer/SM.Base/Drawing/ShaderArguments.cs diff --git a/SMCode/SM.Base/Drawing/Text/CharParameter.cs b/src/renderer/SM.Base/Drawing/Text/CharParameter.cs similarity index 100% rename from SMCode/SM.Base/Drawing/Text/CharParameter.cs rename to src/renderer/SM.Base/Drawing/Text/CharParameter.cs diff --git a/SMCode/SM.Base/Drawing/Text/Font.cs b/src/renderer/SM.Base/Drawing/Text/Font.cs similarity index 89% rename from SMCode/SM.Base/Drawing/Text/Font.cs rename to src/renderer/SM.Base/Drawing/Text/Font.cs index f9c9667..102046a 100644 --- a/SMCode/SM.Base/Drawing/Text/Font.cs +++ b/src/renderer/SM.Base/Drawing/Text/Font.cs @@ -40,6 +40,12 @@ namespace SM.Base.Drawing.Text /// public float FontSize { get; set; } = 12; + /// + /// Allows to adjust the baseline to fix clipping issues. + /// Due to some issues with the calculations, this is a temporary fix. + /// + public float BaselineAdjust { get; set; } = 1f; + /// /// The character positions. /// @@ -64,6 +70,8 @@ namespace SM.Base.Drawing.Text public void RegenerateTexture() { Width = Height = 0; + + //Height = Math.Abs(_fontFace.BBox.Bottom) + _fontFace.BBox.Top; Positions = new Dictionary(); _fontFace.SetCharSize(0, FontSize, 0, 96); @@ -83,7 +91,7 @@ namespace SM.Base.Drawing.Text float bBoxHeight = (Math.Abs(_fontFace.BBox.Bottom) + _fontFace.BBox.Top); float bBoxTopScale = _fontFace.BBox.Top / bBoxHeight; - float baseline = Height * bBoxTopScale + 1; + float baseline = (Height * bBoxTopScale) + BaselineAdjust; Map = new Bitmap(Width, Height); using (Graphics g = Graphics.FromImage(Map)) @@ -95,8 +103,7 @@ namespace SM.Base.Drawing.Text { _fontFace.LoadChar(keyvalue.Key, LoadFlags.Render, LoadTarget.Normal); - int y = ((int)baseline - (int)_fontFace.Glyph.Metrics.HorizontalBearingY); - + int y = ((int)baseline - (int) _fontFace.Glyph.Metrics.HorizontalBearingY); g.DrawImageUnscaled(_fontFace.Glyph.Bitmap.ToGdipBitmap(Color.White), (int)keyvalue.Value[1], y); Vector2 offset = new Vector2(keyvalue.Value[1] / Width, 0); diff --git a/SMCode/SM.Base/Drawing/Text/FontCharStorage.cs b/src/renderer/SM.Base/Drawing/Text/FontCharStorage.cs similarity index 100% rename from SMCode/SM.Base/Drawing/Text/FontCharStorage.cs rename to src/renderer/SM.Base/Drawing/Text/FontCharStorage.cs diff --git a/SMCode/SM.Base/Drawing/Text/TextDrawingBasis.cs b/src/renderer/SM.Base/Drawing/Text/TextDrawingBasis.cs similarity index 76% rename from SMCode/SM.Base/Drawing/Text/TextDrawingBasis.cs rename to src/renderer/SM.Base/Drawing/Text/TextDrawingBasis.cs index 206a63c..9879639 100644 --- a/SMCode/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/SMCode/SM.Base/Drawing/TextureTransformation.cs b/src/renderer/SM.Base/Drawing/TextureTransformation.cs similarity index 100% rename from SMCode/SM.Base/Drawing/TextureTransformation.cs rename to src/renderer/SM.Base/Drawing/TextureTransformation.cs diff --git a/SMCode/SM.Base/PostEffects/BloomEffect.cs b/src/renderer/SM.Base/Legacy/PostProcessing/BloomEffectOld.cs similarity index 66% rename from SMCode/SM.Base/PostEffects/BloomEffect.cs rename to src/renderer/SM.Base/Legacy/PostProcessing/BloomEffectOld.cs index 9b3d279..4a7366c 100644 --- a/SMCode/SM.Base/PostEffects/BloomEffect.cs +++ b/src/renderer/SM.Base/Legacy/PostProcessing/BloomEffectOld.cs @@ -1,5 +1,7 @@ #region usings +using System; +using System.Drawing; using OpenTK; using OpenTK.Graphics.OpenGL4; using SM.Base.Drawing; @@ -7,28 +9,31 @@ 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.PostEffects +namespace SM.Base.Legacy.PostProcessing { /// /// A bloom post process effect. /// - public class BloomEffect : PostProcessEffect + [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( - AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom_merge_vert.glsl"), - AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom_merge.glsl")); + 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(SMRenderer.PostProcessPath + ".bloom_blur.glsl")); + 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; @@ -83,12 +88,6 @@ namespace SM.Base.PostEffects /// public float Radius = 1; - /// - /// This can disable the bloom calculation. - /// Default: true - /// - public bool Enable = true; - /// /// This defines the weight curve. /// @@ -101,6 +100,7 @@ namespace SM.Base.PostEffects UpdateWeights(); } } + /// /// This defines how many picks the effect should pick from the weight curve. /// @@ -112,7 +112,7 @@ namespace SM.Base.PostEffects /// 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 BloomEffectOld(Framebuffer source = null, bool hdr = false, float? textureScale = null) { _source = source; _hdr = hdr; @@ -137,6 +137,10 @@ namespace SM.Base.PostEffects _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" @@ -150,61 +154,62 @@ namespace SM.Base.PostEffects _bloomBuffer2.Append("yBuffer", _yBuffer = new ColorAttachment(0, PixelInformation.RGBA_HDR)); _bloomBuffer2.Compile(); + Pipeline.Framebuffers.Add(_tempColorBuffer); Pipeline.Framebuffers.Add(_bloomBuffer1); Pipeline.Framebuffers.Add(_bloomBuffer2); } /// - public override void Draw(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(); + + source.ConnectedFramebuffer.CopyTo(_tempColorBuffer); + + bool first = true, hoz = true; + int iter = Iterations * 2; + for (int i = 0; i < iter; i++) { - GL.Viewport(0, 0, (int) (Pipeline.ConnectedWindow.Width * _textureScale), - (int) (Pipeline.ConnectedWindow.Height * _textureScale)); + (hoz ? _bloomBuffer1 : _bloomBuffer2).Activate(false); - Framebuffer target = Framebuffer.GetCurrentlyActive(); - bool first = true, hoz = true; - int iter = Iterations * 2; - for (int i = 0; i < iter; i++) + _shader.Draw(collection => { - (hoz ? _bloomBuffer1 : _bloomBuffer2).Activate(false); + collection["renderedTexture"].SetTexture(first ? source : (hoz ? _yBuffer : _xBuffer)); - _shader.Draw(collection => - { - collection["renderedTexture"].SetTexture(first ? _source.ColorAttachments["color"] : (hoz ? _yBuffer : _xBuffer)); + collection["First"].SetBool(first); + collection["Threshold"].SetFloat(Threshold); - collection["First"].SetUniform1(first); - collection["Threshold"].SetUniform1(Threshold); + collection["Horizontal"].SetBool(hoz); - collection["Horizontal"].SetUniform1(hoz); + collection["Weights"].SetFloat(_weights); + collection["WeightCount"].SetFloat(WeightCurvePickAmount); + collection["Power"].SetFloat(Power); - collection["Weights"].SetUniform1(_weights); - collection["WeightCount"].SetUniform1(WeightCurvePickAmount); - collection["Power"].SetUniform1(Power); + collection["Radius"].SetFloat(_textureScale * Radius); + }); - collection["Radius"].SetUniform1(_textureScale * Radius); - }); - - hoz = !hoz; - if (first) first = false; - } - - GL.Viewport(Pipeline.ConnectedWindow.ClientRectangle); - target.Activate(); + hoz = !hoz; + if (first) first = false; } + GL.Viewport(Pipeline.ConnectedWindow.ClientRectangle); + target.Activate(); + _mergeShader.Draw(collection => { - collection["Scene"].SetTexture(_source.ColorAttachments["color"]); + collection["Scene"].SetTexture(_tempColorBuffer["color"]); collection["Bloom"].SetTexture(_yBuffer); - collection["MinAmount"].SetUniform1(MinAmount); - collection["MaxAmount"].SetUniform1(MaxAmount); + collection["MinAmount"].SetFloat(MinAmount); + collection["MaxAmount"].SetFloat(MaxAmount); collection["AmountMap"].SetTexture(AmountMap, collection["HasAmountMap"]); collection["TextureTransform"].SetMatrix3(AmountTransform.GetMatrix()); - collection["Exposure"].SetUniform1(context.UseCamera.Exposure); - collection["HDR"].SetUniform1(_hdr); + collection["Exposure"].SetFloat(context.UseCamera.Exposure); + collection["HDR"].SetBool(_hdr); }); } } diff --git a/SMCode/SM.Base/PostEffects/Shaders/bloom_blur.glsl b/src/renderer/SM.Base/Legacy/PostProcessing/bloom_blur.glsl similarity index 92% rename from SMCode/SM.Base/PostEffects/Shaders/bloom_blur.glsl rename to src/renderer/SM.Base/Legacy/PostProcessing/bloom_blur.glsl index 834ad23..c6bb97a 100644 --- a/SMCode/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/SMCode/SM.Base/PostEffects/Shaders/bloom_merge.glsl b/src/renderer/SM.Base/Legacy/PostProcessing/bloom_merge.glsl similarity index 79% rename from SMCode/SM.Base/PostEffects/Shaders/bloom_merge.glsl rename to src/renderer/SM.Base/Legacy/PostProcessing/bloom_merge.glsl index cef9313..77a8937 100644 --- a/SMCode/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/SMCode/SM.Base/PostEffects/Shaders/bloom_merge_vert.glsl b/src/renderer/SM.Base/Legacy/PostProcessing/bloom_merge.vert similarity index 55% rename from SMCode/SM.Base/PostEffects/Shaders/bloom_merge_vert.glsl rename to src/renderer/SM.Base/Legacy/PostProcessing/bloom_merge.vert index 127a8b5..4d20506 100644 --- a/SMCode/SM.Base/PostEffects/Shaders/bloom_merge_vert.glsl +++ b/src/renderer/SM.Base/Legacy/PostProcessing/bloom_merge.vert @@ -1,11 +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 vertex() { + +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/SMCode/SM.Base/Log.cs b/src/renderer/SM.Base/Log.cs similarity index 93% rename from SMCode/SM.Base/Log.cs rename to src/renderer/SM.Base/Log.cs index 8477937..176a85c 100644 --- a/SMCode/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/SMCode/SM.Base/Objects/InstancedMesh.cs b/src/renderer/SM.Base/Objects/InstancedMesh.cs similarity index 100% rename from SMCode/SM.Base/Objects/InstancedMesh.cs rename to src/renderer/SM.Base/Objects/InstancedMesh.cs diff --git a/SMCode/SM.Base/Objects/Mesh.cs b/src/renderer/SM.Base/Objects/Mesh.cs similarity index 100% rename from SMCode/SM.Base/Objects/Mesh.cs rename to src/renderer/SM.Base/Objects/Mesh.cs diff --git a/SMCode/SM.Base/Objects/Static/AxisHelper.cs b/src/renderer/SM.Base/Objects/Static/AxisHelper.cs similarity index 100% rename from SMCode/SM.Base/Objects/Static/AxisHelper.cs rename to src/renderer/SM.Base/Objects/Static/AxisHelper.cs diff --git a/SMCode/SM.Base/Objects/Static/Plate.cs b/src/renderer/SM.Base/Objects/Static/Plate.cs similarity index 100% rename from SMCode/SM.Base/Objects/Static/Plate.cs rename to src/renderer/SM.Base/Objects/Static/Plate.cs diff --git a/SMOptionals/SM.Game/OpenTK.dll.config b/src/renderer/SM.Base/OpenTK.dll.config similarity index 100% rename from SMOptionals/SM.Game/OpenTK.dll.config rename to src/renderer/SM.Base/OpenTK.dll.config diff --git a/src/renderer/SM.Base/PostEffects/BloomEffect.cs b/src/renderer/SM.Base/PostEffects/BloomEffect.cs new file mode 100644 index 0000000..0a75569 --- /dev/null +++ b/src/renderer/SM.Base/PostEffects/BloomEffect.cs @@ -0,0 +1,270 @@ +using OpenTK; +using OpenTK.Graphics; +using OpenTK.Graphics.OpenGL4; +using SM.Base.Drawing; +using SM.Base.PostProcess; +using SM.Base.Types; +using SM.Base.Utility; +using SM.Base.Window; +using SM.OGL.Framebuffer; +using SM.OGL.Shaders; +using SM.OGL.Texture; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SM.Base.PostEffects +{ + enum BloomEffectShaderType + { + Filtering, + Downsampling, + Upsampling, + Combine + } + + /// + /// 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 : PostProcess.PostProcessEffect + { + private static readonly ShaderFile samplingFile = new ShaderFile(AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom.sampling.frag")); + + 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( + new ShaderFile(AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom.combine.vert")), + AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom.combine.frag") + ); + + static BloomEffect() + { + _upsampleShader.ShaderFiles.Fragment[0].GLSLExtensions.Add(samplingFile); + _combineShader.ShaderFiles.Fragment[0].GLSLExtensions.Add(samplingFile); + } + + /* + private static readonly string bloomFile = AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom.frag"); + private static readonly ShaderFile combineVertex = new ShaderFile(AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom.combine.vert")); + + static Dictionary _ppShaders = new Dictionary(2); + + static PostProcessShader[] GetShaders(bool high) + { + if (_ppShaders.ContainsKey(high)) return _ppShaders[high]; + + PostProcessShader[] shaders; + _ppShaders.Add(high, shaders = new PostProcessShader[4]); + + for(int i = 0; i < 4; i++) + { + ShaderFile file = new ShaderFile(bloomFile) + { + Defines = + { + "ACTION_"+((BloomEffectShaderType)i).ToString().ToUpper(), + } + }; + if (high) file.Defines.Add("HIGH"); + + PostProcessShader shader; + if (i == 3) shader = new PostProcessShader(vertex: combineVertex, file); + else shader = new PostProcessShader(file); + + shaders[i] = shader; + } + + return shaders; + }*/ + + const int MAXBLOOMSTEPS = 8; + const float INTENSITY = .1f; + + private readonly bool _hdr; + + private List _downsampler; + private List _upsample; + private PostProcessShader[] shaders; + + private int _iterations; + private float _sampleSize; + private Vector4 _thresholdCurve; + private Color4 _bloomColor; + + /// + /// The threshold, where the effect decided what is bright. + /// + public float Threshold = .8f; + /// + /// The radius of the effect. + /// + 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; + + /// + /// An amount map specifices where the bloom effect should be visible. + /// Reads only in the "R"-channel. + /// + public TextureBase AmountMap; + /// + /// Allows you to transform the texture coordnates for + /// + public TextureTransformation AmountMapTransform = new TextureTransformation(); + /// + /// Specifices limits, how the is read. + /// Default: + /// + public MinMax AmountLimits = MinMax.Default; + + /// + /// This creates a more prettier bloom effect. + /// + /// This allows to enable hdr returns. + /// If set true, it will use the high quality settings. + public BloomEffect(bool hdr = false, bool highSetting = true) + { + _hdr = hdr; + //shaders = GetShaders(highSetting); + shaders = new[] { _filterShader, _downsampleShader, _upsampleShader, _combineShader }; + } + /// + protected override void InitProcess() => CreateFramebuffers(); + + private void CreateFramebuffers() + { + if (_downsampler != null) _downsampler.ForEach(a => a.Reset()); + if (_upsample != null) _upsample.ForEach(a => a.Reset()); + + _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); + } + } + + /// + public override void ScreenSizeChanged(IGenericWindow window) + { + CreateFramebuffers(); + } + + /// + protected override void Drawing(ColorAttachment source, DrawContext context) + { + Framebuffer target = Framebuffer.GetCurrentlyActive(); + + // Filtering + _downsampler[0].Activate(true); + shaders[0].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); + shaders[1].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); + + shaders[2].Draw(last, (a) => + { + if (last != null) a["baseBuffer"].SetTexture(downsampleSource); + a["sampleSize"].SetFloat(_sampleSize); + }); + + last = upsampleTarget["0"]; + } + + // combine + target.Activate(true); + shaders[3].Draw(last, (a) => + { + a["sampleSize"].SetFloat(_sampleSize); + + a["scene"].SetTexture(_downsampler[0]["1"]); + a["bloomColor"].SetColor(_bloomColor); + + if (AmountMap != null) + { + a["amountTransform"].SetMatrix3(AmountMapTransform.GetMatrix()); + a["amountMap"].SetTexture(AmountMap, a["hasAmountMap"]); + a["amountLimit"].SetVector2((Vector2)AmountLimits); + + } + + a["HDR"].SetBool(_hdr); + }); + } + } +} diff --git a/SMCode/SM.Base/PostEffects/PostProcessUtility.cs b/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs similarity index 61% rename from SMCode/SM.Base/PostEffects/PostProcessUtility.cs rename to src/renderer/SM.Base/PostEffects/PostProcessUtility.cs index 55bef36..0d77ac4 100644 --- a/SMCode/SM.Base/PostEffects/PostProcessUtility.cs +++ b/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs @@ -4,18 +4,34 @@ using OpenTK.Graphics.OpenGL4; using SM.Base.PostProcess; using SM.Base.Utility; using SM.OGL.Framebuffer; +using SM.OGL.Shaders; +using System.Collections.Generic; #endregion namespace SM.Base.PostEffects { + public enum HDRColorCurve + { + OnlyExposure, + Reinhard, + ACES + } + /// /// This class has some utility for render pipelines /// public static class PostProcessUtility { - private static readonly PostProcessShader _hdrExposureShader = - new PostProcessShader(AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".finalize_hdr.glsl")); + public static readonly ShaderFile HDRCurves = new ShaderFile(AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".hdr_curves.frag")); + private static readonly string _finalizeHdrCode = AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".finalize_hdr.glsl"); + + private static readonly Dictionary _hdrExposureShader = new Dictionary() + { + { HDRColorCurve.OnlyExposure, new PostProcessShader(new ShaderFile(_finalizeHdrCode) {GLSLExtensions = { HDRCurves } }) }, + { HDRColorCurve.Reinhard, new PostProcessShader(new ShaderFile(_finalizeHdrCode) { GLSLExtensions = { HDRCurves }, Defines = { "TYPE_REINHARD" } }) }, + { HDRColorCurve.ACES, new PostProcessShader(new ShaderFile(_finalizeHdrCode) { GLSLExtensions = { HDRCurves }, Defines = { "TYPE_ACES" } }) }, + }; private static readonly PostProcessShader _gammaShader = new PostProcessShader( @@ -38,7 +54,7 @@ namespace SM.Base.PostEffects target.Activate(FramebufferTarget.DrawFramebuffer); GL.BlitFramebuffer(0, 0, (int) multisampledBuffers.Size.X, (int) multisampledBuffers.Size.Y, 0, 0, (int) target.Size.X, (int) target.Size.Y, ClearBufferMask.ColorBufferBit, - BlitFramebufferFilter.Nearest); + BlitFramebufferFilter.Linear); target.Activate(); } @@ -48,12 +64,12 @@ namespace SM.Base.PostEffects /// /// /// - public static void FinalizeHDR(ColorAttachment attachment, float exposure) + public static void FinalizeHDR(ColorAttachment attachment, HDRColorCurve colorCurve = HDRColorCurve.ACES, float exposure = 1) { - _hdrExposureShader.Draw(u => + _hdrExposureShader[colorCurve].Draw(u => { - u["Gamma"].SetUniform1(Gamma); - u["Exposure"].SetUniform1(exposure); + u["Gamma"].SetFloat(Gamma); + u["Exposure"].SetFloat(exposure); u["Scene"].SetTexture(attachment); }); } @@ -66,7 +82,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.frag b/src/renderer/SM.Base/PostEffects/Shaders/bloom.frag new file mode 100644 index 0000000..2401377 --- /dev/null +++ b/src/renderer/SM.Base/PostEffects/Shaders/bloom.frag @@ -0,0 +1,188 @@ +#version 330 core +/* ACTIONS: +0 = Filtering +1 = Downsamping +2 = Upsampling +3 = Combine +*/ + +in vec2 vTexture; + +uniform vec2 renderedTextureTexelSize; +// Uniforms +uniform vec4 ThresholdCurve; + + +// Downsampling + +uniform float sampleSize; +uniform sampler2D baseBuffer; + +in vec2 amountUV; + +uniform sampler2D scene; +uniform vec4 bloomColor; +uniform bool HDR; + +uniform bool hasAmountMap; +uniform sampler2D amountMap; +uniform vec2 amountLimit; + + +layout(location = 0) out vec4 color; +layout(location = 1) out vec4 sceneOutput; + +vec4 GetRenderColorOffset(vec2); +vec3 reinhardTone(vec3); + +// ---- Utils ---- +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; +} + +// ---- Functions ---- +vec3 simpleBoxFilter() { + #if defined (ACTION_DOWNSAMPLING) + vec4 d = renderedTextureTexelSize.xyxy * vec4(-1,-1,1,1); + #else + vec4 d = renderedTextureTexelSize.xyxy * vec4(-1,-1,1,1) * (sampleSize * 0.5); + #endif + + vec3 s; + s = GetRenderColorOffset(d.xy).rgb; + s += GetRenderColorOffset(d.zy).rgb; + s += GetRenderColorOffset(d.xw).rgb; + s += GetRenderColorOffset(d.zw).rgb; + + return s * 0.25; // 1 / 4 = 0.25 +} + +// Downsampling: +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; +} + +// Upsampling: +vec3 upsample_high() { + vec4 d = renderedTextureTexelSize.xyxy * vec4(1, 1,-1,0) * sampleSize; + + 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 texture2D(baseBuffer, vTexture).rgb + s * 0.0625; // 1 / 16 = 0.0625 +} + +// ---- Actions ---- +vec3 filtering() { + + + vec3 col = safe_color(GetRenderColorOffset(vec2(0)).rgb); + sceneOutput = vec4(col, 1); + return sceneOutput.rgb; + + #ifdef HIGH + vec3 d = renderedTextureTexelSize.xyx * vec3(1,1,0); + vec3 s0 = col + 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); + #endif + + 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); + return col * resultBr; +} + +vec3 downsample() { + #ifdef HIGH + return downsample_high(); + #else + return simpleBoxFilter(); + #endif +} + +vec3 upsample() { + #ifdef HIGH + return upsample_high(); + #else + return simpleBoxFilter(); + #endif +} + +vec3 combine() { + vec3 scene = safe_color(texture2D(scene, vTexture).rgb); + vec3 blur = upsample() * bloomColor.rgb; + + if (hasAmountMap) { + blur *= clamp(texture2D(amountMap, amountUV).r * (amountLimit.y - amountLimit.x) + amountLimit.x, 0, 1); + } + + if (HDR) { + return scene + blur; + } + + return scene + reinhardTone(blur); +} + +// main: +void main() { + vec3 col; + + #if defined(ACTION_FILTERING) + col = filtering(); + #elif defined(ACTION_DOWNSAMPLING) + col = downsample(); + #elif defined(ACTION_UPSAMPLING) + col = upsample(); + #else + col = combine(); + #endif + + color = vec4(col, 1); +} 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..2c67f8b --- /dev/null +++ b/src/renderer/SM.Base/PostEffects/Shaders/bloom/combine.frag @@ -0,0 +1,41 @@ +#version 330 core + +in vec2 vTexture; +in vec2 amountUV; + +uniform sampler2D scene; +uniform vec4 bloomColor; +uniform bool HDR; + +uniform bool hasAmountMap; +uniform sampler2D amountMap; +uniform vec2 amountLimit; + +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 (hasAmountMap) { + blur *= clamp(texture2D(amountMap, amountUV).r * (amountLimit.y - amountLimit.x) + amountLimit.x, 0, 1); + } + + if (HDR) { + color = vec4(scene + blur, 1); + return; + } + + color = vec4(scene + reinhardTone(blur), 1); +} diff --git a/src/renderer/SM.Base/PostEffects/Shaders/bloom/combine.vert b/src/renderer/SM.Base/PostEffects/Shaders/bloom/combine.vert new file mode 100644 index 0000000..1a92d4c --- /dev/null +++ b/src/renderer/SM.Base/PostEffects/Shaders/bloom/combine.vert @@ -0,0 +1,17 @@ +#version 330 + +layout(location = 0) in vec3 aPos; +layout(location = 1) in vec2 aTex; + +uniform mat4 MVP; +uniform mat3 amountTransform; + +out vec2 vTexture; +out vec2 amountUV; + +void main() { + vTexture = aTex; + amountUV = vec2(amountTransform * vec3(aTex, 1)); + + gl_Position = MVP * vec4(aPos, 1); +} \ No newline at end of file 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..c0c5178 --- /dev/null +++ b/src/renderer/SM.Base/PostEffects/Shaders/bloom/downsample.frag @@ -0,0 +1,40 @@ +#version 330 core + +uniform vec2 renderedTextureTexelSize; + +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..9f08e3d --- /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) * sampleSize; + + 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/SMCode/SM.Base/PostEffects/Shaders/finalize_gamma.glsl b/src/renderer/SM.Base/PostEffects/Shaders/finalize_gamma.glsl similarity index 100% rename from SMCode/SM.Base/PostEffects/Shaders/finalize_gamma.glsl rename to src/renderer/SM.Base/PostEffects/Shaders/finalize_gamma.glsl diff --git a/src/renderer/SM.Base/PostEffects/Shaders/finalize_hdr.glsl b/src/renderer/SM.Base/PostEffects/Shaders/finalize_hdr.glsl new file mode 100644 index 0000000..eeacf82 --- /dev/null +++ b/src/renderer/SM.Base/PostEffects/Shaders/finalize_hdr.glsl @@ -0,0 +1,28 @@ +#version 330 + +in vec2 vTexture; + +uniform sampler2D Scene; +uniform float Exposure; +uniform float Gamma; + +layout(location = 0) out vec4 color; + +vec3 ACES(vec3); + +vec3 reinhardTone(vec3); + +vec3 exposure(vec3); + +void main() { + + vec3 scene = texture2D(Scene, vTexture).rgb; + vec3 result = exposure(scene); + #if defined(TYPE_REINHARD) + result = reinhardTone(result); + #elif defined(TYPE_ACES) + result = ACES(result); + #endif + + color = vec4(pow(result, vec3(1 / Gamma)), 1); +} \ No newline at end of file diff --git a/src/renderer/SM.Base/PostEffects/Shaders/hdr_curves.frag b/src/renderer/SM.Base/PostEffects/Shaders/hdr_curves.frag new file mode 100644 index 0000000..6ec0e52 --- /dev/null +++ b/src/renderer/SM.Base/PostEffects/Shaders/hdr_curves.frag @@ -0,0 +1,21 @@ +#version 330 core + +uniform float Exposure; + +vec3 ACES(vec3 col) { + 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((col * (a * col + b)) / (col * (c * col + d) + e), 0.0,1.0); +} + +vec3 reinhardTone(vec3 col) { + return col / (col + vec3(1.0)); +} + +vec3 exposure(vec3 col) { + return vec3(1) - exp(-col * Exposure); +} \ No newline at end of file diff --git a/SMCode/SM.Base/PostProcess/DefaultFiles/extensions.frag b/src/renderer/SM.Base/PostProcess/DefaultFiles/extensions.frag similarity index 100% rename from SMCode/SM.Base/PostProcess/DefaultFiles/extensions.frag rename to src/renderer/SM.Base/PostProcess/DefaultFiles/extensions.frag diff --git a/SMCode/SM.Base/PostProcess/DefaultFiles/vertexFile.vert b/src/renderer/SM.Base/PostProcess/DefaultFiles/vertexFile.vert similarity index 100% rename from SMCode/SM.Base/PostProcess/DefaultFiles/vertexFile.vert rename to src/renderer/SM.Base/PostProcess/DefaultFiles/vertexFile.vert diff --git a/SMCode/SM.Base/PostProcess/DefaultFiles/vertexWithExt.vert b/src/renderer/SM.Base/PostProcess/DefaultFiles/vertexWithExt.vert similarity index 100% rename from SMCode/SM.Base/PostProcess/DefaultFiles/vertexWithExt.vert rename to src/renderer/SM.Base/PostProcess/DefaultFiles/vertexWithExt.vert diff --git a/SMCode/SM.Base/PostProcess/PostProcessEffect.cs b/src/renderer/SM.Base/PostProcess/PostProcessEffect.cs similarity index 61% rename from SMCode/SM.Base/PostProcess/PostProcessEffect.cs rename to src/renderer/SM.Base/PostProcess/PostProcessEffect.cs index 5a522cb..d60d22b 100644 --- a/SMCode/SM.Base/PostProcess/PostProcessEffect.cs +++ b/src/renderer/SM.Base/PostProcess/PostProcessEffect.cs @@ -3,6 +3,7 @@ using OpenTK; using SM.Base.Scene; using SM.Base.Window; +using SM.OGL.Framebuffer; #endregion @@ -23,6 +24,12 @@ namespace SM.Base.PostProcess /// protected RenderPipeline Pipeline; + /// + /// Enables the effect. + /// Default: true + /// + public bool Enable = true; + /// /// Initialize the effect. /// @@ -40,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(DrawContext context); + protected abstract void Drawing(ColorAttachment source, DrawContext context); /// /// Event, when the scene changed. @@ -52,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 new file mode 100644 index 0000000..b1a4744 --- /dev/null +++ b/src/renderer/SM.Base/PostProcess/PostProcessShader.cs @@ -0,0 +1,130 @@ +#region usings + +using System; +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 + +namespace SM.Base.PostProcess +{ + /// + /// Specific shader for post processing. + /// + public class PostProcessShader : GenericShader + { + private static readonly ShaderFile _fragExtensions = + new ShaderFile(AssemblyUtility.ReadAssemblyFile("SM.Base.PostProcess.DefaultFiles.extensions.frag")); + + private static readonly ShaderFile _normalVertex = + new ShaderFile(AssemblyUtility.ReadAssemblyFile("SM.Base.PostProcess.DefaultFiles.vertexFile.vert")); + + 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. + /// + public PostProcessShader(string fragment) : this(_normalVertex, new ShaderFile(fragment)) + { + } + /// + /// Creates the shader with the default vertex shader and custom fragment shader. + /// + public PostProcessShader(ShaderFile fragment) : this(_normalVertex, fragment) + { + } + + /// + /// Creates the shader with an vertex extension and custom fragment. + /// + /// + /// + public PostProcessShader(string vertexExt, string fragment) : this(new ShaderFile(_normalVertexWithExt) + { + GLSLExtensions = new List {new ShaderFile(vertexExt)} + }, new ShaderFile(fragment)) + { + } + /// + /// Creates the shader with an vertex shader and custom fragment. + /// + /// + /// + public PostProcessShader(ShaderFile vertex, string fragment) : this(vertex, new ShaderFile(fragment)) + { + } + + /// + /// Creates the shader with an vertex shader and custom fragment. + /// + /// + /// + public PostProcessShader(ShaderFile vertex, ShaderFile fragment) : base( + new ShaderFileCollection(vertex, fragment)) + { + 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) + { + if (ErrorInShader) return; + + Activate(); + Plate.Object.Activate(); + + Uniforms["MVP"].SetMatrix4(PostProcessEffect.Mvp); + + setUniformAction(Uniforms); + + GL.DrawArrays(PrimitiveType.Quads, 0, 4); + + CleanUp(); + } + } +} \ No newline at end of file diff --git a/SMCode/SM.Base/Properties/AssemblyInfo.cs b/src/renderer/SM.Base/Properties/AssemblyInfo.cs similarity index 100% rename from SMCode/SM.Base/Properties/AssemblyInfo.cs rename to src/renderer/SM.Base/Properties/AssemblyInfo.cs diff --git a/SMCode/SM.Base/SM.Base.csproj b/src/renderer/SM.Base/SM.Base.csproj similarity index 79% rename from SMCode/SM.Base/SM.Base.csproj rename to src/renderer/SM.Base/SM.Base.csproj index 5e201f9..2f713e0 100644 --- a/SMCode/SM.Base/SM.Base.csproj +++ b/src/renderer/SM.Base/SM.Base.csproj @@ -1,5 +1,7 @@  + + @@ -16,6 +18,7 @@ true + true @@ -37,23 +40,6 @@ 4 latest - - - ..\..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll - - - - ..\..\..\IAmTwo - Kopie\packages\SharpFont.4.0.1\lib\net45\SharpFont.dll - - - - - - - - - - @@ -62,21 +48,23 @@ + + - - + + @@ -87,7 +75,7 @@ - + @@ -127,25 +115,16 @@ - - - {f604d684-bc1d-4819-88b5-8b5d03a17be0} - SM.OGL - - - - + + - - - @@ -154,12 +133,50 @@ + + + {f604d684-bc1d-4819-88b5-8b5d03a17be0} + SM.OGL + + + + + ..\..\..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll + + + ..\..\..\packages\SharpFont.4.0.1\lib\net45\SharpFont.dll + True + + + + + + + + + + + + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - \ No newline at end of file diff --git a/SMCode/SM.Base/SM.Base.csproj.DotSettings b/src/renderer/SM.Base/SM.Base.csproj.DotSettings similarity index 100% rename from SMCode/SM.Base/SM.Base.csproj.DotSettings rename to src/renderer/SM.Base/SM.Base.csproj.DotSettings diff --git a/SMCode/SM.Base/SMRenderer.cs b/src/renderer/SM.Base/SMRenderer.cs similarity index 100% rename from SMCode/SM.Base/SMRenderer.cs rename to src/renderer/SM.Base/SMRenderer.cs diff --git a/SMCode/SM.Base/Scene/GenericCamera.cs b/src/renderer/SM.Base/Scene/GenericCamera.cs similarity index 100% rename from SMCode/SM.Base/Scene/GenericCamera.cs rename to src/renderer/SM.Base/Scene/GenericCamera.cs diff --git a/SMCode/SM.Base/Scene/GenericItemCollection.cs b/src/renderer/SM.Base/Scene/GenericItemCollection.cs similarity index 100% rename from SMCode/SM.Base/Scene/GenericItemCollection.cs rename to src/renderer/SM.Base/Scene/GenericItemCollection.cs diff --git a/SMCode/SM.Base/Scene/GenericScene.cs b/src/renderer/SM.Base/Scene/GenericScene.cs similarity index 100% rename from SMCode/SM.Base/Scene/GenericScene.cs rename to src/renderer/SM.Base/Scene/GenericScene.cs diff --git a/SMCode/SM.Base/Scene/IBackgroundItem.cs b/src/renderer/SM.Base/Scene/IBackgroundItem.cs similarity index 100% rename from SMCode/SM.Base/Scene/IBackgroundItem.cs rename to src/renderer/SM.Base/Scene/IBackgroundItem.cs diff --git a/SMCode/SM.Base/Scene/ICollectionItem.cs b/src/renderer/SM.Base/Scene/ICollectionItem.cs similarity index 100% rename from SMCode/SM.Base/Scene/ICollectionItem.cs rename to src/renderer/SM.Base/Scene/ICollectionItem.cs diff --git a/SMCode/SM.Base/Scene/IFixedScriptable.cs b/src/renderer/SM.Base/Scene/IFixedScriptable.cs similarity index 100% rename from SMCode/SM.Base/Scene/IFixedScriptable.cs rename to src/renderer/SM.Base/Scene/IFixedScriptable.cs diff --git a/SMCode/SM.Base/Scene/IScriptable.cs b/src/renderer/SM.Base/Scene/IScriptable.cs similarity index 100% rename from SMCode/SM.Base/Scene/IScriptable.cs rename to src/renderer/SM.Base/Scene/IScriptable.cs diff --git a/SMCode/SM.Base/Scene/IShowCollection.cs b/src/renderer/SM.Base/Scene/IShowCollection.cs similarity index 100% rename from SMCode/SM.Base/Scene/IShowCollection.cs rename to src/renderer/SM.Base/Scene/IShowCollection.cs diff --git a/SMCode/SM.Base/Scene/IShowItem.cs b/src/renderer/SM.Base/Scene/IShowItem.cs similarity index 100% rename from SMCode/SM.Base/Scene/IShowItem.cs rename to src/renderer/SM.Base/Scene/IShowItem.cs diff --git a/SMCode/SM.Base/Shaders/Extensions/ExtensionManager.cs b/src/renderer/SM.Base/Shaders/Extensions/ExtensionManager.cs similarity index 100% rename from SMCode/SM.Base/Shaders/Extensions/ExtensionManager.cs rename to src/renderer/SM.Base/Shaders/Extensions/ExtensionManager.cs diff --git a/SMCode/SM.Base/Shaders/Extensions/fragment/noise.glsl b/src/renderer/SM.Base/Shaders/Extensions/fragment/noise.glsl similarity index 100% rename from SMCode/SM.Base/Shaders/Extensions/fragment/noise.glsl rename to src/renderer/SM.Base/Shaders/Extensions/fragment/noise.glsl diff --git a/SMCode/SM.Base/Shaders/Extensions/fragment/textureGamma.glsl b/src/renderer/SM.Base/Shaders/Extensions/fragment/textureGamma.glsl similarity index 100% rename from SMCode/SM.Base/Shaders/Extensions/fragment/textureGamma.glsl rename to src/renderer/SM.Base/Shaders/Extensions/fragment/textureGamma.glsl diff --git a/SMCode/SM.Base/Shaders/Extensions/vertex/basic.vert b/src/renderer/SM.Base/Shaders/Extensions/vertex/basic.vert similarity index 100% rename from SMCode/SM.Base/Shaders/Extensions/vertex/basic.vert rename to src/renderer/SM.Base/Shaders/Extensions/vertex/basic.vert diff --git a/SMCode/SM.Base/Shaders/MaterialShader.cs b/src/renderer/SM.Base/Shaders/MaterialShader.cs similarity index 88% rename from SMCode/SM.Base/Shaders/MaterialShader.cs rename to src/renderer/SM.Base/Shaders/MaterialShader.cs index 470ad01..10c3387 100644 --- a/SMCode/SM.Base/Shaders/MaterialShader.cs +++ b/src/renderer/SM.Base/Shaders/MaterialShader.cs @@ -37,6 +37,7 @@ namespace SM.Base.Shaders /// The context public virtual void Draw(DrawContext context) { + if (ErrorInShader) return; context.Shader.Activate(); context.Mesh.Activate(); @@ -45,9 +46,7 @@ namespace SM.Base.Shaders { try { - if (context.Mesh is ILineMesh lineMesh) - GL.LineWidth(context.Material.ShaderArguments.Get("LineWidth", lineMesh.LineWidth)); - else if (context.Material.ShaderArguments.ContainsKey("LineWidth")) + if (context.Material.ShaderArguments.ContainsKey("LineWidth")) GL.LineWidth((float)context.Material.ShaderArguments["LineWidth"]); } catch diff --git a/SMCode/SM.Base/Shaders/SimpleShader.cs b/src/renderer/SM.Base/Shaders/SimpleShader.cs similarity index 96% rename from SMCode/SM.Base/Shaders/SimpleShader.cs rename to src/renderer/SM.Base/Shaders/SimpleShader.cs index e068e12..5db13b4 100644 --- a/SMCode/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/SMCode/SM.Base/Shaders/SimpleShaderPresets/basic_vertex.glsl b/src/renderer/SM.Base/Shaders/SimpleShaderPresets/basic_vertex.glsl similarity index 75% rename from SMCode/SM.Base/Shaders/SimpleShaderPresets/basic_vertex.glsl rename to src/renderer/SM.Base/Shaders/SimpleShaderPresets/basic_vertex.glsl index 503fb5a..5dd3936 100644 --- a/SMCode/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/SMCode/SM.Base/Shaders/SimpleShaderPresets/instanced_vertex.glsl b/src/renderer/SM.Base/Shaders/SimpleShaderPresets/instanced_vertex.glsl similarity index 81% rename from SMCode/SM.Base/Shaders/SimpleShaderPresets/instanced_vertex.glsl rename to src/renderer/SM.Base/Shaders/SimpleShaderPresets/instanced_vertex.glsl index 3565cf6..1f594ae 100644 --- a/SMCode/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/SMCode/SM.Base/Textures/Texture.cs b/src/renderer/SM.Base/Textures/Texture.cs similarity index 100% rename from SMCode/SM.Base/Textures/Texture.cs rename to src/renderer/SM.Base/Textures/Texture.cs diff --git a/SMCode/SM.Base/Time/Interval.cs b/src/renderer/SM.Base/Time/Interval.cs similarity index 100% rename from SMCode/SM.Base/Time/Interval.cs rename to src/renderer/SM.Base/Time/Interval.cs diff --git a/SMCode/SM.Base/Time/Stopwatch.cs b/src/renderer/SM.Base/Time/Stopwatch.cs similarity index 100% rename from SMCode/SM.Base/Time/Stopwatch.cs rename to src/renderer/SM.Base/Time/Stopwatch.cs diff --git a/SMCode/SM.Base/Time/Timer.cs b/src/renderer/SM.Base/Time/Timer.cs similarity index 97% rename from SMCode/SM.Base/Time/Timer.cs rename to src/renderer/SM.Base/Time/Timer.cs index f6e3c37..15ff2bd 100644 --- a/SMCode/SM.Base/Time/Timer.cs +++ b/src/renderer/SM.Base/Time/Timer.cs @@ -33,7 +33,7 @@ namespace SM.Base.Time /// /// The target time in seconds. /// - public float Target { get; } + public float Target { get; set; } /// /// The already elapsed time but normalized to the target. diff --git a/SMCode/SM.Base/Types/CVector1.cs b/src/renderer/SM.Base/Types/CVector1.cs similarity index 71% rename from SMCode/SM.Base/Types/CVector1.cs rename to src/renderer/SM.Base/Types/CVector1.cs index b2a80f9..891e8ea 100644 --- a/SMCode/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/SMCode/SM.Base/Types/CVector2.cs b/src/renderer/SM.Base/Types/CVector2.cs similarity index 77% rename from SMCode/SM.Base/Types/CVector2.cs rename to src/renderer/SM.Base/Types/CVector2.cs index 8063c6b..5f89219 100644 --- a/SMCode/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/SMCode/SM.Base/Types/CVector3.cs b/src/renderer/SM.Base/Types/CVector3.cs similarity index 81% rename from SMCode/SM.Base/Types/CVector3.cs rename to src/renderer/SM.Base/Types/CVector3.cs index 64231f0..e5dfd92 100644 --- a/SMCode/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/SMCode/SM.Base/Types/CVector4.cs b/src/renderer/SM.Base/Types/CVector4.cs similarity index 80% rename from SMCode/SM.Base/Types/CVector4.cs rename to src/renderer/SM.Base/Types/CVector4.cs index 2f88938..90addab 100644 --- a/SMCode/SM.Base/Types/CVector4.cs +++ b/src/renderer/SM.Base/Types/CVector4.cs @@ -1,5 +1,4 @@ using System; -using System.Windows.Forms; using OpenTK; using SM.Base.Animation; @@ -24,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 new file mode 100644 index 0000000..39d5831 --- /dev/null +++ b/src/renderer/SM.Base/Types/CVectorBase.cs @@ -0,0 +1,142 @@ +using System; +using OpenTK; +using OpenTK.Audio.OpenAL; +using OpenTK.Graphics.OpenGL; +using SM.Base.Animation; + +namespace SM.Base.Types +{ + /// + /// Basis for the CVector classes + /// + public abstract class CVectorBase + { + /// + /// This event triggers when a component changed. + /// + public event Action Changed; + + /// + /// The length/magnitute of the vector. + /// + public float Length => GetLength(); + + /// + /// Gets the square of the vector length (magnitude). + /// + /// + /// This property avoids the costly square root operation required by the Length property. This makes it more suitable + /// for comparisons. + /// + public float LengthSquared => GetLength(true); + + /// + /// Get the length of the vector. + /// + /// If true, it will return the squared product. + /// + public float GetLength(bool squared = false) + { + float length = GetLengthProcess(); + if (squared) return length; + return (float)Math.Sqrt(length); + } + + /// + /// Normalizes the vector. + /// + public void Normalize() + { + float length = GetLength(); + 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. + /// + /// + public abstract void SetRaw(params float[] parameters); + + /// + /// This triggers the event. + /// + protected void TriggerChanged() + { + Changed?.Invoke(); + } + + /// + /// Conversion from to One-dimensional Vector. + /// + /// + protected abstract float GetLengthProcess(); + + /// + /// Normalizes the vector. + /// + /// + protected abstract void NormalizationProcess(float length); + + /// + /// Converts the vector to a + /// + /// + protected abstract Vector4 ConvertToVector4(); + } +} \ No newline at end of file diff --git a/src/renderer/SM.Base/Types/MinMax.cs b/src/renderer/SM.Base/Types/MinMax.cs new file mode 100644 index 0000000..6b8f2c4 --- /dev/null +++ b/src/renderer/SM.Base/Types/MinMax.cs @@ -0,0 +1,53 @@ +using OpenTK; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SM.Base.Types +{ + /// + /// Structure to store Min and Max-values. + /// + public struct MinMax + { + /// + /// Default Value: 0..1 + /// + public static readonly MinMax Default = new MinMax(0, 1); + + /// + /// Minimum Value + /// + public float Min; + /// + /// Maximum Value + /// + public float Max; + + /// + /// Creates a MinMax-structure with two values. + /// + public MinMax(float min, float max) + { + Min = min; + Max = max; + } + + /// + /// Get a value that is between and based on t [0..1] + /// + /// + public float GetPoint(float t) + { + return t * (Max - Min) + Min; + } + + /// + /// Converts to Vector2. + /// + /// + public static explicit operator Vector2(MinMax v) => new Vector2(v.Min, v.Max); + } +} diff --git a/SMCode/SM.Base/Utility/Assembly.cs b/src/renderer/SM.Base/Utility/Assembly.cs similarity index 100% rename from SMCode/SM.Base/Utility/Assembly.cs rename to src/renderer/SM.Base/Utility/Assembly.cs diff --git a/SMCode/SM.Base/Utility/Deltatime.cs b/src/renderer/SM.Base/Utility/Deltatime.cs similarity index 100% rename from SMCode/SM.Base/Utility/Deltatime.cs rename to src/renderer/SM.Base/Utility/Deltatime.cs diff --git a/SMCode/SM.Base/Utility/IInitializable.cs b/src/renderer/SM.Base/Utility/IInitializable.cs similarity index 100% rename from SMCode/SM.Base/Utility/IInitializable.cs rename to src/renderer/SM.Base/Utility/IInitializable.cs 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/SMCode/SM.Base/Utility/Randomize.cs b/src/renderer/SM.Base/Utility/Randomize.cs similarity index 100% rename from SMCode/SM.Base/Utility/Randomize.cs rename to src/renderer/SM.Base/Utility/Randomize.cs diff --git a/SMCode/SM.Base/Utility/Ray.cs b/src/renderer/SM.Base/Utility/Ray.cs similarity index 100% rename from SMCode/SM.Base/Utility/Ray.cs rename to src/renderer/SM.Base/Utility/Ray.cs diff --git a/SMCode/SM.Base/Utility/RotationUtility.cs b/src/renderer/SM.Base/Utility/RotationUtility.cs similarity index 100% rename from SMCode/SM.Base/Utility/RotationUtility.cs rename to src/renderer/SM.Base/Utility/RotationUtility.cs diff --git a/SMCode/SM.Base/Utility/Util.cs b/src/renderer/SM.Base/Utility/Util.cs similarity index 100% rename from SMCode/SM.Base/Utility/Util.cs rename to src/renderer/SM.Base/Utility/Util.cs diff --git a/SMCode/SM.Base/Window/Contexts/DrawContext.cs b/src/renderer/SM.Base/Window/Contexts/DrawContext.cs similarity index 100% rename from SMCode/SM.Base/Window/Contexts/DrawContext.cs rename to src/renderer/SM.Base/Window/Contexts/DrawContext.cs diff --git a/SMCode/SM.Base/Window/Contexts/FixedUpdateContext.cs b/src/renderer/SM.Base/Window/Contexts/FixedUpdateContext.cs similarity index 100% rename from SMCode/SM.Base/Window/Contexts/FixedUpdateContext.cs rename to src/renderer/SM.Base/Window/Contexts/FixedUpdateContext.cs diff --git a/SMCode/SM.Base/Window/Contexts/UpdateContext.cs b/src/renderer/SM.Base/Window/Contexts/UpdateContext.cs similarity index 100% rename from SMCode/SM.Base/Window/Contexts/UpdateContext.cs rename to src/renderer/SM.Base/Window/Contexts/UpdateContext.cs diff --git a/SMCode/SM.Base/Window/GLWindow.cs b/src/renderer/SM.Base/Window/GLWindow.cs similarity index 100% rename from SMCode/SM.Base/Window/GLWindow.cs rename to src/renderer/SM.Base/Window/GLWindow.cs diff --git a/SMCode/SM.Base/Window/IGenericWindow.cs b/src/renderer/SM.Base/Window/IGenericWindow.cs similarity index 100% rename from SMCode/SM.Base/Window/IGenericWindow.cs rename to src/renderer/SM.Base/Window/IGenericWindow.cs diff --git a/SMCode/SM.Base/Window/ISetup.cs b/src/renderer/SM.Base/Window/ISetup.cs similarity index 100% rename from SMCode/SM.Base/Window/ISetup.cs rename to src/renderer/SM.Base/Window/ISetup.cs diff --git a/SMCode/SM.Base/Window/RenderPipeline.cs b/src/renderer/SM.Base/Window/RenderPipeline.cs similarity index 70% rename from SMCode/SM.Base/Window/RenderPipeline.cs rename to src/renderer/SM.Base/Window/RenderPipeline.cs index b9f89dd..19afdb0 100644 --- a/SMCode/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,19 +53,26 @@ namespace SM.Base.Window /// public virtual void Activate() + { } + public void Initialization() { - } + InitializationProcess(); - /// - public virtual void Initialization() - { - if (MainFramebuffer != null) { + InitizePostProcessing(); + if (MainFramebuffer != null) + { Framebuffers.Add(MainFramebuffer); MainFramebuffer.Name = GetType().Name + ".MainFramebuffer"; } DefaultShader ??= SMRenderer.DefaultMaterialShader; } + /// + protected virtual void InitializationProcess() + { + + } + internal void Render(ref DrawContext context) { RenderProcess(ref context); @@ -73,11 +86,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. @@ -113,14 +141,20 @@ namespace SM.Base.Window /// /// This creates a finished setup for a framebuffer. /// - public Framebuffer CreateWindowFramebuffer(int multisamples = 0, PixelInformation? pixelInformation = null, bool depth = true) + public Framebuffer CreateWindowFramebuffer(int multisamples = 0, PixelInformation? pixelInformation = null, bool depth = true) => + CreateWindowFramebuffer(ConnectedWindow, multisamples, pixelInformation, depth); + + /// + /// This creates a finished setup for a framebuffer. + /// + public static Framebuffer CreateWindowFramebuffer(IFramebufferWindow window, 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 framebuffer = new Framebuffer(window); + 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/SMCode/SM.Base/Window/WindowCode.cs b/src/renderer/SM.Base/Window/WindowCode.cs similarity index 96% rename from SMCode/SM.Base/Window/WindowCode.cs rename to src/renderer/SM.Base/Window/WindowCode.cs index 6270a52..8cdd501 100644 --- a/SMCode/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/SMCode/SM.Base/Window/WindowFlags.cs b/src/renderer/SM.Base/Window/WindowFlags.cs similarity index 100% rename from SMCode/SM.Base/Window/WindowFlags.cs rename to src/renderer/SM.Base/Window/WindowFlags.cs diff --git a/SMCode/SM.Base/Window/winIcon.ico b/src/renderer/SM.Base/Window/winIcon.ico similarity index 100% rename from SMCode/SM.Base/Window/winIcon.ico rename to src/renderer/SM.Base/Window/winIcon.ico diff --git a/SMCode/SM.Base/packages.config b/src/renderer/SM.Base/packages.config similarity index 77% rename from SMCode/SM.Base/packages.config rename to src/renderer/SM.Base/packages.config index e8dfb8b..85e4bbb 100644 --- a/SMCode/SM.Base/packages.config +++ b/src/renderer/SM.Base/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file diff --git a/SMCode/SM.OGL/Framebuffer/ColorAttachment.cs b/src/renderer/SM.OGL/Framebuffer/ColorAttachment.cs similarity index 60% rename from SMCode/SM.OGL/Framebuffer/ColorAttachment.cs rename to src/renderer/SM.OGL/Framebuffer/ColorAttachment.cs index cf3678a..0592e2e 100644 --- a/SMCode/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,18 @@ 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; } + + /// + /// Can contains the size this attachment want to be. + /// If set, it will ignore the size from the framebuffer. + /// + public Vector2? AttachmentSize = null; + /// /// Returns the of this ColorAttachment. /// @@ -47,7 +60,8 @@ 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) { } /// @@ -55,13 +69,19 @@ 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; + + if (multisamples > 8) multisamples = 8; _multisamples = multisamples; Target = IsMultisampled ? TextureTarget.Texture2DMultisample : TextureTarget.Texture2D; + + WrapMode = TextureWrapMode.ClampToEdge; } /// /// Generates the attachment. @@ -70,6 +90,7 @@ namespace SM.OGL.Framebuffer public void Generate(Framebuffer f) { _id = GL.GenTexture(); + ConnectedFramebuffer = f; if (IsMultisampled) GenerateMultisampledTexture(f); else GenerateTexture(f); @@ -77,29 +98,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/SMCode/SM.OGL/Framebuffer/Framebuffer.cs b/src/renderer/SM.OGL/Framebuffer/Framebuffer.cs similarity index 66% rename from SMCode/SM.OGL/Framebuffer/Framebuffer.cs rename to src/renderer/SM.OGL/Framebuffer/Framebuffer.cs index 628e807..6a817de 100644 --- a/SMCode/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; @@ -46,8 +50,16 @@ namespace SM.OGL.Framebuffer /// public Vector2 Size { get; private set; } + /// + /// Says what value the dafault for the "applyViewport"-value in . + /// public bool DefaultApplyViewport { get; set; } = true; + /// + /// Stores the first color attachment added. + /// + public ColorAttachment FirstColorAttachment { get; private set; } + /// /// Contains all color attachments. /// @@ -56,7 +68,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 +128,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 +148,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 +176,20 @@ 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)); + /// + /// Appends a color attachment. + /// + /// + /// + /// + 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 +199,8 @@ namespace SM.OGL.Framebuffer /// public void AppendRenderbuffer(RenderbufferAttachment attachment) { - RenderbufferAttachments.Add(attachment, -1); + if (RenderbufferAttachments.Contains(attachment)) return; + RenderbufferAttachments.Add(attachment); } /// @@ -180,6 +215,7 @@ namespace SM.OGL.Framebuffer /// Activates the framebuffer for the specific target framebuffer and without clearing. /// /// + /// public void Activate(FramebufferTarget target, bool? applyViewport = null) { Activate(target, ClearBufferMask.None, applyViewport); @@ -189,6 +225,7 @@ namespace SM.OGL.Framebuffer /// Activates the framebuffer while clearing the specified buffer. /// /// + /// public void Activate(ClearBufferMask clearMask, bool? applyViewport = null) { Activate(FramebufferTarget.Framebuffer, clearMask, applyViewport); @@ -199,19 +236,58 @@ 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 +308,8 @@ namespace SM.OGL.Framebuffer break; } + + return buffer; } } diff --git a/SMCode/SM.OGL/Framebuffer/IFramebufferWindow.cs b/src/renderer/SM.OGL/Framebuffer/IFramebufferWindow.cs similarity index 100% rename from SMCode/SM.OGL/Framebuffer/IFramebufferWindow.cs rename to src/renderer/SM.OGL/Framebuffer/IFramebufferWindow.cs diff --git a/SMCode/SM.OGL/Framebuffer/RenderbufferAttachment.cs b/src/renderer/SM.OGL/Framebuffer/RenderbufferAttachment.cs similarity index 56% rename from SMCode/SM.OGL/Framebuffer/RenderbufferAttachment.cs rename to src/renderer/SM.OGL/Framebuffer/RenderbufferAttachment.cs index 3988bb4..de00fb9 100644 --- a/SMCode/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,49 @@ 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; + } + + /// + public override int GetHashCode() + { + int hashCode = -1803239493; + hashCode = hashCode * -1521134295 + Storage.GetHashCode(); + hashCode = hashCode * -1521134295 + FramebufferAttachment.GetHashCode(); + hashCode = hashCode * -1521134295 + Multisample.GetHashCode(); + hashCode = hashCode * -1521134295 + ID.GetHashCode(); + return hashCode; } } } \ No newline at end of file diff --git a/SMCode/SM.OGL/GLCustomActions.cs b/src/renderer/SM.OGL/GLCustomActions.cs similarity index 100% rename from SMCode/SM.OGL/GLCustomActions.cs rename to src/renderer/SM.OGL/GLCustomActions.cs diff --git a/SMCode/SM.OGL/GLDebugging.cs b/src/renderer/SM.OGL/GLDebugging.cs similarity index 100% rename from SMCode/SM.OGL/GLDebugging.cs rename to src/renderer/SM.OGL/GLDebugging.cs diff --git a/SMCode/SM.OGL/GLObject.cs b/src/renderer/SM.OGL/GLObject.cs similarity index 98% rename from SMCode/SM.OGL/GLObject.cs rename to src/renderer/SM.OGL/GLObject.cs index 89b0fbe..a0538e6 100644 --- a/SMCode/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/SMCode/SM.OGL/GLSettings.cs b/src/renderer/SM.OGL/GLSettings.cs similarity index 100% rename from SMCode/SM.OGL/GLSettings.cs rename to src/renderer/SM.OGL/GLSettings.cs diff --git a/SMCode/SM.OGL/GLSystem.cs b/src/renderer/SM.OGL/GLSystem.cs similarity index 100% rename from SMCode/SM.OGL/GLSystem.cs rename to src/renderer/SM.OGL/GLSystem.cs diff --git a/SMCode/SM.OGL/Mesh/BoundingBox.cs b/src/renderer/SM.OGL/Mesh/BoundingBox.cs similarity index 100% rename from SMCode/SM.OGL/Mesh/BoundingBox.cs rename to src/renderer/SM.OGL/Mesh/BoundingBox.cs diff --git a/SMCode/SM.OGL/Mesh/GenericMesh.cs b/src/renderer/SM.OGL/Mesh/GenericMesh.cs similarity index 100% rename from SMCode/SM.OGL/Mesh/GenericMesh.cs rename to src/renderer/SM.OGL/Mesh/GenericMesh.cs diff --git a/SMCode/SM.OGL/Mesh/ILineMesh.cs b/src/renderer/SM.OGL/Mesh/ILineMesh.cs similarity index 100% rename from SMCode/SM.OGL/Mesh/ILineMesh.cs rename to src/renderer/SM.OGL/Mesh/ILineMesh.cs diff --git a/SMCode/SM.OGL/Mesh/MeshAttribute.cs b/src/renderer/SM.OGL/Mesh/MeshAttribute.cs similarity index 100% rename from SMCode/SM.OGL/Mesh/MeshAttribute.cs rename to src/renderer/SM.OGL/Mesh/MeshAttribute.cs diff --git a/SMCode/SM.OGL/Mesh/MeshAttributeList.cs b/src/renderer/SM.OGL/Mesh/MeshAttributeList.cs similarity index 100% rename from SMCode/SM.OGL/Mesh/MeshAttributeList.cs rename to src/renderer/SM.OGL/Mesh/MeshAttributeList.cs diff --git a/SMCode/SM.OGL/Mesh/VBO.cs b/src/renderer/SM.OGL/Mesh/VBO.cs similarity index 100% rename from SMCode/SM.OGL/Mesh/VBO.cs rename to src/renderer/SM.OGL/Mesh/VBO.cs diff --git a/SM_TEST/OpenTK.dll.config b/src/renderer/SM.OGL/OpenTK.dll.config similarity index 100% rename from SM_TEST/OpenTK.dll.config rename to src/renderer/SM.OGL/OpenTK.dll.config diff --git a/SMCode/SM.OGL/Properties/AssemblyInfo.cs b/src/renderer/SM.OGL/Properties/AssemblyInfo.cs similarity index 100% rename from SMCode/SM.OGL/Properties/AssemblyInfo.cs rename to src/renderer/SM.OGL/Properties/AssemblyInfo.cs diff --git a/SMCode/SM.OGL/SM.OGL.csproj b/src/renderer/SM.OGL/SM.OGL.csproj similarity index 97% rename from SMCode/SM.OGL/SM.OGL.csproj rename to src/renderer/SM.OGL/SM.OGL.csproj index 74321d3..fd8ec5d 100644 --- a/SMCode/SM.OGL/SM.OGL.csproj +++ b/src/renderer/SM.OGL/SM.OGL.csproj @@ -12,6 +12,7 @@ v4.5.2 512 true + true @@ -35,7 +36,7 @@ - ..\..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll + ..\..\..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll @@ -70,12 +71,12 @@ + + + - - - \ No newline at end of file diff --git a/SMCode/SM.OGL/Shaders/GenericShader.cs b/src/renderer/SM.OGL/Shaders/GenericShader.cs similarity index 90% rename from SMCode/SM.OGL/Shaders/GenericShader.cs rename to src/renderer/SM.OGL/Shaders/GenericShader.cs index 27d74e7..c6617a6 100644 --- a/SMCode/SM.OGL/Shaders/GenericShader.cs +++ b/src/renderer/SM.OGL/Shaders/GenericShader.cs @@ -16,10 +16,12 @@ namespace SM.OGL.Shaders /// protected override bool AutoCompile { get; set; } = true; + public bool ErrorInShader { get; private set; } + /// /// Contains the different files for the shader. /// - protected ShaderFileCollection ShaderFileFiles; + public ShaderFileCollection ShaderFiles; /// /// Contains and manage the uniforms from the shader. @@ -67,7 +69,7 @@ namespace SM.OGL.Shaders Console.WriteLine(); - ShaderFileFiles = new ShaderFileCollection(vertex,fragment, geometry); + ShaderFiles = new ShaderFileCollection(vertex,fragment, geometry); } /// @@ -80,7 +82,7 @@ namespace SM.OGL.Shaders /// protected GenericShader(ShaderFileCollection shaderFileFiles) { - ShaderFileFiles = shaderFileFiles; + ShaderFiles = shaderFileFiles; } /// @@ -92,7 +94,7 @@ namespace SM.OGL.Shaders /// public void Update(ShaderFileCollection newShaderFiles) { - ShaderFileFiles = newShaderFiles; + ShaderFiles = newShaderFiles; Recompile(); } @@ -102,12 +104,17 @@ namespace SM.OGL.Shaders public void Load() { _id = GL.CreateProgram(); + Uniforms = new UniformCollection { ParentShader = this }; - ShaderFileFiles.Append(this); + ErrorInShader = !ShaderFiles.Append(this); + if (ErrorInShader) + { + GL.DeleteProgram(_id); + return; + } GL.LinkProgram(_id); - ShaderFileFiles.Detach(this); + ShaderFiles.Detach(this); - Uniforms = new UniformCollection {ParentShader = this}; Uniforms.Import(this); GLDebugging.CheckGLErrors($"A error occured at shader creation for '{GetType()}': %code%"); diff --git a/SMCode/SM.OGL/Shaders/IUniform.cs b/src/renderer/SM.OGL/Shaders/IUniform.cs similarity index 100% rename from SMCode/SM.OGL/Shaders/IUniform.cs rename to src/renderer/SM.OGL/Shaders/IUniform.cs diff --git a/SMCode/SM.OGL/Shaders/ShaderExtensions.cs b/src/renderer/SM.OGL/Shaders/ShaderExtensions.cs similarity index 100% rename from SMCode/SM.OGL/Shaders/ShaderExtensions.cs rename to src/renderer/SM.OGL/Shaders/ShaderExtensions.cs diff --git a/SMCode/SM.OGL/Shaders/ShaderFile.cs b/src/renderer/SM.OGL/Shaders/ShaderFile.cs similarity index 66% rename from SMCode/SM.OGL/Shaders/ShaderFile.cs rename to src/renderer/SM.OGL/Shaders/ShaderFile.cs index 5cb23f8..4e395b5 100644 --- a/SMCode/SM.OGL/Shaders/ShaderFile.cs +++ b/src/renderer/SM.OGL/Shaders/ShaderFile.cs @@ -14,12 +14,14 @@ namespace SM.OGL.Shaders public class ShaderFile : GLObject { private string _data; - + /// /// Contains other shader files to allow access to their functions. /// public List GLSLExtensions = new List(); + public List Defines = new List(); + /// /// Gets/Sets the name for this shader file. /// @@ -63,21 +65,44 @@ namespace SM.OGL.Shaders _data = _data.Replace("//!" + kvp.Key, kvp.Value); } - internal void Compile(GenericShader shader, ShaderType type) + internal bool Compile(GenericShader shader, ShaderType type) { if (_id < 0) { GenerateSource(); _id = GL.CreateShader(type); - GL.ShaderSource(_id, _data); + if (Defines.Count > 0) + { + string defineString = ""; + foreach(string define in Defines) + { + defineString += "#define " + define + Environment.NewLine; + } + + GL.ShaderSource(_id, 2, new string[] { defineString, _data }, new int[] { defineString.Length, _data.Length }); + } else GL.ShaderSource(_id, _data); GL.CompileShader(_id); } - GL.AttachShader(shader, _id); - GLDebugging.CheckGLErrors($"Error at loading shader file: '{shader.GetType()}', '{type}', %code%"); + GL.GetShader(_id, ShaderParameter.CompileStatus, out int compileStatus); + if (compileStatus != 1) + { + GL.GetShader(_id, ShaderParameter.InfoLogLength, out int loglength); - for (var i = 0; i < GLSLExtensions.Count; i++) GLSLExtensions[i].Compile(shader, type); + GLCustomActions.AtWarning?.Invoke($"Shader '{ToString()}' doesn't compile correctly.\nReason:" + GL.GetShaderInfoLog(_id)); + + GL.DeleteShader(_id); + return false; + } + + GL.AttachShader(shader, _id); + + + for (var i = 0; i < GLSLExtensions.Count; i++) { + if (!GLSLExtensions[i].Compile(shader, type)) return false; + } + return true; } /// diff --git a/SMCode/SM.OGL/Shaders/ShaderFileCollection.cs b/src/renderer/SM.OGL/Shaders/ShaderFileCollection.cs similarity index 89% rename from SMCode/SM.OGL/Shaders/ShaderFileCollection.cs rename to src/renderer/SM.OGL/Shaders/ShaderFileCollection.cs index 0b6f2a7..33b92ed 100644 --- a/SMCode/SM.OGL/Shaders/ShaderFileCollection.cs +++ b/src/renderer/SM.OGL/Shaders/ShaderFileCollection.cs @@ -68,17 +68,19 @@ namespace SM.OGL.Shaders /// Appends the files to the shader. /// /// - internal void Append(GenericShader shader) + internal bool Append(GenericShader shader) { foreach (ShaderFile file in Vertex) - file.Compile(shader, ShaderType.VertexShader); + if (!file.Compile(shader, ShaderType.VertexShader)) return false; if (Geometry != null) foreach (ShaderFile file in Geometry) - file.Compile(shader, ShaderType.GeometryShader); + if (!file.Compile(shader, ShaderType.GeometryShader)) return false; - foreach (ShaderFile file in Fragment) - file.Compile(shader, ShaderType.FragmentShader); + foreach (ShaderFile file in Fragment) + if (!file.Compile(shader, ShaderType.FragmentShader)) return false; + + return true; } /// diff --git a/SMCode/SM.OGL/Shaders/ShaderPreProcess.cs b/src/renderer/SM.OGL/Shaders/ShaderPreProcess.cs similarity index 100% rename from SMCode/SM.OGL/Shaders/ShaderPreProcess.cs rename to src/renderer/SM.OGL/Shaders/ShaderPreProcess.cs diff --git a/src/renderer/SM.OGL/Shaders/Uniform.cs b/src/renderer/SM.OGL/Shaders/Uniform.cs new file mode 100644 index 0000000..5b5810e --- /dev/null +++ b/src/renderer/SM.OGL/Shaders/Uniform.cs @@ -0,0 +1,585 @@ +#region usings + +using OpenTK; +using OpenTK.Graphics; +using OpenTK.Graphics.OpenGL4; +using SM.OGL.Texture; + +#endregion + +namespace SM.OGL.Shaders +{ + /// + /// Manages the uniforms. + /// + public struct Uniform : IUniform + { + /// + /// This contains the location for the uniform. + /// + public int Location { get; internal set; } + + /// + /// This contains the Parent collection of this uniform. + /// + public UniformCollection Parent { get; } + + #region Constructors + /// + /// This creates a new uniform manager, that has a null parent. + /// + /// + public Uniform(int location) : this(location, null) + { + } + + /// + /// This creates a new uniform manager, that get the location from the provided shader and with a null parent. + /// + /// + /// + public Uniform(string name, GenericShader shader) : this(GL.GetUniformLocation(shader, name), null) + { + + } + /// + /// This creates a new uniform manager, that get the location from the provided shader and with a parent. + /// + /// + /// + /// + public Uniform(string name, GenericShader shader, UniformCollection parent) : this(GL.GetUniformLocation(shader, name), parent) + { + + } + + /// + /// This create a new uniform manager + /// + /// Location id + /// Parent collection + public Uniform(int location, UniformCollection parent) + { + Location = location; + Parent = parent; + } + + #endregion + + #region Uniform1 + + /// + /// Set a boolean as value. + /// + /// + public void SetBool(bool value) + { + GL.Uniform1(Location, value ? 1 : 0); + } + + /// + /// Sets a integer. + /// + /// + public void SetInt(int value) + { + GL.Uniform1(Location, value); + } + + /// + /// Sets an array of integers. + /// + /// + public void SetInt(params int[] values) + { + GL.Uniform1(Location, values.Length, values); + } + + /// + /// Set a unsigned integer. + /// + /// + public void SetUInt(uint value) + { + GL.Uniform1(Location, value); + } + + /// + /// Set an array of unsigned integers. + /// + /// + public void SetUInt(params uint[] values) + { + GL.Uniform1(Location, values.Length, values); + } + + /// + /// Sets a float. + /// + /// + public void SetFloat(float value) + { + GL.Uniform1(Location, value); + } + + /// + /// Sets an array of floats. + /// + /// + public void SetFloat(params float[] values) + { + GL.Uniform1(Location, values.Length, values); + } + + #endregion + + #region Uniform2 + + /// + /// Sets a float vector2 by providing the values. + /// + /// + /// + public void SetVector2(float x, float y) + { + GL.Uniform2(Location, x, y); + } + + /// + /// Sets a unsigned integer vector2 by providing the values. + /// + /// + /// + public void SetVector2(uint x, uint y) + { + GL.Uniform2(Location, x, y); + } + + /// + /// Sets a integer vector2 by providing the values. + /// + /// + /// + public void SetVector2(int x, int y) + { + GL.Uniform2(Location, x, y); + } + + /// + /// Sets a float vector2. + /// + /// + public void SetVector2(Vector2 vector2) + { + GL.Uniform2(Location, 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 + + /// + /// Sets a float vector3 by providing the values. + /// + /// + /// + /// + public void SetVector3(float x, float y, float z) + { + GL.Uniform3(Location, x, y, 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); + } + + /// + /// Sets a integer vector3 by providing the values. + /// + /// + /// + /// + public void SetVector3(int x, int y, int z) + { + GL.Uniform3(Location, x, y, z); + } + + /// + /// Sets a vector3. + /// + /// + public void SetVector3(Vector3 vector) + { + GL.Uniform3(Location, 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 + + /// + /// 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); + } + + /// + /// Sets a vector4. + /// + /// + public void SetVector4(Vector4 vector) + { + GL.Uniform4(Location, vector); + } + + /// + /// Sets a vector4. + /// + /// + public void SetVector4(ref Vector4 vector) + { + GL.Uniform4(Location, ref vector); + } + + /// + /// Sets a array of Vector4. + /// + /// + public void SetVector4(params Vector4[] values) + { + 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); + } + + /// + /// 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); + } + + #endregion + + #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); + } + + /// + /// 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); + } + + #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); + } + + /// + /// 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); + } + + #endregion + + #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); + } + + /// + /// 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); + } + + #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. + /// + /// The texture you want to add + /// The check uniform. + public void SetTexture(TextureBase texture, Uniform checkUniform) + { + checkUniform.SetBool(texture != null); + if (texture != null) SetTexture(texture); + } + + /// + /// Try to sets the texture at the specified position and tells the checkUniform, if worked or not. + /// + /// The texture you want to add + /// The position + /// The check uniform. + public void SetTexture(TextureBase texture, int pos, Uniform checkUniform) + { + checkUniform.SetBool(texture != null); + if (texture != null) SetTexture(texture); + } + + /// + /// Sets the texture to the next possible position. + /// + /// + public void SetTexture(TextureBase texture) + { + if (Parent != null) SetTexture(texture, Parent.NextTexture); + } + + /// + /// Sets the texture to the specified position. + /// + /// + /// + public void SetTexture(TextureBase texture, int texturePos) + { + Parent.NextTexture = texturePos + 1; + GL.ActiveTexture(TextureUnit.Texture0 + texturePos); + GL.BindTexture(texture.Target, texture); + SetInt(texturePos); + } + + /// + /// Returns the location from the uniform + /// + /// + public static implicit operator int(Uniform u) + { + return u.Location; + } + } +} \ No newline at end of file diff --git a/SMCode/SM.OGL/Shaders/UniformArray.cs b/src/renderer/SM.OGL/Shaders/UniformArray.cs similarity index 100% rename from SMCode/SM.OGL/Shaders/UniformArray.cs rename to src/renderer/SM.OGL/Shaders/UniformArray.cs diff --git a/SMCode/SM.OGL/Shaders/UniformCollection.cs b/src/renderer/SM.OGL/Shaders/UniformCollection.cs similarity index 100% rename from SMCode/SM.OGL/Shaders/UniformCollection.cs rename to src/renderer/SM.OGL/Shaders/UniformCollection.cs diff --git a/SMCode/SM.OGL/Texture/PixelInformation.cs b/src/renderer/SM.OGL/Texture/PixelInformation.cs similarity index 96% rename from SMCode/SM.OGL/Texture/PixelInformation.cs rename to src/renderer/SM.OGL/Texture/PixelInformation.cs index e52e75c..109f513 100644 --- a/SMCode/SM.OGL/Texture/PixelInformation.cs +++ b/src/renderer/SM.OGL/Texture/PixelInformation.cs @@ -14,7 +14,7 @@ namespace SM.OGL.Texture /// /// RGB without Alpha channel, High Dynamic Range (0 - n) /// - public static PixelInformation RGB_HDR = new PixelInformation(PixelInternalFormat.Rgb16f, PixelFormat.Rgb, PixelType.Float); + public static PixelInformation RGB_HDR = new PixelInformation(PixelInternalFormat.R11fG11fB10f, PixelFormat.Rgb, PixelType.Float); /// /// RGB with Alpha channel, Low Dynamic Range (0 - 1) /// diff --git a/SMCode/SM.OGL/Texture/TextureBase.cs b/src/renderer/SM.OGL/Texture/TextureBase.cs similarity index 53% rename from SMCode/SM.OGL/Texture/TextureBase.cs rename to src/renderer/SM.OGL/Texture/TextureBase.cs index 495fe74..524c528 100644 --- a/SMCode/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,46 @@ namespace SM.OGL.Texture /// public virtual int Height { get; protected set; } + /// + /// Returns the size of the texture. + /// + public Vector2 Size => new Vector2(Width, Height); + /// + /// Returns the texel size of the texture. + /// Returns: 1 / Size + /// + public Vector2 TexelSize => new Vector2(1f / Width, 1f / Height); + /// public override void Dispose() { GL.DeleteTexture(_id); base.Dispose(); } + + /// + /// Generates a basic texture, that applies all settings from the -class. + /// + /// + 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/SMCode/SM.OGL/Version.cs b/src/renderer/SM.OGL/Version.cs similarity index 100% rename from SMCode/SM.OGL/Version.cs rename to src/renderer/SM.OGL/Version.cs diff --git a/SM_WPF_TEST/packages.config b/src/renderer/SM.OGL/packages.config similarity index 51% rename from SM_WPF_TEST/packages.config rename to src/renderer/SM.OGL/packages.config index 82cdaeb..1f65eab 100644 --- a/SM_WPF_TEST/packages.config +++ b/src/renderer/SM.OGL/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/SMCode/SM2D/Controls/Mouse2D.cs b/src/renderer/SM2D/Controls/Mouse2D.cs similarity index 100% rename from SMCode/SM2D/Controls/Mouse2D.cs rename to src/renderer/SM2D/Controls/Mouse2D.cs diff --git a/SMCode/SM2D/Drawing/DrawBackground.cs b/src/renderer/SM2D/Drawing/DrawBackground.cs similarity index 98% rename from SMCode/SM2D/Drawing/DrawBackground.cs rename to src/renderer/SM2D/Drawing/DrawBackground.cs index 3fabd1d..da6c696 100644 --- a/SMCode/SM2D/Drawing/DrawBackground.cs +++ b/src/renderer/SM2D/Drawing/DrawBackground.cs @@ -85,7 +85,7 @@ namespace SM2D.Drawing { base.DrawContext(ref context); context.ModelMatrix = Matrix4.CreateScale((context.UseCamera as Camera).WorldScale.X, (context.UseCamera as Camera).WorldScale.Y, 0) * Matrix4.CreateTranslation(0,0, -1.1f); - context.Shader.Draw(context); + Material.Draw(context); } } } \ No newline at end of file diff --git a/SMCode/SM2D/Drawing/DrawObject2D.cs b/src/renderer/SM2D/Drawing/DrawObject2D.cs similarity index 97% rename from SMCode/SM2D/Drawing/DrawObject2D.cs rename to src/renderer/SM2D/Drawing/DrawObject2D.cs index e9176e6..ac2a95d 100644 --- a/SMCode/SM2D/Drawing/DrawObject2D.cs +++ b/src/renderer/SM2D/Drawing/DrawObject2D.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Drawing.Printing; using OpenTK; using OpenTK.Graphics; using SM.Base.Drawing; @@ -35,7 +36,7 @@ namespace SM2D.Drawing protected override void DrawContext(ref DrawContext context) { base.DrawContext(ref context); - context.Shader.Draw(context); + Material.Draw(context); } /// diff --git a/SMCode/SM2D/Drawing/DrawParticles.cs b/src/renderer/SM2D/Drawing/DrawParticles.cs similarity index 62% rename from SMCode/SM2D/Drawing/DrawParticles.cs rename to src/renderer/SM2D/Drawing/DrawParticles.cs index 90f469a..e85a302 100644 --- a/SMCode/SM2D/Drawing/DrawParticles.cs +++ b/src/renderer/SM2D/Drawing/DrawParticles.cs @@ -12,7 +12,7 @@ namespace SM2D.Drawing public class DrawParticles : ParticleDrawingBasis { /// - public override Func MovementCalculation { get; set; } = ParticleMovement.Default2D; + public override Func, Vector2> MovementCalculation { get; set; } = ParticleMovement.Default2D; /// /// The direction the particles should travel. @@ -30,7 +30,7 @@ namespace SM2D.Drawing } /// - protected override ParticleStruct CreateObject(int index) + protected override ParticleInstance CreateObject(int index) { Vector2 dir; if (Direction.HasValue) @@ -42,18 +42,26 @@ namespace SM2D.Drawing } else dir = new Vector2(Randomize.GetFloat(-1, 1), Randomize.GetFloat(-1, 1)); - return new ParticleStruct() + var particle = new ParticleInstance() { - Matrix = Matrix4.CreateScale(1), + Matrix = DetachedParticles ? Transform.InWorldSpace : Matrix4.CreateScale(1), + Direction = dir, - Speed = Randomize.GetFloat(MaxSpeed) + + Speed = Randomize.GetFloat(MaxSpeed), + StartLifetime = Lifetime - Randomize.GetFloat(LifetimeRandomize) }; + particle.Lifetime = particle.StartLifetime; + + return particle; } /// - protected override Matrix4 CreateMatrix(ParticleStruct Struct, Vector2 direction) + protected override Matrix4 CreateMatrix(ParticleInstance Struct, Vector2 direction) { - return Struct.Matrix * Matrix4.CreateTranslation(direction.X, direction.Y, 0); + Vector2 pos = direction; + + return Struct.Matrix * Matrix4.CreateTranslation(pos.X, pos.Y, 0); } } } \ No newline at end of file diff --git a/SMCode/SM2D/Drawing/DrawText.cs b/src/renderer/SM2D/Drawing/DrawText.cs similarity index 96% rename from SMCode/SM2D/Drawing/DrawText.cs rename to src/renderer/SM2D/Drawing/DrawText.cs index 3708e5c..32dc642 100644 --- a/SMCode/SM2D/Drawing/DrawText.cs +++ b/src/renderer/SM2D/Drawing/DrawText.cs @@ -41,7 +41,7 @@ namespace SM2D.Drawing base.DrawContext(ref context); context.Instances = _instances; - context.Shader.Draw(context); + Material.Draw(context); } } } \ No newline at end of file diff --git a/SMCode/SM2D/Object/PolyLine.cs b/src/renderer/SM2D/Object/PolyLine.cs similarity index 100% rename from SMCode/SM2D/Object/PolyLine.cs rename to src/renderer/SM2D/Object/PolyLine.cs diff --git a/SMCode/SM2D/Object/Polygon.cs b/src/renderer/SM2D/Object/Polygon.cs similarity index 100% rename from SMCode/SM2D/Object/Polygon.cs rename to src/renderer/SM2D/Object/Polygon.cs diff --git a/SMCode/SM2D/Object/PolygonVertex.cs b/src/renderer/SM2D/Object/PolygonVertex.cs similarity index 100% rename from SMCode/SM2D/Object/PolygonVertex.cs rename to src/renderer/SM2D/Object/PolygonVertex.cs diff --git a/SM_WPF_TEST/OpenTK.dll.config b/src/renderer/SM2D/OpenTK.dll.config similarity index 100% rename from SM_WPF_TEST/OpenTK.dll.config rename to src/renderer/SM2D/OpenTK.dll.config diff --git a/SMCode/SM2D/Pipelines/Basic2DPipeline.cs b/src/renderer/SM2D/Pipelines/Basic2DPipeline.cs similarity index 100% rename from SMCode/SM2D/Pipelines/Basic2DPipeline.cs rename to src/renderer/SM2D/Pipelines/Basic2DPipeline.cs diff --git a/SMCode/SM2D/Properties/AssemblyInfo.cs b/src/renderer/SM2D/Properties/AssemblyInfo.cs similarity index 100% rename from SMCode/SM2D/Properties/AssemblyInfo.cs rename to src/renderer/SM2D/Properties/AssemblyInfo.cs diff --git a/SMCode/SM2D/SM2D.csproj b/src/renderer/SM2D/SM2D.csproj similarity index 86% rename from SMCode/SM2D/SM2D.csproj rename to src/renderer/SM2D/SM2D.csproj index d58b4f3..247194f 100644 --- a/SMCode/SM2D/SM2D.csproj +++ b/src/renderer/SM2D/SM2D.csproj @@ -11,6 +11,7 @@ v4.5.2 512 true + true @@ -30,7 +31,14 @@ prompt 4 + + false + + + ..\..\..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll + True + @@ -53,11 +61,6 @@ - - - 3.3.1 - - @@ -71,5 +74,9 @@ SM.OGL + + + + \ No newline at end of file diff --git a/SMCode/SM2D/SM2D.csproj.DotSettings b/src/renderer/SM2D/SM2D.csproj.DotSettings similarity index 100% rename from SMCode/SM2D/SM2D.csproj.DotSettings rename to src/renderer/SM2D/SM2D.csproj.DotSettings diff --git a/SMCode/SM2D/Scene/Camera.cs b/src/renderer/SM2D/Scene/Camera.cs similarity index 100% rename from SMCode/SM2D/Scene/Camera.cs rename to src/renderer/SM2D/Scene/Camera.cs diff --git a/SMCode/SM2D/Scene/ItemCollection.cs b/src/renderer/SM2D/Scene/ItemCollection.cs similarity index 100% rename from SMCode/SM2D/Scene/ItemCollection.cs rename to src/renderer/SM2D/Scene/ItemCollection.cs diff --git a/SMCode/SM2D/Scene/Scene.cs b/src/renderer/SM2D/Scene/Scene.cs similarity index 100% rename from SMCode/SM2D/Scene/Scene.cs rename to src/renderer/SM2D/Scene/Scene.cs diff --git a/SMCode/SM2D/Shader/ShaderCollection.cs b/src/renderer/SM2D/Shader/ShaderCollection.cs similarity index 93% rename from SMCode/SM2D/Shader/ShaderCollection.cs rename to src/renderer/SM2D/Shader/ShaderCollection.cs index e7dacf8..2886b20 100644 --- a/SMCode/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/SMCode/SM2D/Shader/ShaderFiles/basic.glsl b/src/renderer/SM2D/Shader/ShaderFiles/basic.glsl similarity index 100% rename from SMCode/SM2D/Shader/ShaderFiles/basic.glsl rename to src/renderer/SM2D/Shader/ShaderFiles/basic.glsl diff --git a/SMCode/SM2D/Types/Transformation.cs b/src/renderer/SM2D/Types/Transformation.cs similarity index 100% rename from SMCode/SM2D/Types/Transformation.cs rename to src/renderer/SM2D/Types/Transformation.cs diff --git a/SMCode/SM2D/Window/Window2DSetup.cs b/src/renderer/SM2D/Window/Window2DSetup.cs similarity index 100% rename from SMCode/SM2D/Window/Window2DSetup.cs rename to src/renderer/SM2D/Window/Window2DSetup.cs diff --git a/src/renderer/SM2D/packages.config b/src/renderer/SM2D/packages.config new file mode 100644 index 0000000..1f65eab --- /dev/null +++ b/src/renderer/SM2D/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/SM_TEST/App.config b/tests/SM_TEST/App.config similarity index 59% rename from SM_TEST/App.config rename to tests/SM_TEST/App.config index 88fa402..8227adb 100644 --- a/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/OpenTK.dll.config b/tests/SM_TEST/OpenTK.dll.config new file mode 100644 index 0000000..7098d39 --- /dev/null +++ b/tests/SM_TEST/OpenTK.dll.config @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/SM_TEST/Program.cs b/tests/SM_TEST/Program.cs new file mode 100644 index 0000000..f36bd80 --- /dev/null +++ b/tests/SM_TEST/Program.cs @@ -0,0 +1,116 @@ +using System; +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; +using SM2D; +using SM2D.Controls; +using SM2D.Drawing; +using SM2D.Object; +using SM2D.Scene; +using Font = SM.Base.Drawing.Text.Font; + +namespace SM_TEST +{ + class Program + { + static Scene scene; + private static GLWindow window; + private static GameController controller; + + private static GameKeybindActor actor; + + public static STPProject portal; + static void Main(string[] args){ + Font font = new Font(@".\GapSansBold.ttf") + { + FontSize = 51, + }; + + 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"); + + window = new GLWindow(1280, 720, "0ms", WindowFlags.Window, VSyncMode.Off); + window.ApplySetup(new Window2DSetup()); + window.SetRenderPipeline(new TestRenderPipeline()); + + window.SetScene(scene = new Scene() + { + ShowAxisHelper = true + }); + scene.Background.Color = Color4.DarkGray; + scene.Camera = new Camera() + { + + }; + + 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.RenderFrame += Window_RenderFrame; + window.Run(); + + Debug.WriteLine("Window Closed"); + } + + private static void Window_RenderFrame(object sender, FrameEventArgs e) + { + window.Title = Math.Round(e.Time * 1000,2) + "ms"; + } + } +} \ No newline at end of file diff --git a/SM_TEST/Properties/AssemblyInfo.cs b/tests/SM_TEST/Properties/AssemblyInfo.cs similarity index 100% rename from SM_TEST/Properties/AssemblyInfo.cs rename to tests/SM_TEST/Properties/AssemblyInfo.cs diff --git a/tests/SM_TEST/SM_TEST.csproj b/tests/SM_TEST/SM_TEST.csproj new file mode 100644 index 0000000..3050d81 --- /dev/null +++ b/tests/SM_TEST/SM_TEST.csproj @@ -0,0 +1,107 @@ + + + + + + + Debug + AnyCPU + {6D4FB8E6-4D0B-4928-8F9E-EF5C2FBF44E8} + WinExe + SM_TEST + SM_TEST + v4.5.2 + 512 + true + true + + + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + ..\..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll + + + ..\..\packages\ShaderToolParser.1.0.0-pre3\lib\net450\ShaderToolParser.dll + + + ..\..\packages\SharpDX.4.2.0\lib\net45\SharpDX.dll + + + ..\..\packages\SharpDX.XInput.4.2.0\lib\net45\SharpDX.XInput.dll + + + ..\..\packages\SharpFont.4.0.1\lib\net45\SharpFont.dll + + + + + + + + + + + + + + + + + + + + + + {4cb351f4-b3f2-4f77-acc2-02f21dbf5ec2} + SMRenderer.Intergrations + + + {079BAB31-3DC4-40DA-90C7-EFAA8517C647} + SMRenderer.Utils + + + {8e733844-4204-43e7-b3dc-3913cddabb0d} + SM.Base + + + {f604d684-bc1d-4819-88b5-8b5d03a17be0} + SM.OGL + + + {a4565538-625a-42c6-a330-dd4f1abb3986} + SM2D + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + \ No newline at end of file diff --git a/tests/SM_TEST/TestRenderPipeline.cs b/tests/SM_TEST/TestRenderPipeline.cs new file mode 100644 index 0000000..dcd7b22 --- /dev/null +++ b/tests/SM_TEST/TestRenderPipeline.cs @@ -0,0 +1,64 @@ +using OpenTK.Graphics.OpenGL4; +using SM.Base.Legacy.PostProcessing; +using SM.Base.PostEffects; +using SM.Base.Textures; +using SM.Base.Window; +using SM.Intergrations.ShaderTool; +using SM.OGL.Framebuffer; +using SM.OGL.Texture; + +namespace SM_TEST +{ + public class TestRenderPipeline : RenderPipeline + { + private BloomEffect _bloom; + + private Framebuffer _postBuffer; + private STPostProcessEffect _vittage; + + protected override void InitializationProcess() + { + MainFramebuffer = CreateWindowFramebuffer(8, PixelInformation.RGBA_HDR, true); + _postBuffer = CreateWindowFramebuffer(0, PixelInformation.RGB_HDR, false); + Framebuffers.Add(_postBuffer); + + _bloom = new BloomEffect(true, true) + { + Radius = 20, + AmountMap = new Texture(new System.Drawing.Bitmap("bloom_amountMap.png")) + }; + PostProcessEffects.Add(_bloom); + + _vittage = new STPostProcessEffect(Program.portal.DrawNodes.Find(a => a.Variables.ContainsKey("_ViewportSize"))) + { + Arguments = + { + {"CheckSize", 10f}, + {"Strength", .25f}, + {"TargetSize", 5f}, + {"Move", 3.33f} + } + }; + PostProcessEffects.Add(_vittage); + } + + protected override void RenderProcess(ref DrawContext context) + { + GL.Enable(EnableCap.DepthTest); + MainFramebuffer.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); + context.Scene.DrawBackground(context); + context.Scene.DrawMainObjects(context); + context.Scene.DrawHUD(context); + + GL.Disable(EnableCap.DepthTest); + _postBuffer.Activate(ClearBufferMask.ColorBufferBit); + PostProcessUtility.ResolveMultisampledBuffers(MainFramebuffer, _postBuffer); + + _bloom.Draw(_postBuffer["color"], context); + _vittage.Draw(_postBuffer["color"], context); + Framebuffer.Screen.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); + + PostProcessUtility.FinalizeHDR(_postBuffer["color"], HDRColorCurve.OnlyExposure, .1f); + } + } +} \ No newline at end of file diff --git a/SM_TEST/packages.config b/tests/SM_TEST/packages.config similarity index 54% rename from SM_TEST/packages.config rename to tests/SM_TEST/packages.config index 2a7b555..7b1ca7f 100644 --- a/SM_TEST/packages.config +++ b/tests/SM_TEST/packages.config @@ -1,6 +1,9 @@  + + + \ No newline at end of file