From 2be5c879be22f76a58ecaadc845c695582533141 Mon Sep 17 00:00:00 2001 From: Michel Fedde <35878897+IedSoftworks@users.noreply.github.com> Date: Tue, 11 May 2021 10:30:57 +0200 Subject: [PATCH 01/10] Create README.md --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 README.md 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. From db7f01dca1660d4f5e73603192100c2ea6616630 Mon Sep 17 00:00:00 2001 From: Michel Fedde Date: Tue, 11 May 2021 21:44:45 +0200 Subject: [PATCH 02/10] Rewrote the particles to allow for more advanced particles. + Particles can now be detached from the object. + Each particle now has an own Lifetime, that can be controlled. + Particles can now appear in a continuous way. --- .../Drawing/Particles/ParticleContext.cs | 24 ---- .../Drawing/Particles/ParticleDrawingBasis.cs | 130 +++++++++++++----- .../Drawing/Particles/ParticleInstance.cs | 38 +++++ .../Drawing/Particles/ParticleMovement.cs | 8 +- .../Drawing/Particles/ParticleStruct.cs | 30 ---- SMCode/SM.Base/SM.Base.csproj | 3 +- SMCode/SM.Base/Time/Timer.cs | 2 +- SMCode/SM2D/Drawing/DrawParticles.cs | 23 +++- SM_TEST/Program.cs | 22 +-- 9 files changed, 171 insertions(+), 109 deletions(-) delete mode 100644 SMCode/SM.Base/Drawing/Particles/ParticleContext.cs create mode 100644 SMCode/SM.Base/Drawing/Particles/ParticleInstance.cs delete mode 100644 SMCode/SM.Base/Drawing/Particles/ParticleStruct.cs 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 index 24643db..c49359e 100644 --- a/SMCode/SM.Base/Drawing/Particles/ParticleDrawingBasis.cs +++ b/SMCode/SM.Base/Drawing/Particles/ParticleDrawingBasis.cs @@ -18,6 +18,18 @@ namespace SM.Base.Drawing.Particles 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 @@ -25,24 +37,38 @@ namespace SM.Base.Drawing.Particles public int Amount = 32; /// - /// This contains the different instances for the particles. + /// The base lifetime for particles in seconds. /// - protected List instances; + public float Lifetime; + /// + /// Ranomizes 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; + } + } + + public bool DetachedParticles; /// /// The maximum speed of the particles + /// Default: 25 /// - public float MaxSpeed = 50; - - /// - /// This contains all important information for each particle. - /// - protected ParticleStruct[] particleStructs; - - /// - /// The stopwatch of the particles. - /// - protected Timer timer; + public float MaxSpeed = 25; /// /// Sets up the timer. @@ -51,6 +77,10 @@ namespace SM.Base.Drawing.Particles protected ParticleDrawingBasis(TimeSpan duration) { timer = new Timer(duration); + _continuesInterval = new Interval(0); + _continuesInterval.End += CreateContinuesParticles; + + Lifetime = (float) duration.TotalSeconds; } /// @@ -65,27 +95,29 @@ namespace SM.Base.Drawing.Particles /// /// Controls the movement of each particles. /// - public abstract Func MovementCalculation { get; set; } + public abstract Func, TDirection> MovementCalculation { get; set; } /// public bool UpdateActive { - get => timer.Active; + get => timer.Active || _continuesInterval.Active; set { return; } } /// public void Update(UpdateContext context) { - ParticleContext particleContext = new ParticleContext - { - Timer = timer - }; - for (int i = 0; i < Amount; i++) + for (int i = 0; i < instances.Count; i++) { - particleContext.Speed = particleStructs[i].Speed; - instances[i].ModelMatrix = CreateMatrix(particleStructs[i], - MovementCalculation(particleStructs[i].Direction, particleContext)); + instances[i].Lifetime -= context.Deltatime; + if (instances[i].Lifetime <= 0) + { + instances.Remove(instances[i]); + break; + } + + instances[i].ModelMatrix = CreateMatrix(instances[i], + MovementCalculation(instances[i])); } } @@ -94,19 +126,50 @@ namespace SM.Base.Drawing.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) return; + if (!timer.Active && _continuesInterval != null && !_continuesInterval.Active) return; base.DrawContext(ref context); - context.Instances = instances; + if (DetachedParticles) context.ModelMatrix = Matrix4.Identity; + + context.Instances = instances.ConvertAll(a => (Instance)a); context.Shader.Draw(context); } @@ -116,24 +179,27 @@ namespace SM.Base.Drawing.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()); + instances.Add(CreateObject(i)); } } + private void CreateContinuesParticles(Timer arg1, UpdateContext arg2) + { + instances.Add(CreateObject(instances.Count)); + } + /// /// Creates a particle. /// - protected abstract ParticleStruct CreateObject(int index); + protected abstract ParticleInstance CreateObject(int index); /// /// Generates the desired matrix for drawing. /// - protected abstract Matrix4 CreateMatrix(ParticleStruct Struct, TDirection relativePosition); + protected abstract Matrix4 CreateMatrix(ParticleInstance Struct, TDirection relativePosition); } } \ No newline at end of file diff --git a/SMCode/SM.Base/Drawing/Particles/ParticleInstance.cs b/SMCode/SM.Base/Drawing/Particles/ParticleInstance.cs new file mode 100644 index 0000000..1010414 --- /dev/null +++ b/SMCode/SM.Base/Drawing/Particles/ParticleInstance.cs @@ -0,0 +1,38 @@ +using OpenTK; + +namespace SM.Base.Drawing.Particles +{ + public class ParticleInstance : Instance + { + 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; + + /// + /// The start position. + /// + public TValue StartPosition; + } +} \ No newline at end of file diff --git a/SMCode/SM.Base/Drawing/Particles/ParticleMovement.cs b/SMCode/SM.Base/Drawing/Particles/ParticleMovement.cs index 6fdad6a..cccd773 100644 --- a/SMCode/SM.Base/Drawing/Particles/ParticleMovement.cs +++ b/SMCode/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/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/SM.Base.csproj b/SMCode/SM.Base/SM.Base.csproj index 5e201f9..1efa852 100644 --- a/SMCode/SM.Base/SM.Base.csproj +++ b/SMCode/SM.Base/SM.Base.csproj @@ -62,6 +62,7 @@ + @@ -69,9 +70,7 @@ - - diff --git a/SMCode/SM.Base/Time/Timer.cs b/SMCode/SM.Base/Time/Timer.cs index f6e3c37..15ff2bd 100644 --- a/SMCode/SM.Base/Time/Timer.cs +++ b/SMCode/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/SM2D/Drawing/DrawParticles.cs b/SMCode/SM2D/Drawing/DrawParticles.cs index 90f469a..c01bda2 100644 --- a/SMCode/SM2D/Drawing/DrawParticles.cs +++ b/SMCode/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,27 @@ 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.GetMatrix() : Matrix4.CreateScale(1), + Direction = dir, - Speed = Randomize.GetFloat(MaxSpeed) + StartPosition = Transform.Position, + + 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/SM_TEST/Program.cs b/SM_TEST/Program.cs index 940dcf7..2880498 100644 --- a/SM_TEST/Program.cs +++ b/SM_TEST/Program.cs @@ -12,6 +12,7 @@ using SM.Base.Drawing; using SM.Base.Time; using SM.Base.Window; using SM2D; +using SM2D.Controls; using SM2D.Drawing; using SM2D.Object; using SM2D.Scene; @@ -48,16 +49,17 @@ namespace SM_TEST }; - DrawObject2D test = new DrawObject2D() + particles = new DrawParticles(TimeSpan.FromSeconds(1)) { - Texture = new Bitmap("test.png") + Lifetime = 1f, + ContinuousInterval = .5f, + + Direction = -Vector2.UnitY, + DetachedParticles = true }; - 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); + particles.Transform.Size.Set(50); - scene.Objects.Add(test); + scene.Objects.Add(particles); window.UpdateFrame += WindowOnUpdateFrame; window.RenderFrame += Window_RenderFrame; @@ -74,9 +76,11 @@ namespace SM_TEST private static void WindowOnUpdateFrame(object sender, FrameEventArgs e) { if (Mouse.LeftClick) - interpolation.Stop(); + particles.Trigger(); if (Mouse.RightClick) - interpolation.Stop(false); + particles.ContinuousInterval = .05f; + + particles.Transform.Position.Set(Mouse2D.InWorld(scene.Camera)); } } } \ No newline at end of file From 89de4258e1bec719c04c43626de9459bf6715a43 Mon Sep 17 00:00:00 2001 From: Michel Fedde Date: Fri, 14 May 2021 21:38:50 +0200 Subject: [PATCH 03/10] 1.0.14 NUGET-Changes: + Materials now have a method to draw. That should allow more freedom on how materials can have a effect on the resulting shader. ~ PostProcessEffect.Draw now needs a source ColorAttachment. ~ Added some missing summaries GIT-/SOLUTION-Changes: Remade the folder structure, to something more senseable. --- SMCode/SM3D/SM3D.csproj | 41 ------ SMRendererV3.sln | 41 +++--- SM_WPF_TEST/App.config | 6 - SM_WPF_TEST/App.xaml | 9 -- SM_WPF_TEST/App.xaml.cs | 11 -- SM_WPF_TEST/MainWindow.xaml | 16 --- SM_WPF_TEST/MainWindow.xaml.cs | 32 ----- SM_WPF_TEST/Properties/AssemblyInfo.cs | 53 -------- SM_WPF_TEST/Properties/Resources.Designer.cs | 70 ----------- SM_WPF_TEST/Properties/Resources.resx | 117 ------------------ SM_WPF_TEST/Properties/Settings.Designer.cs | 29 ----- SM_WPF_TEST/Properties/Settings.settings | 7 -- SM_WPF_TEST/SM_WPF_TEST.csproj | 102 --------------- SM_WPF_TEST/Window1.xaml | 12 -- SM_WPF_TEST/Window1.xaml.cs | 30 ----- .../SM.Intergrations}/OpenTK.dll.config | 0 .../Properties/AssemblyInfo.cs | 19 ++- .../SM.Intergrations/SM.Intergrations.csproj | 53 ++++---- .../SM.Intergrations/ShaderTool/STMaterial.cs | 50 ++++++++ .../ShaderTool/STMaterialShader.cs | 70 +++++++++++ .../ShaderTool/STPostProcessEffect.cs | 51 ++++++++ .../ShaderTool/STPostProcessShader.cs | 74 +++++++++++ .../SM.Intergrations/packages.config | 5 + .../SM.Utils}/Controls/GameController.cs | 2 +- .../SM.Utils}/Controls/GameControllerState.cs | 2 +- .../Controls/GameControllerStateButtons.cs | 2 +- .../Controls/GameControllerStateDPad.cs | 2 +- .../Controls/GameControllerStateThumbs.cs | 2 +- .../Controls/GameControllerStateTriggers.cs | 2 +- .../SM.Utils}/Controls/GameKeybind.cs | 4 +- .../SM.Utils}/Controls/GameKeybindActor.cs | 2 +- .../SM.Utils}/Controls/GameKeybindContext.cs | 2 +- .../SM.Utils}/Controls/GameKeybindHost.cs | 2 +- .../SM.Utils}/Controls/GameKeybindList.cs | 2 +- .../optionals/SM.Utils}/OpenTK.dll.config | 0 .../SM.Utils}/Properties/AssemblyInfo.cs | 0 .../optionals/SM.Utils/SM.Utils.csproj | 10 +- .../optionals/SM.Utils}/packages.config | 0 .../SM.Base/Animation/AnimationCurves.cs | 0 .../SM.Base/Animation/InterpolationProcess.cs | 0 .../renderer}/SM.Base/Controls/Keyboard.cs | 0 .../renderer}/SM.Base/Controls/Mouse.cs | 0 .../renderer}/SM.Base/Drawing/DrawingBasis.cs | 0 .../SM.Base/Drawing/GenericTransformation.cs | 0 .../renderer}/SM.Base/Drawing/Instance.cs | 0 .../renderer}/SM.Base/Drawing/Material.cs | 14 ++- .../Drawing/Particles/ParticleDrawingBasis.cs | 19 ++- .../Drawing/Particles/ParticleInstance.cs | 12 +- .../Drawing/Particles/ParticleMovement.cs | 0 .../SM.Base/Drawing/ShaderArguments.cs | 0 .../SM.Base/Drawing/Text/CharParameter.cs | 0 .../renderer}/SM.Base/Drawing/Text/Font.cs | 0 .../SM.Base/Drawing/Text/FontCharStorage.cs | 0 .../SM.Base/Drawing/Text/TextDrawingBasis.cs | 0 .../SM.Base/Drawing/TextureTransformation.cs | 0 .../renderer}/SM.Base/Legacy/Font.cs | 0 {SMCode => src/renderer}/SM.Base/Log.cs | 0 .../SM.Base/Objects/InstancedMesh.cs | 0 .../renderer}/SM.Base/Objects/Mesh.cs | 0 .../SM.Base/Objects/Static/AxisHelper.cs | 0 .../renderer}/SM.Base/Objects/Static/Plate.cs | 0 .../renderer/SM.Base}/OpenTK.dll.config | 0 .../SM.Base/PostEffects/BloomEffect.cs | 7 +- .../SM.Base/PostEffects/PostProcessUtility.cs | 0 .../PostEffects/Shaders/bloom_blur.glsl | 0 .../PostEffects/Shaders/bloom_merge.glsl | 0 .../PostEffects/Shaders/bloom_merge_vert.glsl | 0 .../PostEffects/Shaders/finalize_gamma.glsl | 0 .../PostEffects/Shaders/finalize_hdr.glsl | 0 .../PostProcess/DefaultFiles/extensions.frag | 0 .../PostProcess/DefaultFiles/vertexFile.vert | 0 .../DefaultFiles/vertexWithExt.vert | 0 .../SM.Base/PostProcess/PostProcessEffect.cs | 3 +- .../SM.Base/PostProcess/PostProcessShader.cs | 0 .../SM.Base/Properties/AssemblyInfo.cs | 0 .../renderer}/SM.Base/SM.Base.csproj | 61 +++++---- .../SM.Base/SM.Base.csproj.DotSettings | 0 .../renderer}/SM.Base/SMRenderer.cs | 0 .../renderer}/SM.Base/Scene/GenericCamera.cs | 0 .../SM.Base/Scene/GenericItemCollection.cs | 0 .../renderer}/SM.Base/Scene/GenericScene.cs | 0 .../SM.Base/Scene/IBackgroundItem.cs | 0 .../SM.Base/Scene/ICollectionItem.cs | 0 .../SM.Base/Scene/IFixedScriptable.cs | 0 .../renderer}/SM.Base/Scene/IScriptable.cs | 0 .../SM.Base/Scene/IShowCollection.cs | 0 .../renderer}/SM.Base/Scene/IShowItem.cs | 0 .../Shaders/Extensions/ExtensionManager.cs | 0 .../Shaders/Extensions/fragment/noise.glsl | 0 .../Extensions/fragment/textureGamma.glsl | 0 .../Shaders/Extensions/vertex/basic.vert | 0 .../SM.Base/Shaders/MaterialShader.cs | 4 +- .../renderer}/SM.Base/Shaders/SimpleShader.cs | 0 .../SimpleShaderPresets/basic_vertex.glsl | 0 .../SimpleShaderPresets/instanced_vertex.glsl | 0 .../renderer}/SM.Base/Textures/Texture.cs | 0 .../renderer}/SM.Base/Time/Interval.cs | 0 .../renderer}/SM.Base/Time/Stopwatch.cs | 0 .../renderer}/SM.Base/Time/Timer.cs | 0 .../renderer}/SM.Base/Types/CVector1.cs | 0 .../renderer}/SM.Base/Types/CVector2.cs | 0 .../renderer}/SM.Base/Types/CVector3.cs | 0 .../renderer}/SM.Base/Types/CVector4.cs | 1 - .../renderer}/SM.Base/Types/CVectorBase.cs | 0 .../renderer}/SM.Base/Utility/Assembly.cs | 0 .../renderer}/SM.Base/Utility/Deltatime.cs | 0 .../SM.Base/Utility/IInitializable.cs | 0 .../renderer}/SM.Base/Utility/Randomize.cs | 0 .../renderer}/SM.Base/Utility/Ray.cs | 0 .../SM.Base/Utility/RotationUtility.cs | 0 .../renderer}/SM.Base/Utility/Util.cs | 0 .../SM.Base/Window/Contexts/DrawContext.cs | 0 .../Window/Contexts/FixedUpdateContext.cs | 0 .../SM.Base/Window/Contexts/UpdateContext.cs | 0 .../renderer}/SM.Base/Window/GLWindow.cs | 0 .../SM.Base/Window/IGenericWindow.cs | 0 .../renderer}/SM.Base/Window/ISetup.cs | 0 .../SM.Base/Window/RenderPipeline.cs | 0 .../renderer}/SM.Base/Window/WindowCode.cs | 0 .../renderer}/SM.Base/Window/WindowFlags.cs | 0 .../renderer}/SM.Base/Window/winIcon.ico | Bin .../renderer}/SM.Base/packages.config | 0 .../SM.OGL/Framebuffer/ColorAttachment.cs | 0 .../SM.OGL/Framebuffer/Framebuffer.cs | 0 .../SM.OGL/Framebuffer/IFramebufferWindow.cs | 0 .../Framebuffer/RenderbufferAttachment.cs | 0 .../renderer}/SM.OGL/GLCustomActions.cs | 0 .../renderer}/SM.OGL/GLDebugging.cs | 0 {SMCode => src/renderer}/SM.OGL/GLObject.cs | 0 {SMCode => src/renderer}/SM.OGL/GLSettings.cs | 0 {SMCode => src/renderer}/SM.OGL/GLSystem.cs | 0 .../renderer}/SM.OGL/Mesh/BoundingBox.cs | 0 .../renderer}/SM.OGL/Mesh/GenericMesh.cs | 0 .../renderer}/SM.OGL/Mesh/ILineMesh.cs | 0 .../renderer}/SM.OGL/Mesh/MeshAttribute.cs | 0 .../SM.OGL/Mesh/MeshAttributeList.cs | 0 {SMCode => src/renderer}/SM.OGL/Mesh/VBO.cs | 0 .../renderer/SM.OGL}/OpenTK.dll.config | 0 .../SM.OGL/Properties/AssemblyInfo.cs | 0 {SMCode => src/renderer}/SM.OGL/SM.OGL.csproj | 8 +- .../renderer}/SM.OGL/Shaders/GenericShader.cs | 0 .../renderer}/SM.OGL/Shaders/IUniform.cs | 0 .../SM.OGL/Shaders/ShaderExtensions.cs | 0 .../renderer}/SM.OGL/Shaders/ShaderFile.cs | 0 .../SM.OGL/Shaders/ShaderFileCollection.cs | 0 .../SM.OGL/Shaders/ShaderPreProcess.cs | 0 .../renderer}/SM.OGL/Shaders/Uniform.cs | 0 .../renderer}/SM.OGL/Shaders/UniformArray.cs | 0 .../SM.OGL/Shaders/UniformCollection.cs | 0 .../SM.OGL/Texture/PixelInformation.cs | 0 .../renderer}/SM.OGL/Texture/TextureBase.cs | 0 {SMCode => src/renderer}/SM.OGL/Version.cs | 0 .../renderer}/SM.OGL/packages.config | 0 .../renderer}/SM2D/Controls/Mouse2D.cs | 0 .../renderer}/SM2D/Drawing/DrawBackground.cs | 2 +- .../renderer}/SM2D/Drawing/DrawObject2D.cs | 3 +- .../renderer}/SM2D/Drawing/DrawParticles.cs | 3 +- .../renderer}/SM2D/Drawing/DrawText.cs | 2 +- .../renderer}/SM2D/Object/PolyLine.cs | 0 .../renderer}/SM2D/Object/Polygon.cs | 0 .../renderer}/SM2D/Object/PolygonVertex.cs | 0 .../renderer/SM2D}/OpenTK.dll.config | 0 .../SM2D/Pipelines/Basic2DPipeline.cs | 0 .../renderer}/SM2D/Properties/AssemblyInfo.cs | 0 {SMCode => src/renderer}/SM2D/SM2D.csproj | 12 +- .../renderer}/SM2D/SM2D.csproj.DotSettings | 0 {SMCode => src/renderer}/SM2D/Scene/Camera.cs | 0 .../renderer}/SM2D/Scene/ItemCollection.cs | 0 {SMCode => src/renderer}/SM2D/Scene/Scene.cs | 0 .../renderer}/SM2D/Shader/ShaderCollection.cs | 0 .../SM2D/Shader/ShaderFiles/basic.glsl | 0 .../renderer}/SM2D/Types/Transformation.cs | 0 .../renderer}/SM2D/Window/Window2DSetup.cs | 0 .../renderer/SM2D}/packages.config | 0 {SM_TEST => tests/SM_TEST}/App.config | 0 tests/SM_TEST/OpenTK.dll.config | 25 ++++ {SM_TEST => tests/SM_TEST}/Program.cs | 39 +++--- .../SM_TEST}/Properties/AssemblyInfo.cs | 0 tests/SM_TEST/SM_TEST.csproj | 101 +++++++++++++++ .../SM_TEST}/TestRenderPipeline.cs | 31 +++-- {SM_TEST => tests/SM_TEST}/packages.config | 3 + 181 files changed, 584 insertions(+), 698 deletions(-) delete mode 100644 SMCode/SM3D/SM3D.csproj delete mode 100644 SM_WPF_TEST/App.config delete mode 100644 SM_WPF_TEST/App.xaml delete mode 100644 SM_WPF_TEST/App.xaml.cs delete mode 100644 SM_WPF_TEST/MainWindow.xaml delete mode 100644 SM_WPF_TEST/MainWindow.xaml.cs delete mode 100644 SM_WPF_TEST/Properties/AssemblyInfo.cs delete mode 100644 SM_WPF_TEST/Properties/Resources.Designer.cs delete mode 100644 SM_WPF_TEST/Properties/Resources.resx delete mode 100644 SM_WPF_TEST/Properties/Settings.Designer.cs delete mode 100644 SM_WPF_TEST/Properties/Settings.settings delete mode 100644 SM_WPF_TEST/SM_WPF_TEST.csproj delete mode 100644 SM_WPF_TEST/Window1.xaml delete mode 100644 SM_WPF_TEST/Window1.xaml.cs rename {SMCode/SM.Base => src/optionals/SM.Intergrations}/OpenTK.dll.config (100%) rename {SMCode/SM3D => src/optionals/SM.Intergrations}/Properties/AssemblyInfo.cs (75%) rename SM_TEST/SM_TEST.csproj => src/optionals/SM.Intergrations/SM.Intergrations.csproj (63%) create mode 100644 src/optionals/SM.Intergrations/ShaderTool/STMaterial.cs create mode 100644 src/optionals/SM.Intergrations/ShaderTool/STMaterialShader.cs create mode 100644 src/optionals/SM.Intergrations/ShaderTool/STPostProcessEffect.cs create mode 100644 src/optionals/SM.Intergrations/ShaderTool/STPostProcessShader.cs create mode 100644 src/optionals/SM.Intergrations/packages.config rename {SMOptionals/SM.Game => src/optionals/SM.Utils}/Controls/GameController.cs (96%) rename {SMOptionals/SM.Game => src/optionals/SM.Utils}/Controls/GameControllerState.cs (98%) rename {SMOptionals/SM.Game => src/optionals/SM.Utils}/Controls/GameControllerStateButtons.cs (97%) rename {SMOptionals/SM.Game => src/optionals/SM.Utils}/Controls/GameControllerStateDPad.cs (96%) rename {SMOptionals/SM.Game => src/optionals/SM.Utils}/Controls/GameControllerStateThumbs.cs (94%) rename {SMOptionals/SM.Game => src/optionals/SM.Utils}/Controls/GameControllerStateTriggers.cs (90%) rename {SMOptionals/SM.Game => src/optionals/SM.Utils}/Controls/GameKeybind.cs (90%) rename {SMOptionals/SM.Game => src/optionals/SM.Utils}/Controls/GameKeybindActor.cs (98%) rename {SMOptionals/SM.Game => src/optionals/SM.Utils}/Controls/GameKeybindContext.cs (92%) rename {SMOptionals/SM.Game => src/optionals/SM.Utils}/Controls/GameKeybindHost.cs (97%) rename {SMOptionals/SM.Game => src/optionals/SM.Utils}/Controls/GameKeybindList.cs (95%) rename {SMCode/SM.OGL => src/optionals/SM.Utils}/OpenTK.dll.config (100%) rename {SMOptionals/SM.Game => src/optionals/SM.Utils}/Properties/AssemblyInfo.cs (100%) rename SMOptionals/SM.Game/SM.Game.csproj => src/optionals/SM.Utils/SM.Utils.csproj (89%) rename {SMOptionals/SM.Game => src/optionals/SM.Utils}/packages.config (100%) rename {SMCode => src/renderer}/SM.Base/Animation/AnimationCurves.cs (100%) rename {SMCode => src/renderer}/SM.Base/Animation/InterpolationProcess.cs (100%) rename {SMCode => src/renderer}/SM.Base/Controls/Keyboard.cs (100%) rename {SMCode => src/renderer}/SM.Base/Controls/Mouse.cs (100%) rename {SMCode => src/renderer}/SM.Base/Drawing/DrawingBasis.cs (100%) rename {SMCode => src/renderer}/SM.Base/Drawing/GenericTransformation.cs (100%) rename {SMCode => src/renderer}/SM.Base/Drawing/Instance.cs (100%) rename {SMCode => src/renderer}/SM.Base/Drawing/Material.cs (68%) rename {SMCode => src/renderer}/SM.Base/Drawing/Particles/ParticleDrawingBasis.cs (91%) rename {SMCode => src/renderer}/SM.Base/Drawing/Particles/ParticleInstance.cs (83%) rename {SMCode => src/renderer}/SM.Base/Drawing/Particles/ParticleMovement.cs (100%) rename {SMCode => src/renderer}/SM.Base/Drawing/ShaderArguments.cs (100%) rename {SMCode => src/renderer}/SM.Base/Drawing/Text/CharParameter.cs (100%) rename {SMCode => src/renderer}/SM.Base/Drawing/Text/Font.cs (100%) rename {SMCode => src/renderer}/SM.Base/Drawing/Text/FontCharStorage.cs (100%) rename {SMCode => src/renderer}/SM.Base/Drawing/Text/TextDrawingBasis.cs (100%) rename {SMCode => src/renderer}/SM.Base/Drawing/TextureTransformation.cs (100%) rename {SMCode => src/renderer}/SM.Base/Legacy/Font.cs (100%) rename {SMCode => src/renderer}/SM.Base/Log.cs (100%) rename {SMCode => src/renderer}/SM.Base/Objects/InstancedMesh.cs (100%) rename {SMCode => src/renderer}/SM.Base/Objects/Mesh.cs (100%) rename {SMCode => src/renderer}/SM.Base/Objects/Static/AxisHelper.cs (100%) rename {SMCode => src/renderer}/SM.Base/Objects/Static/Plate.cs (100%) rename {SMOptionals/SM.Game => src/renderer/SM.Base}/OpenTK.dll.config (100%) rename {SMCode => src/renderer}/SM.Base/PostEffects/BloomEffect.cs (97%) rename {SMCode => src/renderer}/SM.Base/PostEffects/PostProcessUtility.cs (100%) rename {SMCode => src/renderer}/SM.Base/PostEffects/Shaders/bloom_blur.glsl (100%) rename {SMCode => src/renderer}/SM.Base/PostEffects/Shaders/bloom_merge.glsl (100%) rename {SMCode => src/renderer}/SM.Base/PostEffects/Shaders/bloom_merge_vert.glsl (100%) rename {SMCode => src/renderer}/SM.Base/PostEffects/Shaders/finalize_gamma.glsl (100%) rename {SMCode => src/renderer}/SM.Base/PostEffects/Shaders/finalize_hdr.glsl (100%) rename {SMCode => src/renderer}/SM.Base/PostProcess/DefaultFiles/extensions.frag (100%) rename {SMCode => src/renderer}/SM.Base/PostProcess/DefaultFiles/vertexFile.vert (100%) rename {SMCode => src/renderer}/SM.Base/PostProcess/DefaultFiles/vertexWithExt.vert (100%) rename {SMCode => src/renderer}/SM.Base/PostProcess/PostProcessEffect.cs (92%) rename {SMCode => src/renderer}/SM.Base/PostProcess/PostProcessShader.cs (100%) rename {SMCode => src/renderer}/SM.Base/Properties/AssemblyInfo.cs (100%) rename {SMCode => src/renderer}/SM.Base/SM.Base.csproj (89%) rename {SMCode => src/renderer}/SM.Base/SM.Base.csproj.DotSettings (100%) rename {SMCode => src/renderer}/SM.Base/SMRenderer.cs (100%) rename {SMCode => src/renderer}/SM.Base/Scene/GenericCamera.cs (100%) rename {SMCode => src/renderer}/SM.Base/Scene/GenericItemCollection.cs (100%) rename {SMCode => src/renderer}/SM.Base/Scene/GenericScene.cs (100%) rename {SMCode => src/renderer}/SM.Base/Scene/IBackgroundItem.cs (100%) rename {SMCode => src/renderer}/SM.Base/Scene/ICollectionItem.cs (100%) rename {SMCode => src/renderer}/SM.Base/Scene/IFixedScriptable.cs (100%) rename {SMCode => src/renderer}/SM.Base/Scene/IScriptable.cs (100%) rename {SMCode => src/renderer}/SM.Base/Scene/IShowCollection.cs (100%) rename {SMCode => src/renderer}/SM.Base/Scene/IShowItem.cs (100%) rename {SMCode => src/renderer}/SM.Base/Shaders/Extensions/ExtensionManager.cs (100%) rename {SMCode => src/renderer}/SM.Base/Shaders/Extensions/fragment/noise.glsl (100%) rename {SMCode => src/renderer}/SM.Base/Shaders/Extensions/fragment/textureGamma.glsl (100%) rename {SMCode => src/renderer}/SM.Base/Shaders/Extensions/vertex/basic.vert (100%) rename {SMCode => src/renderer}/SM.Base/Shaders/MaterialShader.cs (88%) rename {SMCode => src/renderer}/SM.Base/Shaders/SimpleShader.cs (100%) rename {SMCode => src/renderer}/SM.Base/Shaders/SimpleShaderPresets/basic_vertex.glsl (100%) rename {SMCode => src/renderer}/SM.Base/Shaders/SimpleShaderPresets/instanced_vertex.glsl (100%) rename {SMCode => src/renderer}/SM.Base/Textures/Texture.cs (100%) rename {SMCode => src/renderer}/SM.Base/Time/Interval.cs (100%) rename {SMCode => src/renderer}/SM.Base/Time/Stopwatch.cs (100%) rename {SMCode => src/renderer}/SM.Base/Time/Timer.cs (100%) rename {SMCode => src/renderer}/SM.Base/Types/CVector1.cs (100%) rename {SMCode => src/renderer}/SM.Base/Types/CVector2.cs (100%) rename {SMCode => src/renderer}/SM.Base/Types/CVector3.cs (100%) rename {SMCode => src/renderer}/SM.Base/Types/CVector4.cs (99%) rename {SMCode => src/renderer}/SM.Base/Types/CVectorBase.cs (100%) rename {SMCode => src/renderer}/SM.Base/Utility/Assembly.cs (100%) rename {SMCode => src/renderer}/SM.Base/Utility/Deltatime.cs (100%) rename {SMCode => src/renderer}/SM.Base/Utility/IInitializable.cs (100%) rename {SMCode => src/renderer}/SM.Base/Utility/Randomize.cs (100%) rename {SMCode => src/renderer}/SM.Base/Utility/Ray.cs (100%) rename {SMCode => src/renderer}/SM.Base/Utility/RotationUtility.cs (100%) rename {SMCode => src/renderer}/SM.Base/Utility/Util.cs (100%) rename {SMCode => src/renderer}/SM.Base/Window/Contexts/DrawContext.cs (100%) rename {SMCode => src/renderer}/SM.Base/Window/Contexts/FixedUpdateContext.cs (100%) rename {SMCode => src/renderer}/SM.Base/Window/Contexts/UpdateContext.cs (100%) rename {SMCode => src/renderer}/SM.Base/Window/GLWindow.cs (100%) rename {SMCode => src/renderer}/SM.Base/Window/IGenericWindow.cs (100%) rename {SMCode => src/renderer}/SM.Base/Window/ISetup.cs (100%) rename {SMCode => src/renderer}/SM.Base/Window/RenderPipeline.cs (100%) rename {SMCode => src/renderer}/SM.Base/Window/WindowCode.cs (100%) rename {SMCode => src/renderer}/SM.Base/Window/WindowFlags.cs (100%) rename {SMCode => src/renderer}/SM.Base/Window/winIcon.ico (100%) rename {SMCode => src/renderer}/SM.Base/packages.config (100%) rename {SMCode => src/renderer}/SM.OGL/Framebuffer/ColorAttachment.cs (100%) rename {SMCode => src/renderer}/SM.OGL/Framebuffer/Framebuffer.cs (100%) rename {SMCode => src/renderer}/SM.OGL/Framebuffer/IFramebufferWindow.cs (100%) rename {SMCode => src/renderer}/SM.OGL/Framebuffer/RenderbufferAttachment.cs (100%) rename {SMCode => src/renderer}/SM.OGL/GLCustomActions.cs (100%) rename {SMCode => src/renderer}/SM.OGL/GLDebugging.cs (100%) rename {SMCode => src/renderer}/SM.OGL/GLObject.cs (100%) rename {SMCode => src/renderer}/SM.OGL/GLSettings.cs (100%) rename {SMCode => src/renderer}/SM.OGL/GLSystem.cs (100%) rename {SMCode => src/renderer}/SM.OGL/Mesh/BoundingBox.cs (100%) rename {SMCode => src/renderer}/SM.OGL/Mesh/GenericMesh.cs (100%) rename {SMCode => src/renderer}/SM.OGL/Mesh/ILineMesh.cs (100%) rename {SMCode => src/renderer}/SM.OGL/Mesh/MeshAttribute.cs (100%) rename {SMCode => src/renderer}/SM.OGL/Mesh/MeshAttributeList.cs (100%) rename {SMCode => src/renderer}/SM.OGL/Mesh/VBO.cs (100%) rename {SM_TEST => src/renderer/SM.OGL}/OpenTK.dll.config (100%) rename {SMCode => src/renderer}/SM.OGL/Properties/AssemblyInfo.cs (100%) rename {SMCode => src/renderer}/SM.OGL/SM.OGL.csproj (97%) rename {SMCode => src/renderer}/SM.OGL/Shaders/GenericShader.cs (100%) rename {SMCode => src/renderer}/SM.OGL/Shaders/IUniform.cs (100%) rename {SMCode => src/renderer}/SM.OGL/Shaders/ShaderExtensions.cs (100%) rename {SMCode => src/renderer}/SM.OGL/Shaders/ShaderFile.cs (100%) rename {SMCode => src/renderer}/SM.OGL/Shaders/ShaderFileCollection.cs (100%) rename {SMCode => src/renderer}/SM.OGL/Shaders/ShaderPreProcess.cs (100%) rename {SMCode => src/renderer}/SM.OGL/Shaders/Uniform.cs (100%) rename {SMCode => src/renderer}/SM.OGL/Shaders/UniformArray.cs (100%) rename {SMCode => src/renderer}/SM.OGL/Shaders/UniformCollection.cs (100%) rename {SMCode => src/renderer}/SM.OGL/Texture/PixelInformation.cs (100%) rename {SMCode => src/renderer}/SM.OGL/Texture/TextureBase.cs (100%) rename {SMCode => src/renderer}/SM.OGL/Version.cs (100%) rename {SMCode => src/renderer}/SM.OGL/packages.config (100%) rename {SMCode => src/renderer}/SM2D/Controls/Mouse2D.cs (100%) rename {SMCode => src/renderer}/SM2D/Drawing/DrawBackground.cs (98%) rename {SMCode => src/renderer}/SM2D/Drawing/DrawObject2D.cs (97%) rename {SMCode => src/renderer}/SM2D/Drawing/DrawParticles.cs (93%) rename {SMCode => src/renderer}/SM2D/Drawing/DrawText.cs (96%) rename {SMCode => src/renderer}/SM2D/Object/PolyLine.cs (100%) rename {SMCode => src/renderer}/SM2D/Object/Polygon.cs (100%) rename {SMCode => src/renderer}/SM2D/Object/PolygonVertex.cs (100%) rename {SM_WPF_TEST => src/renderer/SM2D}/OpenTK.dll.config (100%) rename {SMCode => src/renderer}/SM2D/Pipelines/Basic2DPipeline.cs (100%) rename {SMCode => src/renderer}/SM2D/Properties/AssemblyInfo.cs (100%) rename {SMCode => src/renderer}/SM2D/SM2D.csproj (90%) rename {SMCode => src/renderer}/SM2D/SM2D.csproj.DotSettings (100%) rename {SMCode => src/renderer}/SM2D/Scene/Camera.cs (100%) rename {SMCode => src/renderer}/SM2D/Scene/ItemCollection.cs (100%) rename {SMCode => src/renderer}/SM2D/Scene/Scene.cs (100%) rename {SMCode => src/renderer}/SM2D/Shader/ShaderCollection.cs (100%) rename {SMCode => src/renderer}/SM2D/Shader/ShaderFiles/basic.glsl (100%) rename {SMCode => src/renderer}/SM2D/Types/Transformation.cs (100%) rename {SMCode => src/renderer}/SM2D/Window/Window2DSetup.cs (100%) rename {SM_WPF_TEST => src/renderer/SM2D}/packages.config (100%) rename {SM_TEST => tests/SM_TEST}/App.config (100%) create mode 100644 tests/SM_TEST/OpenTK.dll.config rename {SM_TEST => tests/SM_TEST}/Program.cs (68%) rename {SM_TEST => tests/SM_TEST}/Properties/AssemblyInfo.cs (100%) create mode 100644 tests/SM_TEST/SM_TEST.csproj rename {SM_TEST => tests/SM_TEST}/TestRenderPipeline.cs (59%) rename {SM_TEST => tests/SM_TEST}/packages.config (54%) 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/SMRendererV3.sln b/SMRendererV3.sln index 93ce3e3..753bfc7 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}") = "SM.Utils", "src\optionals\SM.Utils\SM.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}") = "SM.Intergrations", "src\optionals\SM.Intergrations\SM.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_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/SM.Intergrations.csproj similarity index 63% rename from SM_TEST/SM_TEST.csproj rename to src/optionals/SM.Intergrations/SM.Intergrations.csproj index 5cd19ac..aeea189 100644 --- a/SM_TEST/SM_TEST.csproj +++ b/src/optionals/SM.Intergrations/SM.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..84022fc --- /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; + + ShaderFileFiles.Vertex = new[] { new ShaderFile(composeNode.Vertex.ShaderCode) }; + ShaderFileFiles.Fragment = new [] {new ShaderFile(composeNode.Fragment.ShaderCode)}; + if (composeNode.Geometry != null) + ShaderFileFiles.Geometry = new[] {new ShaderFile(composeNode.Geometry.ShaderCode)}; + + foreach (KeyValuePair pair in drawNode.Variables) + { + switch (pair.Value.Type) + { + case STPBasisType.Bool: + _uniforms += context => Uniforms[pair.Key].SetUniform1(context.Material.ShaderArguments.Get(pair.Key, false)); + break; + case STPBasisType.Float: + _uniforms += context => Uniforms[pair.Key].SetUniform1(context.Material.ShaderArguments.Get(pair.Key, 0.0f)); + break; + case STPBasisType.Vector2: + _uniforms += context => Uniforms[pair.Key].SetUniform2(context.Material.ShaderArguments.Get(pair.Key, Vector2.Zero)); + break; + case STPBasisType.Vector3: + _uniforms += context => Uniforms[pair.Key].SetUniform3(context.Material.ShaderArguments.Get(pair.Key, Vector3.Zero)); + break; + case STPBasisType.Vector4: + _uniforms += context => + Uniforms[pair.Key].SetUniform4(context.Material.ShaderArguments.Get(pair.Key, Vector4.Zero)); + 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..f62445c --- /dev/null +++ b/src/optionals/SM.Intergrations/ShaderTool/STPostProcessEffect.cs @@ -0,0 +1,51 @@ +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; + + 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); + } + } + } + + public override void Draw(ColorAttachment source, DrawContext context) + { + Arguments["_Scene"] = (TextureBase)source; + Arguments["_MVP"] = Mvp; + Arguments["_ViewportSize"] = context.Window.WindowSize; + + _shader.Draw(Arguments); + } + } +} \ 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..35a1b4c --- /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; + + ShaderFileFiles.Vertex = new[] { new ShaderFile(composeNode.Vertex.ShaderCode) }; + ShaderFileFiles.Fragment = new[] { new ShaderFile(composeNode.Fragment.ShaderCode) }; + if (composeNode.Geometry != null) + ShaderFileFiles.Geometry = new[] { new ShaderFile(composeNode.Geometry.ShaderCode) }; + + foreach (KeyValuePair pair in postProcessNode.Variables) + { + switch (pair.Value.Type) + { + case STPBasisType.Bool: + _uniforms += context => Uniforms[pair.Key].SetUniform1(context.Get(pair.Key, false)); + break; + case STPBasisType.Float: + _uniforms += context => Uniforms[pair.Key].SetUniform1(context.Get(pair.Key, 0.0f)); + break; + case STPBasisType.Vector2: + _uniforms += context => Uniforms[pair.Key].SetUniform2(context.Get(pair.Key, Vector2.Zero)); + break; + case STPBasisType.Vector3: + _uniforms += context => Uniforms[pair.Key].SetUniform3(context.Get(pair.Key, Vector3.Zero)); + break; + case STPBasisType.Vector4: + _uniforms += context => + Uniforms[pair.Key].SetUniform4(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/src/optionals/SM.Intergrations/packages.config b/src/optionals/SM.Intergrations/packages.config new file mode 100644 index 0000000..12fbc5b --- /dev/null +++ b/src/optionals/SM.Intergrations/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/SMOptionals/SM.Game/Controls/GameController.cs b/src/optionals/SM.Utils/Controls/GameController.cs similarity index 96% rename from SMOptionals/SM.Game/Controls/GameController.cs rename to src/optionals/SM.Utils/Controls/GameController.cs index 65f41dd..af6d989 100644 --- a/SMOptionals/SM.Game/Controls/GameController.cs +++ b/src/optionals/SM.Utils/Controls/GameController.cs @@ -1,6 +1,6 @@ using SharpDX.XInput; -namespace SM.Game.Controls +namespace SM.Optionals.Controls { public struct GameController { diff --git a/SMOptionals/SM.Game/Controls/GameControllerState.cs b/src/optionals/SM.Utils/Controls/GameControllerState.cs similarity index 98% rename from SMOptionals/SM.Game/Controls/GameControllerState.cs rename to src/optionals/SM.Utils/Controls/GameControllerState.cs index 414a2ae..4b661a2 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.Optionals.Controls { public struct GameControllerState { diff --git a/SMOptionals/SM.Game/Controls/GameControllerStateButtons.cs b/src/optionals/SM.Utils/Controls/GameControllerStateButtons.cs similarity index 97% rename from SMOptionals/SM.Game/Controls/GameControllerStateButtons.cs rename to src/optionals/SM.Utils/Controls/GameControllerStateButtons.cs index 57aca8c..7ee7763 100644 --- a/SMOptionals/SM.Game/Controls/GameControllerStateButtons.cs +++ b/src/optionals/SM.Utils/Controls/GameControllerStateButtons.cs @@ -1,6 +1,6 @@ using SharpDX.XInput; -namespace SM.Game.Controls +namespace SM.Optionals.Controls { public struct GameControllerStateButtons { diff --git a/SMOptionals/SM.Game/Controls/GameControllerStateDPad.cs b/src/optionals/SM.Utils/Controls/GameControllerStateDPad.cs similarity index 96% rename from SMOptionals/SM.Game/Controls/GameControllerStateDPad.cs rename to src/optionals/SM.Utils/Controls/GameControllerStateDPad.cs index 5385e60..e5308a6 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.Optionals.Controls { public struct GameControllerStateDPad { diff --git a/SMOptionals/SM.Game/Controls/GameControllerStateThumbs.cs b/src/optionals/SM.Utils/Controls/GameControllerStateThumbs.cs similarity index 94% rename from SMOptionals/SM.Game/Controls/GameControllerStateThumbs.cs rename to src/optionals/SM.Utils/Controls/GameControllerStateThumbs.cs index 1d4eefd..eba90e6 100644 --- a/SMOptionals/SM.Game/Controls/GameControllerStateThumbs.cs +++ b/src/optionals/SM.Utils/Controls/GameControllerStateThumbs.cs @@ -1,6 +1,6 @@ using OpenTK; -namespace SM.Game.Controls +namespace SM.Optionals.Controls { public struct GameControllerStateThumbs { diff --git a/SMOptionals/SM.Game/Controls/GameControllerStateTriggers.cs b/src/optionals/SM.Utils/Controls/GameControllerStateTriggers.cs similarity index 90% rename from SMOptionals/SM.Game/Controls/GameControllerStateTriggers.cs rename to src/optionals/SM.Utils/Controls/GameControllerStateTriggers.cs index 3c99852..13ee4cb 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.Optionals.Controls { public struct GameControllerStateTriggers { 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..1f1e823 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.Optionals.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 98% rename from SMOptionals/SM.Game/Controls/GameKeybindActor.cs rename to src/optionals/SM.Utils/Controls/GameKeybindActor.cs index c0527c3..66a583f 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.Optionals.Controls { public enum GameKeybindActorType { diff --git a/SMOptionals/SM.Game/Controls/GameKeybindContext.cs b/src/optionals/SM.Utils/Controls/GameKeybindContext.cs similarity index 92% rename from SMOptionals/SM.Game/Controls/GameKeybindContext.cs rename to src/optionals/SM.Utils/Controls/GameKeybindContext.cs index 08b6cb4..f3c6d9b 100644 --- a/SMOptionals/SM.Game/Controls/GameKeybindContext.cs +++ b/src/optionals/SM.Utils/Controls/GameKeybindContext.cs @@ -1,6 +1,6 @@ using OpenTK.Input; -namespace SM.Game.Controls +namespace SM.Optionals.Controls { public struct GameKeybindContext { 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..9c35ed1 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.Optionals.Controls { public class GameKeybindHost { diff --git a/SMOptionals/SM.Game/Controls/GameKeybindList.cs b/src/optionals/SM.Utils/Controls/GameKeybindList.cs similarity index 95% rename from SMOptionals/SM.Game/Controls/GameKeybindList.cs rename to src/optionals/SM.Utils/Controls/GameKeybindList.cs index 97662e1..2e37d86 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.Optionals.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/SM.Utils.csproj similarity index 89% rename from SMOptionals/SM.Game/SM.Game.csproj rename to src/optionals/SM.Utils/SM.Utils.csproj index cf248b4..92fd385 100644 --- a/SMOptionals/SM.Game/SM.Game.csproj +++ b/src/optionals/SM.Utils/SM.Utils.csproj @@ -7,8 +7,8 @@ {079BAB31-3DC4-40DA-90C7-EFAA8517C647} Library Properties - SM.Game - SM.Game + SM.Utils + SM.Utils v4.5.2 512 true @@ -32,13 +32,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 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 100% rename from SMCode/SM.Base/Controls/Mouse.cs rename to src/renderer/SM.Base/Controls/Mouse.cs 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 100% rename from SMCode/SM.Base/Drawing/GenericTransformation.cs rename to src/renderer/SM.Base/Drawing/GenericTransformation.cs 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 68% rename from SMCode/SM.Base/Drawing/Material.cs rename to src/renderer/SM.Base/Drawing/Material.cs index 3f14675..dc8c8fb 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,31 @@ 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(); + + public virtual void Draw(DrawContext context) + { + context.Shader.Draw(context); + } } } \ No newline at end of file diff --git a/SMCode/SM.Base/Drawing/Particles/ParticleDrawingBasis.cs b/src/renderer/SM.Base/Drawing/Particles/ParticleDrawingBasis.cs similarity index 91% rename from SMCode/SM.Base/Drawing/Particles/ParticleDrawingBasis.cs rename to src/renderer/SM.Base/Drawing/Particles/ParticleDrawingBasis.cs index c49359e..8461927 100644 --- a/SMCode/SM.Base/Drawing/Particles/ParticleDrawingBasis.cs +++ b/src/renderer/SM.Base/Drawing/Particles/ParticleDrawingBasis.cs @@ -6,6 +6,7 @@ using OpenTK; using SM.Base.Scene; using SM.Base.Time; using SM.Base.Window; +using Stopwatch = System.Diagnostics.Stopwatch; #endregion @@ -41,7 +42,7 @@ namespace SM.Base.Drawing.Particles /// public float Lifetime; /// - /// Ranomizes the lifetime for particles. + /// Randomizes the lifetime for particles. /// public float LifetimeRandomize = 0; @@ -62,6 +63,9 @@ namespace SM.Base.Drawing.Particles } } + /// + /// If true, the particles will spawn in Worldspace and can't be moved by the transformation. + /// public bool DetachedParticles; /// @@ -106,7 +110,8 @@ namespace SM.Base.Drawing.Particles /// public void Update(UpdateContext context) { - + Stopwatch stp = new Stopwatch(); + stp.Start(); for (int i = 0; i < instances.Count; i++) { instances[i].Lifetime -= context.Deltatime; @@ -116,9 +121,10 @@ namespace SM.Base.Drawing.Particles break; } - instances[i].ModelMatrix = CreateMatrix(instances[i], - MovementCalculation(instances[i])); + instances[i].ModelMatrix = CreateMatrix(instances[i], MovementCalculation(instances[i])); } + + Console.WriteLine(); } /// @@ -153,6 +159,7 @@ namespace SM.Base.Drawing.Particles timer.Stop(); } + /// public override void OnRemoved(object sender) { base.OnRemoved(sender); @@ -171,7 +178,7 @@ namespace SM.Base.Drawing.Particles context.Instances = instances.ConvertAll(a => (Instance)a); - context.Shader.Draw(context); + Material.Draw(context); } /// @@ -189,7 +196,7 @@ namespace SM.Base.Drawing.Particles private void CreateContinuesParticles(Timer arg1, UpdateContext arg2) { - instances.Add(CreateObject(instances.Count)); + instances.Add(CreateObject(0)); } /// diff --git a/SMCode/SM.Base/Drawing/Particles/ParticleInstance.cs b/src/renderer/SM.Base/Drawing/Particles/ParticleInstance.cs similarity index 83% rename from SMCode/SM.Base/Drawing/Particles/ParticleInstance.cs rename to src/renderer/SM.Base/Drawing/Particles/ParticleInstance.cs index 1010414..9b94926 100644 --- a/SMCode/SM.Base/Drawing/Particles/ParticleInstance.cs +++ b/src/renderer/SM.Base/Drawing/Particles/ParticleInstance.cs @@ -2,8 +2,14 @@ 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; /// @@ -22,6 +28,7 @@ namespace SM.Base.Drawing.Particles public float Speed; } + /// public class ParticleInstance : ParticleInstance where TValue : struct { @@ -29,10 +36,5 @@ namespace SM.Base.Drawing.Particles /// A direction, that the particle should travel. /// public TValue Direction; - - /// - /// The start position. - /// - public TValue StartPosition; } } \ 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 100% rename from SMCode/SM.Base/Drawing/Particles/ParticleMovement.cs rename to src/renderer/SM.Base/Drawing/Particles/ParticleMovement.cs 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 100% rename from SMCode/SM.Base/Drawing/Text/Font.cs rename to src/renderer/SM.Base/Drawing/Text/Font.cs 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 100% rename from SMCode/SM.Base/Drawing/Text/TextDrawingBasis.cs rename to src/renderer/SM.Base/Drawing/Text/TextDrawingBasis.cs 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/Legacy/Font.cs b/src/renderer/SM.Base/Legacy/Font.cs similarity index 100% rename from SMCode/SM.Base/Legacy/Font.cs rename to src/renderer/SM.Base/Legacy/Font.cs diff --git a/SMCode/SM.Base/Log.cs b/src/renderer/SM.Base/Log.cs similarity index 100% rename from SMCode/SM.Base/Log.cs rename to src/renderer/SM.Base/Log.cs 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/SMCode/SM.Base/PostEffects/BloomEffect.cs b/src/renderer/SM.Base/PostEffects/BloomEffect.cs similarity index 97% rename from SMCode/SM.Base/PostEffects/BloomEffect.cs rename to src/renderer/SM.Base/PostEffects/BloomEffect.cs index 9b3d279..fe8426b 100644 --- a/SMCode/SM.Base/PostEffects/BloomEffect.cs +++ b/src/renderer/SM.Base/PostEffects/BloomEffect.cs @@ -1,5 +1,6 @@ #region usings +using System.Drawing; using OpenTK; using OpenTK.Graphics.OpenGL4; using SM.Base.Drawing; @@ -155,7 +156,7 @@ namespace SM.Base.PostEffects } /// - public override void Draw(DrawContext context) + public override void Draw(ColorAttachment source, DrawContext context) { if (Enable) { @@ -171,7 +172,7 @@ namespace SM.Base.PostEffects _shader.Draw(collection => { - collection["renderedTexture"].SetTexture(first ? _source.ColorAttachments["color"] : (hoz ? _yBuffer : _xBuffer)); + collection["renderedTexture"].SetTexture(first ? source : (hoz ? _yBuffer : _xBuffer)); collection["First"].SetUniform1(first); collection["Threshold"].SetUniform1(Threshold); @@ -195,7 +196,7 @@ namespace SM.Base.PostEffects _mergeShader.Draw(collection => { - collection["Scene"].SetTexture(_source.ColorAttachments["color"]); + collection["Scene"].SetTexture(source); collection["Bloom"].SetTexture(_yBuffer); collection["MinAmount"].SetUniform1(MinAmount); diff --git a/SMCode/SM.Base/PostEffects/PostProcessUtility.cs b/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs similarity index 100% rename from SMCode/SM.Base/PostEffects/PostProcessUtility.cs rename to src/renderer/SM.Base/PostEffects/PostProcessUtility.cs diff --git a/SMCode/SM.Base/PostEffects/Shaders/bloom_blur.glsl b/src/renderer/SM.Base/PostEffects/Shaders/bloom_blur.glsl similarity index 100% rename from SMCode/SM.Base/PostEffects/Shaders/bloom_blur.glsl rename to src/renderer/SM.Base/PostEffects/Shaders/bloom_blur.glsl diff --git a/SMCode/SM.Base/PostEffects/Shaders/bloom_merge.glsl b/src/renderer/SM.Base/PostEffects/Shaders/bloom_merge.glsl similarity index 100% rename from SMCode/SM.Base/PostEffects/Shaders/bloom_merge.glsl rename to src/renderer/SM.Base/PostEffects/Shaders/bloom_merge.glsl diff --git a/SMCode/SM.Base/PostEffects/Shaders/bloom_merge_vert.glsl b/src/renderer/SM.Base/PostEffects/Shaders/bloom_merge_vert.glsl similarity index 100% rename from SMCode/SM.Base/PostEffects/Shaders/bloom_merge_vert.glsl rename to src/renderer/SM.Base/PostEffects/Shaders/bloom_merge_vert.glsl 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/SMCode/SM.Base/PostEffects/Shaders/finalize_hdr.glsl b/src/renderer/SM.Base/PostEffects/Shaders/finalize_hdr.glsl similarity index 100% rename from SMCode/SM.Base/PostEffects/Shaders/finalize_hdr.glsl rename to src/renderer/SM.Base/PostEffects/Shaders/finalize_hdr.glsl 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 92% rename from SMCode/SM.Base/PostProcess/PostProcessEffect.cs rename to src/renderer/SM.Base/PostProcess/PostProcessEffect.cs index 5a522cb..3767ace 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 @@ -44,7 +45,7 @@ namespace SM.Base.PostProcess /// /// Method to draw the actual effect. /// - public abstract void Draw(DrawContext context); + public abstract void Draw(ColorAttachment source, DrawContext context); /// /// Event, when the scene changed. diff --git a/SMCode/SM.Base/PostProcess/PostProcessShader.cs b/src/renderer/SM.Base/PostProcess/PostProcessShader.cs similarity index 100% rename from SMCode/SM.Base/PostProcess/PostProcessShader.cs rename to src/renderer/SM.Base/PostProcess/PostProcessShader.cs 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 89% rename from SMCode/SM.Base/SM.Base.csproj rename to src/renderer/SM.Base/SM.Base.csproj index 1efa852..f0ea177 100644 --- a/SMCode/SM.Base/SM.Base.csproj +++ b/src/renderer/SM.Base/SM.Base.csproj @@ -1,5 +1,7 @@  + + @@ -37,23 +39,6 @@ 4 latest - - - ..\..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll - - - - ..\..\..\IAmTwo - Kopie\packages\SharpFont.4.0.1\lib\net45\SharpFont.dll - - - - - - - - - - @@ -126,12 +111,6 @@ - - - {f604d684-bc1d-4819-88b5-8b5d03a17be0} - SM.OGL - - @@ -140,8 +119,6 @@ - - @@ -153,12 +130,42 @@ + + + {f604d684-bc1d-4819-88b5-8b5d03a17be0} + SM.OGL + + + + + ..\..\..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll + True + + + ..\..\..\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..6aa9a48 100644 --- a/SMCode/SM.Base/Shaders/MaterialShader.cs +++ b/src/renderer/SM.Base/Shaders/MaterialShader.cs @@ -45,9 +45,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 100% rename from SMCode/SM.Base/Shaders/SimpleShader.cs rename to src/renderer/SM.Base/Shaders/SimpleShader.cs diff --git a/SMCode/SM.Base/Shaders/SimpleShaderPresets/basic_vertex.glsl b/src/renderer/SM.Base/Shaders/SimpleShaderPresets/basic_vertex.glsl similarity index 100% rename from SMCode/SM.Base/Shaders/SimpleShaderPresets/basic_vertex.glsl rename to src/renderer/SM.Base/Shaders/SimpleShaderPresets/basic_vertex.glsl diff --git a/SMCode/SM.Base/Shaders/SimpleShaderPresets/instanced_vertex.glsl b/src/renderer/SM.Base/Shaders/SimpleShaderPresets/instanced_vertex.glsl similarity index 100% rename from SMCode/SM.Base/Shaders/SimpleShaderPresets/instanced_vertex.glsl rename to src/renderer/SM.Base/Shaders/SimpleShaderPresets/instanced_vertex.glsl 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 100% rename from SMCode/SM.Base/Time/Timer.cs rename to src/renderer/SM.Base/Time/Timer.cs diff --git a/SMCode/SM.Base/Types/CVector1.cs b/src/renderer/SM.Base/Types/CVector1.cs similarity index 100% rename from SMCode/SM.Base/Types/CVector1.cs rename to src/renderer/SM.Base/Types/CVector1.cs diff --git a/SMCode/SM.Base/Types/CVector2.cs b/src/renderer/SM.Base/Types/CVector2.cs similarity index 100% rename from SMCode/SM.Base/Types/CVector2.cs rename to src/renderer/SM.Base/Types/CVector2.cs diff --git a/SMCode/SM.Base/Types/CVector3.cs b/src/renderer/SM.Base/Types/CVector3.cs similarity index 100% rename from SMCode/SM.Base/Types/CVector3.cs rename to src/renderer/SM.Base/Types/CVector3.cs diff --git a/SMCode/SM.Base/Types/CVector4.cs b/src/renderer/SM.Base/Types/CVector4.cs similarity index 99% rename from SMCode/SM.Base/Types/CVector4.cs rename to src/renderer/SM.Base/Types/CVector4.cs index 2f88938..5429a41 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; diff --git a/SMCode/SM.Base/Types/CVectorBase.cs b/src/renderer/SM.Base/Types/CVectorBase.cs similarity index 100% rename from SMCode/SM.Base/Types/CVectorBase.cs rename to src/renderer/SM.Base/Types/CVectorBase.cs 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/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 100% rename from SMCode/SM.Base/Window/RenderPipeline.cs rename to src/renderer/SM.Base/Window/RenderPipeline.cs diff --git a/SMCode/SM.Base/Window/WindowCode.cs b/src/renderer/SM.Base/Window/WindowCode.cs similarity index 100% rename from SMCode/SM.Base/Window/WindowCode.cs rename to src/renderer/SM.Base/Window/WindowCode.cs 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 100% rename from SMCode/SM.Base/packages.config rename to src/renderer/SM.Base/packages.config diff --git a/SMCode/SM.OGL/Framebuffer/ColorAttachment.cs b/src/renderer/SM.OGL/Framebuffer/ColorAttachment.cs similarity index 100% rename from SMCode/SM.OGL/Framebuffer/ColorAttachment.cs rename to src/renderer/SM.OGL/Framebuffer/ColorAttachment.cs diff --git a/SMCode/SM.OGL/Framebuffer/Framebuffer.cs b/src/renderer/SM.OGL/Framebuffer/Framebuffer.cs similarity index 100% rename from SMCode/SM.OGL/Framebuffer/Framebuffer.cs rename to src/renderer/SM.OGL/Framebuffer/Framebuffer.cs 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 100% rename from SMCode/SM.OGL/Framebuffer/RenderbufferAttachment.cs rename to src/renderer/SM.OGL/Framebuffer/RenderbufferAttachment.cs 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 100% rename from SMCode/SM.OGL/GLObject.cs rename to src/renderer/SM.OGL/GLObject.cs 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..fcd5e49 100644 --- a/SMCode/SM.OGL/SM.OGL.csproj +++ b/src/renderer/SM.OGL/SM.OGL.csproj @@ -35,7 +35,7 @@ - ..\..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll + ..\..\..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll @@ -70,12 +70,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 100% rename from SMCode/SM.OGL/Shaders/GenericShader.cs rename to src/renderer/SM.OGL/Shaders/GenericShader.cs 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 100% rename from SMCode/SM.OGL/Shaders/ShaderFile.cs rename to src/renderer/SM.OGL/Shaders/ShaderFile.cs diff --git a/SMCode/SM.OGL/Shaders/ShaderFileCollection.cs b/src/renderer/SM.OGL/Shaders/ShaderFileCollection.cs similarity index 100% rename from SMCode/SM.OGL/Shaders/ShaderFileCollection.cs rename to src/renderer/SM.OGL/Shaders/ShaderFileCollection.cs 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/SMCode/SM.OGL/Shaders/Uniform.cs b/src/renderer/SM.OGL/Shaders/Uniform.cs similarity index 100% rename from SMCode/SM.OGL/Shaders/Uniform.cs rename to src/renderer/SM.OGL/Shaders/Uniform.cs 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 100% rename from SMCode/SM.OGL/Texture/PixelInformation.cs rename to src/renderer/SM.OGL/Texture/PixelInformation.cs diff --git a/SMCode/SM.OGL/Texture/TextureBase.cs b/src/renderer/SM.OGL/Texture/TextureBase.cs similarity index 100% rename from SMCode/SM.OGL/Texture/TextureBase.cs rename to src/renderer/SM.OGL/Texture/TextureBase.cs 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/SMCode/SM.OGL/packages.config b/src/renderer/SM.OGL/packages.config similarity index 100% rename from SMCode/SM.OGL/packages.config rename to src/renderer/SM.OGL/packages.config 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 93% rename from SMCode/SM2D/Drawing/DrawParticles.cs rename to src/renderer/SM2D/Drawing/DrawParticles.cs index c01bda2..e85a302 100644 --- a/SMCode/SM2D/Drawing/DrawParticles.cs +++ b/src/renderer/SM2D/Drawing/DrawParticles.cs @@ -44,10 +44,9 @@ namespace SM2D.Drawing var particle = new ParticleInstance() { - Matrix = DetachedParticles ? Transform.GetMatrix() : Matrix4.CreateScale(1), + Matrix = DetachedParticles ? Transform.InWorldSpace : Matrix4.CreateScale(1), Direction = dir, - StartPosition = Transform.Position, Speed = Randomize.GetFloat(MaxSpeed), StartLifetime = Lifetime - Randomize.GetFloat(LifetimeRandomize) 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 90% rename from SMCode/SM2D/SM2D.csproj rename to src/renderer/SM2D/SM2D.csproj index d58b4f3..67ed6ca 100644 --- a/SMCode/SM2D/SM2D.csproj +++ b/src/renderer/SM2D/SM2D.csproj @@ -31,6 +31,9 @@ 4 + + ..\..\..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll + @@ -53,11 +56,6 @@ - - - 3.3.1 - - @@ -71,5 +69,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 100% rename from SMCode/SM2D/Shader/ShaderCollection.cs rename to src/renderer/SM2D/Shader/ShaderCollection.cs 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/SM_WPF_TEST/packages.config b/src/renderer/SM2D/packages.config similarity index 100% rename from SM_WPF_TEST/packages.config rename to src/renderer/SM2D/packages.config diff --git a/SM_TEST/App.config b/tests/SM_TEST/App.config similarity index 100% rename from SM_TEST/App.config rename to tests/SM_TEST/App.config 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/SM_TEST/Program.cs b/tests/SM_TEST/Program.cs similarity index 68% rename from SM_TEST/Program.cs rename to tests/SM_TEST/Program.cs index 2880498..a13626d 100644 --- a/SM_TEST/Program.cs +++ b/tests/SM_TEST/Program.cs @@ -2,15 +2,18 @@ using System.Collections.Generic; using System.Diagnostics; using System.Drawing; +using System.Linq; using OpenTK; using OpenTK.Graphics; using OpenTK.Graphics.OpenGL; +using ShaderToolParser; using SM.Base; using SM.Base.Animation; using SM.Base.Controls; using SM.Base.Drawing; using SM.Base.Time; using SM.Base.Window; +using SM.Intergrations.ShaderTool; using SM2D; using SM2D.Controls; using SM2D.Drawing; @@ -25,9 +28,13 @@ namespace SM_TEST static Scene scene; private static GLWindow window; private static PolyLine line; + + private static ItemCollection test; private static DrawParticles particles; private static InterpolationProcess interpolation; + + public static STPProject portal; static void Main(string[] args) { Font font = new Font(@"C:\Windows\Fonts\Arial.ttf") @@ -36,30 +43,34 @@ namespace SM_TEST }; font.RegenerateTexture(); + 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.Blue; + scene.Background.Color = Color4.Red; scene.Camera = new Camera() { }; - - particles = new DrawParticles(TimeSpan.FromSeconds(1)) + DrawObject2D obj = new DrawObject2D() { - Lifetime = 1f, - ContinuousInterval = .5f, - - Direction = -Vector2.UnitY, - DetachedParticles = true + Material = new STMaterial(portal.DrawNodes.First(a => a.Variables.ContainsKey("_MATColor"))) + { + ShaderArguments = { + { "RingLoc", .33f }, + + } + }, + Mesh = Polygon.GenerateCircle() }; - particles.Transform.Size.Set(50); - - scene.Objects.Add(particles); + obj.Transform.Size.Set(200); + scene.Objects.Add(obj); window.UpdateFrame += WindowOnUpdateFrame; window.RenderFrame += Window_RenderFrame; @@ -75,12 +86,12 @@ namespace SM_TEST private static void WindowOnUpdateFrame(object sender, FrameEventArgs e) { + /* if (Mouse.LeftClick) particles.Trigger(); if (Mouse.RightClick) - particles.ContinuousInterval = .05f; + particles.ContinuousInterval = .05f;*/ - particles.Transform.Position.Set(Mouse2D.InWorld(scene.Camera)); } } } \ 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..54f83b0 --- /dev/null +++ b/tests/SM_TEST/SM_TEST.csproj @@ -0,0 +1,101 @@ + + + + + + + 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} + SM.Intergrations + + + {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/SM_TEST/TestRenderPipeline.cs b/tests/SM_TEST/TestRenderPipeline.cs similarity index 59% rename from SM_TEST/TestRenderPipeline.cs rename to tests/SM_TEST/TestRenderPipeline.cs index 5c4edfb..5eecd9c 100644 --- a/SM_TEST/TestRenderPipeline.cs +++ b/tests/SM_TEST/TestRenderPipeline.cs @@ -1,6 +1,7 @@ using OpenTK.Graphics.OpenGL4; using SM.Base.PostEffects; using SM.Base.Window; +using SM.Intergrations.ShaderTool; using SM.OGL.Framebuffer; using SM.OGL.Texture; @@ -9,6 +10,8 @@ namespace SM_TEST public class TestRenderPipeline : RenderPipeline { private BloomEffect _bloom; + private STPostProcessEffect _vittage; + private Framebuffer _postBuffer; public override void Initialization() @@ -16,31 +19,45 @@ namespace SM_TEST MainFramebuffer = CreateWindowFramebuffer(16, PixelInformation.RGBA_HDR); - _postBuffer = CreateWindowFramebuffer(0, PixelInformation.RGBA_HDR, depth: false); + _postBuffer = CreateWindowFramebuffer(0, PixelInformation.RGBA_HDR, depth: true); Framebuffers.Add(_postBuffer); - _bloom = new BloomEffect(_postBuffer, hdr: true, .5f) + _bloom = new BloomEffect(_postBuffer, hdr: true, .75f) { - Threshold = .5f, }; - - _bloom.Initilize(this); + + _vittage = new STPostProcessEffect(Program.portal.DrawNodes.Find(a => a.Variables.ContainsKey("_ViewportSize"))) + { + Arguments = + { + {"CheckSize", 10f}, + {"Strength", .25f}, + {"TargetSize", 5f}, + {"Move", 3.33f} + } + }; + _vittage.Initilize(this); + base.Initialization(); } 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 | ClearBufferMask.DepthBufferBit); PostProcessUtility.ResolveMultisampledBuffers(MainFramebuffer, _postBuffer); - // _bloom.Draw(context); + _vittage.Draw(_postBuffer["color"], context); + _bloom.Draw(_postBuffer["color"], context); Framebuffer.Screen.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); - PostProcessUtility.FinalizeHDR(_postBuffer["color"], .5f); + PostProcessUtility.FinalizeHDR(_postBuffer["color"], .1f); context.Scene.DrawDebug(context); } 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 From dffa58159672008f13703242046940c37e46809d Mon Sep 17 00:00:00 2001 From: Michel Fedde Date: Fri, 21 May 2021 16:05:52 +0200 Subject: [PATCH 04/10] Renderer: + Font.BaselineAdjust Utils: + GameControllerState.AnyInteractions --- SMRendererV3.sln | 4 +-- ...csproj => SMRenderer.Intergrations.csproj} | 0 .../SM.Utils/Controls/GameController.cs | 2 +- .../SM.Utils/Controls/GameControllerState.cs | 4 +-- .../Controls/GameControllerStateButtons.cs | 12 ++++++- .../Controls/GameControllerStateDPad.cs | 6 +++- .../Controls/GameControllerStateThumbs.cs | 4 ++- .../Controls/GameControllerStateTriggers.cs | 5 ++- .../SM.Utils/Controls/GameKeybind.cs | 2 +- .../SM.Utils/Controls/GameKeybindActor.cs | 2 +- .../SM.Utils/Controls/GameKeybindContext.cs | 2 +- .../SM.Utils/Controls/GameKeybindHost.cs | 2 +- .../SM.Utils/Controls/GameKeybindList.cs | 2 +- ...M.Utils.csproj => SMRenderer.Utils.csproj} | 0 .../SM.Base/Drawing/GenericTransformation.cs | 9 ++++- src/renderer/SM.Base/Drawing/Text/Font.cs | 13 ++++++-- tests/SM_TEST/Program.cs | 33 ++++++++----------- tests/SM_TEST/SM_TEST.csproj | 8 +++-- 18 files changed, 70 insertions(+), 40 deletions(-) rename src/optionals/SM.Intergrations/{SM.Intergrations.csproj => SMRenderer.Intergrations.csproj} (100%) rename src/optionals/SM.Utils/{SM.Utils.csproj => SMRenderer.Utils.csproj} (100%) diff --git a/SMRendererV3.sln b/SMRendererV3.sln index 753bfc7..fecf2a6 100644 --- a/SMRendererV3.sln +++ b/SMRendererV3.sln @@ -11,9 +11,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SM2D", "src\renderer\SM2D\S EndProject 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}") = "SM.Utils", "src\optionals\SM.Utils\SM.Utils.csproj", "{079BAB31-3DC4-40DA-90C7-EFAA8517C647}" +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.Intergrations", "src\optionals\SM.Intergrations\SM.Intergrations.csproj", "{4CB351F4-B3F2-4F77-ACC2-02F21DBF5EC2}" +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}") = "Renderer", "Renderer", "{62ED6240-4DEC-4535-95EB-AE3D90A3FDF5}" EndProject diff --git a/src/optionals/SM.Intergrations/SM.Intergrations.csproj b/src/optionals/SM.Intergrations/SMRenderer.Intergrations.csproj similarity index 100% rename from src/optionals/SM.Intergrations/SM.Intergrations.csproj rename to src/optionals/SM.Intergrations/SMRenderer.Intergrations.csproj diff --git a/src/optionals/SM.Utils/Controls/GameController.cs b/src/optionals/SM.Utils/Controls/GameController.cs index af6d989..abac97a 100644 --- a/src/optionals/SM.Utils/Controls/GameController.cs +++ b/src/optionals/SM.Utils/Controls/GameController.cs @@ -1,6 +1,6 @@ using SharpDX.XInput; -namespace SM.Optionals.Controls +namespace SM.Utils.Controls { public struct GameController { diff --git a/src/optionals/SM.Utils/Controls/GameControllerState.cs b/src/optionals/SM.Utils/Controls/GameControllerState.cs index 4b661a2..d080ec3 100644 --- a/src/optionals/SM.Utils/Controls/GameControllerState.cs +++ b/src/optionals/SM.Utils/Controls/GameControllerState.cs @@ -2,7 +2,7 @@ using OpenTK; using SharpDX.XInput; -namespace SM.Optionals.Controls +namespace SM.Utils.Controls { public struct GameControllerState { @@ -12,7 +12,7 @@ namespace SM.Optionals.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; diff --git a/src/optionals/SM.Utils/Controls/GameControllerStateButtons.cs b/src/optionals/SM.Utils/Controls/GameControllerStateButtons.cs index 7ee7763..7feeb05 100644 --- a/src/optionals/SM.Utils/Controls/GameControllerStateButtons.cs +++ b/src/optionals/SM.Utils/Controls/GameControllerStateButtons.cs @@ -1,6 +1,6 @@ using SharpDX.XInput; -namespace SM.Optionals.Controls +namespace SM.Utils.Controls { public struct GameControllerStateButtons { @@ -19,8 +19,13 @@ namespace SM.Optionals.Controls public bool LeftThumb; public bool RightThumb; + public bool Start; + public bool Back; + public bool this[GamepadButtonFlags flags] => _buttonFlags.HasFlag(flags); + public bool AnyInteraction { get; } + internal GameControllerStateButtons(GamepadButtonFlags flags) { _buttonFlags = flags; @@ -35,6 +40,11 @@ namespace SM.Optionals.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/src/optionals/SM.Utils/Controls/GameControllerStateDPad.cs b/src/optionals/SM.Utils/Controls/GameControllerStateDPad.cs index e5308a6..ff3b30e 100644 --- a/src/optionals/SM.Utils/Controls/GameControllerStateDPad.cs +++ b/src/optionals/SM.Utils/Controls/GameControllerStateDPad.cs @@ -1,6 +1,6 @@ using SharpDX.XInput; -namespace SM.Optionals.Controls +namespace SM.Utils.Controls { public struct GameControllerStateDPad { @@ -11,12 +11,16 @@ namespace SM.Optionals.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 index eba90e6..5a63e45 100644 --- a/src/optionals/SM.Utils/Controls/GameControllerStateThumbs.cs +++ b/src/optionals/SM.Utils/Controls/GameControllerStateThumbs.cs @@ -1,6 +1,6 @@ using OpenTK; -namespace SM.Optionals.Controls +namespace SM.Utils.Controls { public struct GameControllerStateThumbs { @@ -13,6 +13,8 @@ namespace SM.Optionals.Controls public bool PressedLeft; public bool PressedRight; + public bool AnyInteraction => Left != Vector2.Zero || Right != Vector2.Zero || PressedLeft || PressedRight; + public override string ToString() { return $"Left: ({Left.X}; {Left.Y}){(PressedLeft ? " Pressed" : "")}; Right: ({Right.X}; {Right.Y}){(PressedRight ? " Pressed" : "")}"; diff --git a/src/optionals/SM.Utils/Controls/GameControllerStateTriggers.cs b/src/optionals/SM.Utils/Controls/GameControllerStateTriggers.cs index 13ee4cb..3d3f41c 100644 --- a/src/optionals/SM.Utils/Controls/GameControllerStateTriggers.cs +++ b/src/optionals/SM.Utils/Controls/GameControllerStateTriggers.cs @@ -1,4 +1,4 @@ -namespace SM.Optionals.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/src/optionals/SM.Utils/Controls/GameKeybind.cs b/src/optionals/SM.Utils/Controls/GameKeybind.cs index 1f1e823..b8a683d 100644 --- a/src/optionals/SM.Utils/Controls/GameKeybind.cs +++ b/src/optionals/SM.Utils/Controls/GameKeybind.cs @@ -1,6 +1,6 @@ using System; -namespace SM.Optionals.Controls +namespace SM.Utils.Controls { public class GameKeybind { diff --git a/src/optionals/SM.Utils/Controls/GameKeybindActor.cs b/src/optionals/SM.Utils/Controls/GameKeybindActor.cs index 66a583f..1bbc8a5 100644 --- a/src/optionals/SM.Utils/Controls/GameKeybindActor.cs +++ b/src/optionals/SM.Utils/Controls/GameKeybindActor.cs @@ -1,6 +1,6 @@ using OpenTK.Input; -namespace SM.Optionals.Controls +namespace SM.Utils.Controls { public enum GameKeybindActorType { diff --git a/src/optionals/SM.Utils/Controls/GameKeybindContext.cs b/src/optionals/SM.Utils/Controls/GameKeybindContext.cs index f3c6d9b..189ec44 100644 --- a/src/optionals/SM.Utils/Controls/GameKeybindContext.cs +++ b/src/optionals/SM.Utils/Controls/GameKeybindContext.cs @@ -1,6 +1,6 @@ using OpenTK.Input; -namespace SM.Optionals.Controls +namespace SM.Utils.Controls { public struct GameKeybindContext { diff --git a/src/optionals/SM.Utils/Controls/GameKeybindHost.cs b/src/optionals/SM.Utils/Controls/GameKeybindHost.cs index 9c35ed1..30c9832 100644 --- a/src/optionals/SM.Utils/Controls/GameKeybindHost.cs +++ b/src/optionals/SM.Utils/Controls/GameKeybindHost.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace SM.Optionals.Controls +namespace SM.Utils.Controls { public class GameKeybindHost { diff --git a/src/optionals/SM.Utils/Controls/GameKeybindList.cs b/src/optionals/SM.Utils/Controls/GameKeybindList.cs index 2e37d86..b5db7ed 100644 --- a/src/optionals/SM.Utils/Controls/GameKeybindList.cs +++ b/src/optionals/SM.Utils/Controls/GameKeybindList.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; -namespace SM.Optionals.Controls +namespace SM.Utils.Controls { public class GameKeybindList : List> { diff --git a/src/optionals/SM.Utils/SM.Utils.csproj b/src/optionals/SM.Utils/SMRenderer.Utils.csproj similarity index 100% rename from src/optionals/SM.Utils/SM.Utils.csproj rename to src/optionals/SM.Utils/SMRenderer.Utils.csproj diff --git a/src/renderer/SM.Base/Drawing/GenericTransformation.cs b/src/renderer/SM.Base/Drawing/GenericTransformation.cs index 3d3325a..8a3bcdf 100644 --- a/src/renderer/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/src/renderer/SM.Base/Drawing/Text/Font.cs b/src/renderer/SM.Base/Drawing/Text/Font.cs index f9c9667..102046a 100644 --- a/src/renderer/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/tests/SM_TEST/Program.cs b/tests/SM_TEST/Program.cs index a13626d..70bd0b0 100644 --- a/tests/SM_TEST/Program.cs +++ b/tests/SM_TEST/Program.cs @@ -14,6 +14,7 @@ using SM.Base.Drawing; using SM.Base.Time; using SM.Base.Window; using SM.Intergrations.ShaderTool; +using SM.Utils.Controls; using SM2D; using SM2D.Controls; using SM2D.Drawing; @@ -37,9 +38,13 @@ namespace SM_TEST public static STPProject portal; static void Main(string[] args) { - Font font = new Font(@"C:\Windows\Fonts\Arial.ttf") + Font font = new Font(@".\GapSansBold.ttf") { - FontSize = 30, + FontSize = 51, + CharSet = new char[] + { + 'I', 'A','M','T','W','O' + } }; font.RegenerateTexture(); @@ -58,18 +63,10 @@ namespace SM_TEST { }; - DrawObject2D obj = new DrawObject2D() - { - Material = new STMaterial(portal.DrawNodes.First(a => a.Variables.ContainsKey("_MATColor"))) - { - ShaderArguments = { - { "RingLoc", .33f }, - - } - }, - Mesh = Polygon.GenerateCircle() - }; - obj.Transform.Size.Set(200); + + DrawText obj = new DrawText(font, "I AM\n\tTWO") + {}; + scene.Objects.Add(obj); window.UpdateFrame += WindowOnUpdateFrame; @@ -86,12 +83,8 @@ namespace SM_TEST private static void WindowOnUpdateFrame(object sender, FrameEventArgs e) { - /* - if (Mouse.LeftClick) - particles.Trigger(); - if (Mouse.RightClick) - particles.ContinuousInterval = .05f;*/ - + bool interactions = new GameController(0).GetState().AnyInteraction; + Console.WriteLine(); } } } \ No newline at end of file diff --git a/tests/SM_TEST/SM_TEST.csproj b/tests/SM_TEST/SM_TEST.csproj index 54f83b0..a520d91 100644 --- a/tests/SM_TEST/SM_TEST.csproj +++ b/tests/SM_TEST/SM_TEST.csproj @@ -73,9 +73,13 @@ - + {4cb351f4-b3f2-4f77-acc2-02f21dbf5ec2} - SM.Intergrations + SMRenderer.Intergrations + + + {079BAB31-3DC4-40DA-90C7-EFAA8517C647} + SMRenderer.Utils {8e733844-4204-43e7-b3dc-3913cddabb0d} From 9b52d401e7bae1a06d71d902ac97fde9b0d8c635 Mon Sep 17 00:00:00 2001 From: Nineto Nine Date: Sun, 26 Sep 2021 21:27:14 +0200 Subject: [PATCH 05/10] 26 Sep 2021 General: + Added Summaries Renderer ------- SM.Base: + SM.Base.Controls.Mouse now has a feature to disable tracking. + Replaced Bloom Effect with the similar system how blender use it. + You can now disable ANY post processing effects. + Interpolation for CVectors. + MathUtils + RenderPipelines now have a central list for post processing effects. ~ Log-System is now ignored if a debugger is attached. ~ Post Processing Shader does now send the texel size as the "renderedTextureTexelSize"-uniform. ~ Improved Text Rendering SM.OGL: + ColorAttachments now contain a reference to the framebuffer its connected. + ColorAttachments can now have a own size. + Framebuffer.Append(string key, Vector2 size, int pos) +Framebuffers now have a method to completely reset itself. + Framebuffers now have a Blit-method called "CopyTo". ~ Framebuffer.GetCurrentlyActive() will now return an actual SM.OGL.Framebuffer-object. ~ Renderbuffers now are a class and contain the ID by itself. ~ Renamed Uniform-function to its class-name: f.E. SetBool, SetFloat instead of SetUniform1 Optionals: Controls: + Framecache for the GameController.GetState() --- .../SMRenderer.Intergrations.csproj | 2 +- .../ShaderTool/STMaterialShader.cs | 16 +- .../ShaderTool/STPostProcessEffect.cs | 2 +- .../ShaderTool/STPostProcessShader.cs | 16 +- .../SM.Utils/Controls/GameController.cs | 33 +- .../SM.Utils/Controls/GameControllerState.cs | 17 +- .../Controls/GameControllerStateButtons.cs | 12 +- .../Controls/GameControllerStateThumbs.cs | 16 +- .../SM.Utils/Controls/GameKeybindActor.cs | 17 +- .../SM.Utils/Controls/GameKeybindContext.cs | 2 +- .../SM.Utils/SMRenderer.Utils.csproj | 9 +- src/renderer/SM.Base/Controls/Mouse.cs | 28 +- src/renderer/SM.Base/Drawing/Material.cs | 4 + .../SM.Base/Drawing/Text/TextDrawingBasis.cs | 46 +- src/renderer/SM.Base/Legacy/Font.cs | 144 ----- .../Legacy/PostProcessing/BloomEffectOld.cs | 216 +++++++ .../PostProcessing}/bloom_blur.glsl | 4 +- .../PostProcessing}/bloom_merge.glsl | 2 +- .../Legacy/PostProcessing/bloom_merge.vert | 18 + src/renderer/SM.Base/Log.cs | 15 +- .../SM.Base/PostEffects/BloomEffect.cs | 304 +++++----- .../SM.Base/PostEffects/PostProcessUtility.cs | 6 +- .../PostEffects/Shaders/bloom/combine.frag | 32 + .../PostEffects/Shaders/bloom/downsample.frag | 41 ++ .../PostEffects/Shaders/bloom/filter.frag | 48 ++ .../PostEffects/Shaders/bloom/sampling.frag | 30 + .../PostEffects/Shaders/bloom/upsample.frag | 13 + .../PostEffects/Shaders/bloom_merge_vert.glsl | 11 - .../PostEffects/Shaders/finalize_hdr.glsl | 22 +- .../SM.Base/PostProcess/PostProcessEffect.cs | 26 +- .../SM.Base/PostProcess/PostProcessShader.cs | 48 +- src/renderer/SM.Base/SM.Base.csproj | 19 +- src/renderer/SM.Base/Shaders/SimpleShader.cs | 6 +- .../SimpleShaderPresets/basic_vertex.glsl | 9 +- .../SimpleShaderPresets/instanced_vertex.glsl | 8 - src/renderer/SM.Base/Types/CVector1.cs | 15 - src/renderer/SM.Base/Types/CVector2.cs | 21 +- src/renderer/SM.Base/Types/CVector3.cs | 17 +- src/renderer/SM.Base/Types/CVector4.cs | 17 +- src/renderer/SM.Base/Types/CVectorBase.cs | 59 ++ src/renderer/SM.Base/Utility/MathUtils.cs | 16 + src/renderer/SM.Base/Window/RenderPipeline.cs | 31 +- src/renderer/SM.Base/Window/WindowCode.cs | 7 +- src/renderer/SM.Base/packages.config | 2 +- .../SM.OGL/Framebuffer/ColorAttachment.cs | 58 +- .../SM.OGL/Framebuffer/Framebuffer.cs | 89 ++- .../Framebuffer/RenderbufferAttachment.cs | 39 +- src/renderer/SM.OGL/GLObject.cs | 2 +- src/renderer/SM.OGL/SM.OGL.csproj | 3 +- src/renderer/SM.OGL/Shaders/GenericShader.cs | 12 +- src/renderer/SM.OGL/Shaders/Uniform.cs | 558 ++++++++++-------- src/renderer/SM.OGL/Texture/TextureBase.cs | 27 + src/renderer/SM.OGL/packages.config | 2 +- src/renderer/SM2D/SM2D.csproj | 7 +- src/renderer/SM2D/Shader/ShaderCollection.cs | 2 +- src/renderer/SM2D/packages.config | 2 +- tests/SM_TEST/App.config | 6 +- tests/SM_TEST/Default Fragment Shader1.frag | 10 + tests/SM_TEST/Program.cs | 70 ++- tests/SM_TEST/SM_TEST.csproj | 4 +- tests/SM_TEST/TestRenderPipeline.cs | 29 +- 61 files changed, 1529 insertions(+), 818 deletions(-) delete mode 100644 src/renderer/SM.Base/Legacy/Font.cs create mode 100644 src/renderer/SM.Base/Legacy/PostProcessing/BloomEffectOld.cs rename src/renderer/SM.Base/{PostEffects/Shaders => Legacy/PostProcessing}/bloom_blur.glsl (92%) rename src/renderer/SM.Base/{PostEffects/Shaders => Legacy/PostProcessing}/bloom_merge.glsl (79%) create mode 100644 src/renderer/SM.Base/Legacy/PostProcessing/bloom_merge.vert create mode 100644 src/renderer/SM.Base/PostEffects/Shaders/bloom/combine.frag create mode 100644 src/renderer/SM.Base/PostEffects/Shaders/bloom/downsample.frag create mode 100644 src/renderer/SM.Base/PostEffects/Shaders/bloom/filter.frag create mode 100644 src/renderer/SM.Base/PostEffects/Shaders/bloom/sampling.frag create mode 100644 src/renderer/SM.Base/PostEffects/Shaders/bloom/upsample.frag delete mode 100644 src/renderer/SM.Base/PostEffects/Shaders/bloom_merge_vert.glsl create mode 100644 src/renderer/SM.Base/Utility/MathUtils.cs create mode 100644 tests/SM_TEST/Default Fragment Shader1.frag diff --git a/src/optionals/SM.Intergrations/SMRenderer.Intergrations.csproj b/src/optionals/SM.Intergrations/SMRenderer.Intergrations.csproj index aeea189..580452a 100644 --- a/src/optionals/SM.Intergrations/SMRenderer.Intergrations.csproj +++ b/src/optionals/SM.Intergrations/SMRenderer.Intergrations.csproj @@ -9,7 +9,7 @@ Properties SM.Intergrations SM.Intergrations - v4.5.2 + v4.7.2 512 true diff --git a/src/optionals/SM.Intergrations/ShaderTool/STMaterialShader.cs b/src/optionals/SM.Intergrations/ShaderTool/STMaterialShader.cs index 84022fc..dbc876e 100644 --- a/src/optionals/SM.Intergrations/ShaderTool/STMaterialShader.cs +++ b/src/optionals/SM.Intergrations/ShaderTool/STMaterialShader.cs @@ -23,30 +23,30 @@ namespace SM.Intergrations.ShaderTool STPCompositeNode composeNode = drawNode.OGLEffect; - ShaderFileFiles.Vertex = new[] { new ShaderFile(composeNode.Vertex.ShaderCode) }; - ShaderFileFiles.Fragment = new [] {new ShaderFile(composeNode.Fragment.ShaderCode)}; + ShaderFiles.Vertex = new[] { new ShaderFile(composeNode.Vertex.ShaderCode) }; + ShaderFiles.Fragment = new [] {new ShaderFile(composeNode.Fragment.ShaderCode)}; if (composeNode.Geometry != null) - ShaderFileFiles.Geometry = new[] {new ShaderFile(composeNode.Geometry.ShaderCode)}; + ShaderFiles.Geometry = new[] {new ShaderFile(composeNode.Geometry.ShaderCode)}; foreach (KeyValuePair pair in drawNode.Variables) { switch (pair.Value.Type) { case STPBasisType.Bool: - _uniforms += context => Uniforms[pair.Key].SetUniform1(context.Material.ShaderArguments.Get(pair.Key, false)); + _uniforms += context => Uniforms[pair.Key].SetBool(context.Material.ShaderArguments.Get(pair.Key, false)); break; case STPBasisType.Float: - _uniforms += context => Uniforms[pair.Key].SetUniform1(context.Material.ShaderArguments.Get(pair.Key, 0.0f)); + _uniforms += context => Uniforms[pair.Key].SetFloat(context.Material.ShaderArguments.Get(pair.Key, 0.0f)); break; case STPBasisType.Vector2: - _uniforms += context => Uniforms[pair.Key].SetUniform2(context.Material.ShaderArguments.Get(pair.Key, Vector2.Zero)); + _uniforms += context => Uniforms[pair.Key].SetVector2(context.Material.ShaderArguments.Get(pair.Key, Vector2.Zero)); break; case STPBasisType.Vector3: - _uniforms += context => Uniforms[pair.Key].SetUniform3(context.Material.ShaderArguments.Get(pair.Key, Vector3.Zero)); + _uniforms += context => Uniforms[pair.Key].SetVector3(context.Material.ShaderArguments.Get(pair.Key, Vector3.Zero)); break; case STPBasisType.Vector4: _uniforms += context => - Uniforms[pair.Key].SetUniform4(context.Material.ShaderArguments.Get(pair.Key, Vector4.Zero)); + Uniforms[pair.Key].SetVector4(context.Material.ShaderArguments.Get(pair.Key, Vector4.Zero)); break; case STPBasisType.Matrix: _uniforms += context => Uniforms[pair.Key].SetMatrix4(context.Material.ShaderArguments.Get(pair.Key, Matrix4.Identity)); diff --git a/src/optionals/SM.Intergrations/ShaderTool/STPostProcessEffect.cs b/src/optionals/SM.Intergrations/ShaderTool/STPostProcessEffect.cs index f62445c..461b046 100644 --- a/src/optionals/SM.Intergrations/ShaderTool/STPostProcessEffect.cs +++ b/src/optionals/SM.Intergrations/ShaderTool/STPostProcessEffect.cs @@ -39,7 +39,7 @@ namespace SM.Intergrations.ShaderTool } } - public override void Draw(ColorAttachment source, DrawContext context) + protected override void Drawing(ColorAttachment source, DrawContext context) { Arguments["_Scene"] = (TextureBase)source; Arguments["_MVP"] = Mvp; diff --git a/src/optionals/SM.Intergrations/ShaderTool/STPostProcessShader.cs b/src/optionals/SM.Intergrations/ShaderTool/STPostProcessShader.cs index 35a1b4c..a8226cc 100644 --- a/src/optionals/SM.Intergrations/ShaderTool/STPostProcessShader.cs +++ b/src/optionals/SM.Intergrations/ShaderTool/STPostProcessShader.cs @@ -23,30 +23,30 @@ namespace SM.Intergrations.ShaderTool STPCompositeNode composeNode = postProcessNode.OGLEffect; - ShaderFileFiles.Vertex = new[] { new ShaderFile(composeNode.Vertex.ShaderCode) }; - ShaderFileFiles.Fragment = new[] { new ShaderFile(composeNode.Fragment.ShaderCode) }; + ShaderFiles.Vertex = new[] { new ShaderFile(composeNode.Vertex.ShaderCode) }; + ShaderFiles.Fragment = new[] { new ShaderFile(composeNode.Fragment.ShaderCode) }; if (composeNode.Geometry != null) - ShaderFileFiles.Geometry = new[] { new ShaderFile(composeNode.Geometry.ShaderCode) }; + ShaderFiles.Geometry = new[] { new ShaderFile(composeNode.Geometry.ShaderCode) }; foreach (KeyValuePair pair in postProcessNode.Variables) { switch (pair.Value.Type) { case STPBasisType.Bool: - _uniforms += context => Uniforms[pair.Key].SetUniform1(context.Get(pair.Key, false)); + _uniforms += context => Uniforms[pair.Key].SetBool(context.Get(pair.Key, false)); break; case STPBasisType.Float: - _uniforms += context => Uniforms[pair.Key].SetUniform1(context.Get(pair.Key, 0.0f)); + _uniforms += context => Uniforms[pair.Key].SetFloat(context.Get(pair.Key, 0.0f)); break; case STPBasisType.Vector2: - _uniforms += context => Uniforms[pair.Key].SetUniform2(context.Get(pair.Key, Vector2.Zero)); + _uniforms += context => Uniforms[pair.Key].SetVector2(context.Get(pair.Key, Vector2.Zero)); break; case STPBasisType.Vector3: - _uniforms += context => Uniforms[pair.Key].SetUniform3(context.Get(pair.Key, Vector3.Zero)); + _uniforms += context => Uniforms[pair.Key].SetVector3(context.Get(pair.Key, Vector3.Zero)); break; case STPBasisType.Vector4: _uniforms += context => - Uniforms[pair.Key].SetUniform4(context.Get(pair.Key, Vector4.Zero)); + Uniforms[pair.Key].SetVector4(context.Get(pair.Key, Vector4.Zero)); break; case STPBasisType.Matrix: _uniforms += context => Uniforms[pair.Key].SetMatrix4(context.Get(pair.Key, Matrix4.Identity)); diff --git a/src/optionals/SM.Utils/Controls/GameController.cs b/src/optionals/SM.Utils/Controls/GameController.cs index abac97a..43570dc 100644 --- a/src/optionals/SM.Utils/Controls/GameController.cs +++ b/src/optionals/SM.Utils/Controls/GameController.cs @@ -1,38 +1,55 @@ using SharpDX.XInput; +using SM.Base; namespace SM.Utils.Controls { - public struct GameController + public class GameController { - public static float GlobalDeadband = 2500; + public static float GlobalDeadband = .1F; private Controller _controller; + private ulong _lastFrame; + + internal GamepadButtonFlags _lastPressedButtons; public float Deadband { get; set; } public bool IsConnected => _controller.IsConnected; - public UserIndex Index { get; private set; } + public GameControllerState LastState { get; private set; } + public UserIndex Index { get; private set; } + public GameController(int id) : this((UserIndex)id) {} public GameController(UserIndex index = UserIndex.Any) { + _lastPressedButtons = GamepadButtonFlags.None; _controller = new Controller(index); Index = index; Deadband = GlobalDeadband; } - public GameControllerState GetState() + public GameControllerState GetState(bool force = false) { - if (!IsConnected) + if (!force && _lastFrame == SMRenderer.CurrentFrame) { - return new GameControllerState(true); + return LastState; } - Gamepad state = _controller.GetState().Gamepad; + GameControllerState st = new GameControllerState(true); + if (IsConnected) + { + Gamepad state = _controller.GetState().Gamepad; + st = new GameControllerState(state, this); + _lastPressedButtons = state.Buttons; + } - return new GameControllerState(state, ref this); + LastState = st; + + _lastFrame = SMRenderer.CurrentFrame; + + return st; } } diff --git a/src/optionals/SM.Utils/Controls/GameControllerState.cs b/src/optionals/SM.Utils/Controls/GameControllerState.cs index d080ec3..7a20aa4 100644 --- a/src/optionals/SM.Utils/Controls/GameControllerState.cs +++ b/src/optionals/SM.Utils/Controls/GameControllerState.cs @@ -22,22 +22,11 @@ namespace SM.Utils.Controls DPad = GameControllerStateDPad.Default; Buttons = GameControllerStateButtons.Default; } - internal GameControllerState(Gamepad state, ref GameController controller) + internal GameControllerState(Gamepad state, GameController controller) { FromConnected = true; - Thumbs = new GameControllerStateThumbs - { - Left = new Vector2( - Math.Abs((float)state.LeftThumbX) < controller.Deadband ? 0 : (float)state.LeftThumbX / short.MaxValue, - Math.Abs((float)state.LeftThumbY) < controller.Deadband ? 0 : (float)state.LeftThumbY / short.MaxValue), - Right = new Vector2( - Math.Abs((float)state.RightThumbX) < controller.Deadband ? 0 : (float)state.RightThumbX / short.MaxValue, - Math.Abs((float)state.RightThumbY) < controller.Deadband ? 0 : (float)state.RightThumbY / short.MaxValue), - - PressedLeft = state.Buttons.HasFlag(GamepadButtonFlags.LeftThumb), - PressedRight = state.Buttons.HasFlag(GamepadButtonFlags.RightThumb) - }; + Thumbs = new GameControllerStateThumbs(controller, state); Triggers = new GameControllerStateTriggers() { @@ -46,7 +35,7 @@ namespace SM.Utils.Controls }; DPad = new GameControllerStateDPad(state.Buttons); - Buttons = new GameControllerStateButtons(state.Buttons); + Buttons = new GameControllerStateButtons(state.Buttons, controller); } public override string ToString() diff --git a/src/optionals/SM.Utils/Controls/GameControllerStateButtons.cs b/src/optionals/SM.Utils/Controls/GameControllerStateButtons.cs index 7feeb05..5bcd5f4 100644 --- a/src/optionals/SM.Utils/Controls/GameControllerStateButtons.cs +++ b/src/optionals/SM.Utils/Controls/GameControllerStateButtons.cs @@ -4,9 +4,14 @@ namespace SM.Utils.Controls { public struct GameControllerStateButtons { - public static GameControllerStateButtons Default = new GameControllerStateButtons(GamepadButtonFlags.None); + public static GameControllerStateButtons Default = new GameControllerStateButtons() + { + _buttonFlags = GamepadButtonFlags.None, + _lastButtonFlags = GamepadButtonFlags.None + }; private GamepadButtonFlags _buttonFlags; + private GamepadButtonFlags _lastButtonFlags; public bool X; public bool Y; @@ -22,13 +27,14 @@ namespace SM.Utils.Controls public bool Start; public bool Back; - public bool this[GamepadButtonFlags flags] => _buttonFlags.HasFlag(flags); + public bool this[GamepadButtonFlags flags, bool once = false] => _buttonFlags.HasFlag(flags) && !(once && _lastButtonFlags.HasFlag(flags)); public bool AnyInteraction { get; } - internal GameControllerStateButtons(GamepadButtonFlags flags) + internal GameControllerStateButtons(GamepadButtonFlags flags, GameController controller) { _buttonFlags = flags; + _lastButtonFlags = controller._lastPressedButtons; X = flags.HasFlag(GamepadButtonFlags.X); Y = flags.HasFlag(GamepadButtonFlags.Y); diff --git a/src/optionals/SM.Utils/Controls/GameControllerStateThumbs.cs b/src/optionals/SM.Utils/Controls/GameControllerStateThumbs.cs index 5a63e45..6741a3c 100644 --- a/src/optionals/SM.Utils/Controls/GameControllerStateThumbs.cs +++ b/src/optionals/SM.Utils/Controls/GameControllerStateThumbs.cs @@ -1,4 +1,6 @@ -using OpenTK; +using System; +using OpenTK; +using SharpDX.XInput; namespace SM.Utils.Controls { @@ -15,6 +17,18 @@ namespace SM.Utils.Controls public bool AnyInteraction => Left != Vector2.Zero || Right != Vector2.Zero || PressedLeft || PressedRight; + public GameControllerStateThumbs(GameController controller, Gamepad state) + { + Vector2 left = new Vector2(state.LeftThumbX, state.LeftThumbY) / short.MaxValue; + Vector2 right = new Vector2(state.RightThumbX, state.RightThumbY) / short.MaxValue; + + Left = new Vector2(Math.Abs(left.X) < controller.Deadband ? 0 : left.X, Math.Abs(left.Y) < controller.Deadband ? 0 : left.Y); + Right = new Vector2(Math.Abs(right.X) < controller.Deadband ? 0 : right.X, Math.Abs(right.Y) < controller.Deadband ? 0 : right.Y); + + PressedLeft = state.Buttons.HasFlag(GamepadButtonFlags.LeftThumb); + PressedRight = state.Buttons.HasFlag(GamepadButtonFlags.RightThumb); + } + public override string ToString() { return $"Left: ({Left.X}; {Left.Y}){(PressedLeft ? " Pressed" : "")}; Right: ({Right.X}; {Right.Y}){(PressedRight ? " Pressed" : "")}"; diff --git a/src/optionals/SM.Utils/Controls/GameKeybindActor.cs b/src/optionals/SM.Utils/Controls/GameKeybindActor.cs index 1bbc8a5..7dfd976 100644 --- a/src/optionals/SM.Utils/Controls/GameKeybindActor.cs +++ b/src/optionals/SM.Utils/Controls/GameKeybindActor.cs @@ -12,16 +12,25 @@ namespace SM.Utils.Controls public struct GameKeybindActor { private GameKeybindActorType _type; - private GameController? _controller; + private GameController _controller; private GameKeybindHost _keybindHost; public GameKeybindActorType Type => _type; - public GameController? Controller => _controller; + public GameController Controller => _controller; public object[] Parameter; - private GameKeybindActor(GameKeybindActorType type, GameController? controller) + private GameKeybindActor(GameKeybindActorType type, GameController controller) + { + _type = type; + _controller = controller; + + _keybindHost = null; + + Parameter = new object[0]; + } + private GameKeybindActor(GameKeybindActorType type, ref GameController controller) { _type = type; _controller = controller; @@ -58,7 +67,7 @@ namespace SM.Utils.Controls KeyboardState = Keyboard.GetState(), MouseState = Mouse.GetState(), - ControllerState = Controller?.GetState(), + ControllerState = Controller?.GetState() ?? new GameControllerState(true), }; return keybind[Type].Invoke(context); diff --git a/src/optionals/SM.Utils/Controls/GameKeybindContext.cs b/src/optionals/SM.Utils/Controls/GameKeybindContext.cs index 189ec44..c08fe7c 100644 --- a/src/optionals/SM.Utils/Controls/GameKeybindContext.cs +++ b/src/optionals/SM.Utils/Controls/GameKeybindContext.cs @@ -6,7 +6,7 @@ namespace SM.Utils.Controls { public KeyboardState KeyboardState; public MouseState MouseState; - public GameControllerState? ControllerState; + public GameControllerState ControllerState; public GameKeybindActor Actor; public GameKeybindHost Host; diff --git a/src/optionals/SM.Utils/SMRenderer.Utils.csproj b/src/optionals/SM.Utils/SMRenderer.Utils.csproj index 92fd385..30b4822 100644 --- a/src/optionals/SM.Utils/SMRenderer.Utils.csproj +++ b/src/optionals/SM.Utils/SMRenderer.Utils.csproj @@ -9,9 +9,10 @@ Properties SM.Utils SM.Utils - v4.5.2 + v4.7.2 512 true + true @@ -61,5 +62,11 @@ + + + {8e733844-4204-43e7-b3dc-3913cddabb0d} + SM.Base + + \ No newline at end of file diff --git a/src/renderer/SM.Base/Controls/Mouse.cs b/src/renderer/SM.Base/Controls/Mouse.cs index 1309818..0a18ce9 100644 --- a/src/renderer/SM.Base/Controls/Mouse.cs +++ b/src/renderer/SM.Base/Controls/Mouse.cs @@ -18,10 +18,20 @@ namespace SM.Base.Controls private static MouseState? _mouseState; private static List _lastButtonsPressed = new List(); + private static Vector2 _inScreen; + /// - /// The current position of the mouse in the screen. + /// Gets or sets the current position of the mouse in the screen. /// - public static Vector2 InScreen { get; private set; } + public static Vector2 InScreen + { + get => _inScreen; + set + { + _inScreen = value; + UpdateNormalized(SMRenderer.CurrentWindow); + } + } /// /// The current position of the mouse in the screen from 0..1. @@ -40,6 +50,16 @@ namespace SM.Base.Controls /// public static bool RightClick => IsDown(MouseButton.Right, true); + /// + /// If true, it disables the tracking of the mouse, allowing you to change the value, without the system replacing it again. + /// + public static bool StopTracking { get; set; } + + private static void UpdateNormalized(IGenericWindow window) + { + InScreenNormalized = new Vector2(_inScreen.X / (float)window.Width, _inScreen.Y / (float)window.Height); + } + /// /// The event to update the values. /// @@ -47,8 +67,10 @@ namespace SM.Base.Controls /// The window where the mouse is checked internal static void MouseMoveEvent(MouseMoveEventArgs mmea, IGenericWindow window) { + if (StopTracking) return; + InScreen = new Vector2(mmea.X, mmea.Y); - InScreenNormalized = new Vector2(mmea.X / (float) window.Width, mmea.Y / (float) window.Height); + UpdateNormalized(window); } internal static void SetState() diff --git a/src/renderer/SM.Base/Drawing/Material.cs b/src/renderer/SM.Base/Drawing/Material.cs index dc8c8fb..c1d1663 100644 --- a/src/renderer/SM.Base/Drawing/Material.cs +++ b/src/renderer/SM.Base/Drawing/Material.cs @@ -39,6 +39,10 @@ namespace SM.Base.Drawing /// public ShaderArguments ShaderArguments { get; internal set; } = new ShaderArguments(); + /// + /// Draws the material with the provided context. + /// + /// public virtual void Draw(DrawContext context) { context.Shader.Draw(context); diff --git a/src/renderer/SM.Base/Drawing/Text/TextDrawingBasis.cs b/src/renderer/SM.Base/Drawing/Text/TextDrawingBasis.cs index 206a63c..9879639 100644 --- a/src/renderer/SM.Base/Drawing/Text/TextDrawingBasis.cs +++ b/src/renderer/SM.Base/Drawing/Text/TextDrawingBasis.cs @@ -1,6 +1,8 @@ #region usings using System; +using System.Collections.Generic; +using System.Linq; using OpenTK; using OpenTK.Graphics; using SM.Base.Objects.Static; @@ -130,9 +132,13 @@ namespace SM.Base.Drawing.Text { if (!Font.WasCompiled) Font.RegenerateTexture(); + if (string.IsNullOrEmpty(_text)) return; + _text = _text.Replace("\r\n", "\n").Replace("\t", " "); _instances = new Instance[_text.Length]; + List> lines = new List>(); + List currentLineInstances = new List(); float x = 0; float y = 0; @@ -146,8 +152,13 @@ namespace SM.Base.Drawing.Text if (_text[i] == '\n') { + if (currentLineInstances.Count > 0) + { + lines.Add(new Tuple(new Vector2(x, y), currentLineInstances.ToArray())); + currentLineInstances.Clear(); + } + y += Font.Height; - Width = Math.Max(Width, x); x = 0; continue; } @@ -170,32 +181,41 @@ namespace SM.Base.Drawing.Text var matrix = Matrix4.CreateScale(parameter.Width, Font.Height, 1) * Matrix4.CreateTranslation(x + parameter.Width / 2, -y, 0); - _instances[i] = new Instance + currentLineInstances.Add(_instances[i] = new Instance { ModelMatrix = matrix, TextureMatrix = parameter.TextureMatrix - }; + }); x += parameter.Advance; } + if (currentLineInstances.Count > 0) + lines.Add(new Tuple(new Vector2(x, y), currentLineInstances.ToArray())); + Height = y + Font.Height; - Width = x; + Width = lines.Max(a => a.Item1.X); if (Origin != TextOrigin.Left) { - foreach (Instance i in _instances) + foreach (Tuple line in lines) { - if (i == null) continue; - switch (Origin) + + foreach (Instance i in line.Item2) { - case TextOrigin.Center: - i.ModelMatrix *= Matrix4.CreateTranslation(-Width / 2, 0, 0); - break; - case TextOrigin.Right: - i.ModelMatrix *= Matrix4.CreateTranslation(-Width, 0, 0); - break; + if (i == null) continue; + switch (Origin) + { + case TextOrigin.Center: + i.ModelMatrix *= Matrix4.CreateTranslation(-line.Item1.X / 2, 0, 0); + break; + case TextOrigin.Right: + i.ModelMatrix *= Matrix4.CreateTranslation(-line.Item1.X, 0, 0); + break; + } } } + + } } } diff --git a/src/renderer/SM.Base/Legacy/Font.cs b/src/renderer/SM.Base/Legacy/Font.cs deleted file mode 100644 index 1cebcb6..0000000 --- a/src/renderer/SM.Base/Legacy/Font.cs +++ /dev/null @@ -1,144 +0,0 @@ -#region usings - -using System.Collections.Generic; -using System.Drawing; -using System.Drawing.Text; -using OpenTK.Graphics.OpenGL4; -using SM.Base.Textures; - -#endregion - -namespace SM.Base.Drawing.Text -{ - /// - /// Represents a font. - /// - public class Font : Texture - { - /// - /// The char set for the font. - /// Default: - /// - public ICollection CharSet = FontCharStorage.SimpleUTF8; - - /// - /// The font family, that is used to find the right font. - /// - public FontFamily FontFamily; - - /// - /// The font size. - /// Default: 12 - /// - public float FontSize = 12; - - public float SpaceWidth { get; private set; } - - public float Spacing = 1; - - /// - /// The font style. - /// Default: - /// - public FontStyle FontStyle = FontStyle.Regular; - - /// - /// This contains all information for the different font character. - /// - public Dictionary Positions = new Dictionary(); - - /// - /// Generates a font from a font family from the specified path. - /// - /// The specified path - public Font(string path) - { - var pfc = new PrivateFontCollection(); - pfc.AddFontFile(path); - FontFamily = pfc.Families[0]; - } - - /// - /// Generates a font from a specified font family. - /// - /// Font-Family - public Font(FontFamily font) - { - FontFamily = font; - } - - /// - public override TextureWrapMode WrapMode { get; set; } = TextureWrapMode.ClampToEdge; - - /// - /// Regenerates the texture. - /// - public void RegenerateTexture() - { - Width = 0; - Height = 0; - Positions = new Dictionary(); - - - var map = new Bitmap(1000, 20); - var charParams = new Dictionary(); - using (var f = new System.Drawing.Font(FontFamily, FontSize, FontStyle)) - { - using (var g = Graphics.FromImage(map)) - { - g.Clear(Color.Transparent); - - foreach (var c in CharSet) - { - var s = c.ToString(); - var size = g.MeasureString(s, f, 0, StringFormat.GenericTypographic); - try - { - charParams.Add(c, new[] {size.Width, Width}); - } - catch - { - // ignored - } - - if (Height < size.Height) Height = (int) size.Height; - Width += (int) size.Width + 1; - } - - SpaceWidth = g.MeasureString("_", f, 0, StringFormat.GenericTypographic).Width; - } - - map = new Bitmap(Width, Height); - using (var g = Graphics.FromImage(map)) - { - foreach (var keyValuePair in charParams) - { - var normalizedX = (keyValuePair.Value[1]+ 0.00001f) / Width; - var normalizedWidth = keyValuePair.Value[0] / Width; - - CharParameter parameter; - Positions.Add(keyValuePair.Key, parameter = new CharParameter - { - NormalizedWidth = normalizedWidth, - NormalizedX = normalizedX, - Width = keyValuePair.Value[0], - X = (int) keyValuePair.Value[1] - }); - - g.DrawString(keyValuePair.Key.ToString(), f, Brushes.White, parameter.X, 0, StringFormat.GenericTypographic); - } - } - } - - Map = map; - Recompile(); - } - - /// - public override void Compile() - { - RegenerateTexture(); - base.Compile(); - } - } -} \ No newline at end of file diff --git a/src/renderer/SM.Base/Legacy/PostProcessing/BloomEffectOld.cs b/src/renderer/SM.Base/Legacy/PostProcessing/BloomEffectOld.cs new file mode 100644 index 0000000..4a7366c --- /dev/null +++ b/src/renderer/SM.Base/Legacy/PostProcessing/BloomEffectOld.cs @@ -0,0 +1,216 @@ +#region usings + +using System; +using System.Drawing; +using OpenTK; +using OpenTK.Graphics.OpenGL4; +using SM.Base.Drawing; +using SM.Base.PostProcess; +using SM.Base.Utility; +using SM.Base.Window; +using SM.OGL.Framebuffer; +using SM.OGL.Shaders; +using SM.OGL.Texture; + +#endregion + +namespace SM.Base.Legacy.PostProcessing +{ + /// + /// A bloom post process effect. + /// + [Obsolete("This bloom effect isn't good. Please use SM.Base.PostEffects.BloomEffect, if you want a good bloom effect.")] + public class BloomEffectOld : PostProcessEffect + { + private static BezierCurve _defaultCurve = new BezierCurve(Vector2.UnitY, Vector2.Zero, new Vector2(0.4f, 0), new Vector2(.5f,0)); + private static readonly PostProcessShader _mergeShader = new PostProcessShader( + new ShaderFile(AssemblyUtility.ReadAssemblyFile("SM.Base.Legacy.PostProcessing.bloom_merge.vert")), + AssemblyUtility.ReadAssemblyFile("SM.Base.Legacy.PostProcessing.bloom_merge.glsl")); + + private static readonly PostProcessShader _shader = + new PostProcessShader(AssemblyUtility.ReadAssemblyFile("SM.Base.Legacy.PostProcessing.bloom_blur.glsl")); + private const float _defaultTextureScale = .75f; + + private Framebuffer _source; + + private Framebuffer _tempColorBuffer; + private Framebuffer _bloomBuffer1; + private Framebuffer _bloomBuffer2; + + private readonly bool _hdr; + + private readonly float _textureScale = .75f; + + private BezierCurve _weightCurve; + private float[] _weights; + + private ColorAttachment _xBuffer; + private ColorAttachment _yBuffer; + + /// + /// A texture where you can define the amount of the bloom effect at each pixel. + /// + public TextureBase AmountMap; + /// + /// The transformation for the amount map. + /// + public TextureTransformation AmountTransform = new TextureTransformation(); + /// + /// The maximal amount the amount map is clamped to. + /// Default: 1 + /// + public float MaxAmount = 1; + /// + /// The minimal amount the amount map is clamped to. + /// Default: 0 + /// + public float MinAmount = 0; + + /// + /// The defines how often the x-y-flipflop happens. + /// Default: 8 + /// + public int Iterations = 8; + /// + /// The Threshold for the bloom effect. + /// Default: .8f + /// + public float Threshold = .8f; + /// + /// Increases the brightness of the resulting effect. + /// Default: 1 + /// + public float Power = 1; + + /// + /// Radius of the effect + /// Default: 2 + /// + public float Radius = 1; + + /// + /// This defines the weight curve. + /// + public BezierCurve WeightCurve + { + get => _weightCurve; + set + { + _weightCurve = value; + UpdateWeights(); + } + } + + /// + /// This defines how many picks the effect should pick from the weight curve. + /// + public int WeightCurvePickAmount = 4; + + /// + /// This creates a bloom effect. + /// + /// This can specify a own source framebuffer. If not set, it will take the Pipeline MainFramebuffer. + /// This allows to enable hdr returns. + /// This allows for a increase in performance, by lowering the calculating texture scale. + public BloomEffectOld(Framebuffer source = null, bool hdr = false, float? textureScale = null) + { + _source = source; + _hdr = hdr; + _textureScale = textureScale.GetValueOrDefault(_defaultTextureScale); + + WeightCurve = _defaultCurve; + } + + + private void UpdateWeights() + { + _weights = new float[WeightCurvePickAmount]; + + for (int i = 0; i < WeightCurvePickAmount; i++) + _weights[i] = _weightCurve.CalculatePoint((float) (i + 1) / (WeightCurvePickAmount + 1)).Y; + } + + /// + protected override void InitProcess() + { + _source ??= Pipeline.MainFramebuffer; + + _source.ColorAttachments["color"].PixelInformation = PixelInformation.RGBA_HDR; + + _tempColorBuffer = new Framebuffer(Pipeline.ConnectedWindow, 1); + _tempColorBuffer.Append("color", new ColorAttachment(0, PixelInformation.RGBA_HDR)); + _tempColorBuffer.Compile(); + + _bloomBuffer1 = new Framebuffer(Pipeline.ConnectedWindow, _textureScale) + { + Name = "BloomX" + }; + _bloomBuffer1.Append("xBuffer", _xBuffer = new ColorAttachment(0, PixelInformation.RGBA_HDR)); + _bloomBuffer1.Compile(); + _bloomBuffer2 = new Framebuffer(Pipeline.ConnectedWindow, _textureScale) + { + Name = "BloomY" + }; + _bloomBuffer2.Append("yBuffer", _yBuffer = new ColorAttachment(0, PixelInformation.RGBA_HDR)); + _bloomBuffer2.Compile(); + + Pipeline.Framebuffers.Add(_tempColorBuffer); + Pipeline.Framebuffers.Add(_bloomBuffer1); + Pipeline.Framebuffers.Add(_bloomBuffer2); + } + + /// + protected override void Drawing(ColorAttachment source, DrawContext context) + { + GL.Viewport(0, 0, (int) (Pipeline.ConnectedWindow.Width * _textureScale), + (int) (Pipeline.ConnectedWindow.Height * _textureScale)); + + Framebuffer target = Framebuffer.GetCurrentlyActive(); + + source.ConnectedFramebuffer.CopyTo(_tempColorBuffer); + + bool first = true, hoz = true; + int iter = Iterations * 2; + for (int i = 0; i < iter; i++) + { + (hoz ? _bloomBuffer1 : _bloomBuffer2).Activate(false); + + _shader.Draw(collection => + { + collection["renderedTexture"].SetTexture(first ? source : (hoz ? _yBuffer : _xBuffer)); + + collection["First"].SetBool(first); + collection["Threshold"].SetFloat(Threshold); + + collection["Horizontal"].SetBool(hoz); + + collection["Weights"].SetFloat(_weights); + collection["WeightCount"].SetFloat(WeightCurvePickAmount); + collection["Power"].SetFloat(Power); + + collection["Radius"].SetFloat(_textureScale * Radius); + }); + + hoz = !hoz; + if (first) first = false; + } + + GL.Viewport(Pipeline.ConnectedWindow.ClientRectangle); + target.Activate(); + + _mergeShader.Draw(collection => + { + collection["Scene"].SetTexture(_tempColorBuffer["color"]); + collection["Bloom"].SetTexture(_yBuffer); + + collection["MinAmount"].SetFloat(MinAmount); + collection["MaxAmount"].SetFloat(MaxAmount); + collection["AmountMap"].SetTexture(AmountMap, collection["HasAmountMap"]); + collection["TextureTransform"].SetMatrix3(AmountTransform.GetMatrix()); + + collection["Exposure"].SetFloat(context.UseCamera.Exposure); + collection["HDR"].SetBool(_hdr); + }); + } + } +} \ No newline at end of file diff --git a/src/renderer/SM.Base/PostEffects/Shaders/bloom_blur.glsl b/src/renderer/SM.Base/Legacy/PostProcessing/bloom_blur.glsl similarity index 92% rename from src/renderer/SM.Base/PostEffects/Shaders/bloom_blur.glsl rename to src/renderer/SM.Base/Legacy/PostProcessing/bloom_blur.glsl index 834ad23..c6bb97a 100644 --- a/src/renderer/SM.Base/PostEffects/Shaders/bloom_blur.glsl +++ b/src/renderer/SM.Base/Legacy/PostProcessing/bloom_blur.glsl @@ -1,5 +1,4 @@ #version 330 -#define PI 3.14159265359 uniform sampler2D renderedTexture; uniform float RenderScale; @@ -16,6 +15,7 @@ uniform float Power; uniform float Radius; layout(location = 0) out vec4 color; +layout(location = 1) out vec4 scene; vec4 GetRenderColorOffset(vec2 offset); @@ -31,6 +31,8 @@ float GetWeight(int dif) { } void main() { + if (First) scene = GetRenderColorOffset(vec2(0)); + vec3 thres = vec3(First ? Threshold : 0); vec2 tex_offset = 1.0 / textureSize(renderedTexture, 0) * vec2(Horizontal ? 1 : 0, Horizontal ? 0 : 1); diff --git a/src/renderer/SM.Base/PostEffects/Shaders/bloom_merge.glsl b/src/renderer/SM.Base/Legacy/PostProcessing/bloom_merge.glsl similarity index 79% rename from src/renderer/SM.Base/PostEffects/Shaders/bloom_merge.glsl rename to src/renderer/SM.Base/Legacy/PostProcessing/bloom_merge.glsl index cef9313..77a8937 100644 --- a/src/renderer/SM.Base/PostEffects/Shaders/bloom_merge.glsl +++ b/src/renderer/SM.Base/Legacy/PostProcessing/bloom_merge.glsl @@ -18,7 +18,7 @@ layout(location = 0) out vec4 color; void main() { vec3 result = texture(Bloom, vTexture).rgb; - if (HasAmountMap) result *= clamp(length(texture(AmountMap, TransformedTexture).rgb) * (MaxAmount - MinAmount) + MinAmount, 0, 1); + //if (HasAmountMap) result *= clamp(length(texture(AmountMap, TransformedTexture).rgb) * (MaxAmount - MinAmount) + MinAmount, 0, 1); if (!HDR) { result = vec3(1.0) - exp(-result * Exposure); } diff --git a/src/renderer/SM.Base/Legacy/PostProcessing/bloom_merge.vert b/src/renderer/SM.Base/Legacy/PostProcessing/bloom_merge.vert new file mode 100644 index 0000000..5875eb3 --- /dev/null +++ b/src/renderer/SM.Base/Legacy/PostProcessing/bloom_merge.vert @@ -0,0 +1,18 @@ +#version 330 + +layout(location = 0) in vec3 aPos; +layout(location = 1) in vec2 aTex; + +uniform mat4 MVP; +uniform mat3 TextureTransform; + +out vec2 vTexture; +out vec2 TransformedTexture; + + +void main() { + vTexture = aTex; + //TransformedTexture = vec2(TextureTransform * vec3(aTex, 1)); + + gl_Position = MVP * vec4(aPos, 1); +} \ No newline at end of file diff --git a/src/renderer/SM.Base/Log.cs b/src/renderer/SM.Base/Log.cs index 8477937..176a85c 100644 --- a/src/renderer/SM.Base/Log.cs +++ b/src/renderer/SM.Base/Log.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.IO.Compression; +using System.Reflection; using System.Windows.Forms; using OpenTK.Graphics.OpenGL4; using SM.OGL; @@ -82,14 +83,14 @@ namespace SM.Base /// /// Presets for the log targets. /// - public static Dictionary Preset = new() + public static Dictionary Preset = new Dictionary() { {LogTarget.Console, "[%type%] %msg%"}, {LogTarget.Debugger, "[%type%] %msg%"}, {LogTarget.File, "<%date%, %time%> [%type%] %msg%"} }; - private static readonly Dictionary Colors = new() + private static readonly Dictionary Colors = new Dictionary() { {LogType.Info, ConsoleColor.Green}, {LogType.Warning, ConsoleColor.Yellow}, @@ -145,7 +146,10 @@ namespace SM.Base { if (_init) return; - AppDomain.CurrentDomain.UnhandledException += ExceptionHandler; + if (!Debugger.IsAttached) + { + AppDomain.CurrentDomain.UnhandledException += ExceptionHandler; + } AppDomain.CurrentDomain.DomainUnload += (sender, args) => { _logStream.WriteLine("Unload application"); @@ -172,9 +176,12 @@ namespace SM.Base Write(e.IsTerminating ? "Terminating Error" : LogType.Error.ToString(), e.IsTerminating ? ConsoleColor.DarkRed : ConsoleColor.Red, e.ExceptionObject); + MethodBase info = (e.ExceptionObject as Exception).TargetSite; + string name = $"{info.ReflectedType.Namespace}.{info.ReflectedType.Name}.{info.Name}".Replace(".", "::"); + if (e.IsTerminating) { - MessageBox.Show($"Critical error occured.\n\n{e.ExceptionObject}", + MessageBox.Show($"Critical error occured at {name}.\n\n{e.ExceptionObject}", $"Terminating Error: {e.ExceptionObject.GetType().Name}"); _logStream?.Close(); } diff --git a/src/renderer/SM.Base/PostEffects/BloomEffect.cs b/src/renderer/SM.Base/PostEffects/BloomEffect.cs index fe8426b..8c5cac7 100644 --- a/src/renderer/SM.Base/PostEffects/BloomEffect.cs +++ b/src/renderer/SM.Base/PostEffects/BloomEffect.cs @@ -1,212 +1,200 @@ -#region usings - -using System.Drawing; -using OpenTK; +using OpenTK; +using OpenTK.Graphics; using OpenTK.Graphics.OpenGL4; -using SM.Base.Drawing; using SM.Base.PostProcess; using SM.Base.Utility; using SM.Base.Window; using SM.OGL.Framebuffer; +using SM.OGL.Shaders; using SM.OGL.Texture; - -#endregion +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; namespace SM.Base.PostEffects { /// - /// A bloom post process effect. + /// The recommended bloom effect, that looks way better than the old one. + /// Based on Blender's implermentation, which is based on COD: Infinite Warfare. /// - public class BloomEffect : PostProcessEffect + public class BloomEffect : PostProcess.PostProcessEffect { - private static BezierCurve _defaultCurve = new BezierCurve(Vector2.UnitY, Vector2.Zero, new Vector2(0.4f, 0), new Vector2(.5f,0)); - private static readonly PostProcessShader _mergeShader = new PostProcessShader( - AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom_merge_vert.glsl"), - AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom_merge.glsl")); + private static readonly ShaderFile samplingFile = new ShaderFile(AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom.sampling.frag")); - private static readonly PostProcessShader _shader = - new PostProcessShader(AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom_blur.glsl")); - private const float _defaultTextureScale = .75f; + private static readonly PostProcessShader _filterShader = new PostProcessShader( + AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom.filter.frag") + ); + private static readonly PostProcessShader _downsampleShader = new PostProcessShader( + AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom.downsample.frag") + ); + private static readonly PostProcessShader _upsampleShader = new PostProcessShader( + AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom.upsample.frag") + ); + private static readonly PostProcessShader _combineShader = new PostProcessShader( + AssemblyUtility.ReadAssemblyFile(SMRenderer.PostProcessPath + ".bloom.combine.frag") + ); - private Framebuffer _source; + static BloomEffect() + { + _upsampleShader.ShaderFiles.Fragment[0].GLSLExtensions.Add(samplingFile); + _combineShader.ShaderFiles.Fragment[0].GLSLExtensions.Add(samplingFile); + } - private Framebuffer _bloomBuffer1; - private Framebuffer _bloomBuffer2; + const int MAXBLOOMSTEPS = 8; + const float INTENSITY = .1f; private readonly bool _hdr; - private readonly float _textureScale = .75f; + private List _downsampler; + private List _upsample; - private BezierCurve _weightCurve; - private float[] _weights; - - private ColorAttachment _xBuffer; - private ColorAttachment _yBuffer; + private int _iterations; + private float _sampleSize; + private Vector4 _thresholdCurve; + private Color4 _bloomColor; /// - /// A texture where you can define the amount of the bloom effect at each pixel. - /// - public TextureBase AmountMap; - /// - /// The transformation for the amount map. - /// - public TextureTransformation AmountTransform = new TextureTransformation(); - /// - /// The maximal amount the amount map is clamped to. - /// Default: 1 - /// - public float MaxAmount = 1; - /// - /// The minimal amount the amount map is clamped to. - /// Default: 0 - /// - public float MinAmount = 0; - - /// - /// The defines how often the x-y-flipflop happens. - /// Default: 8 - /// - public int Iterations = 8; - /// - /// The Threshold for the bloom effect. - /// Default: .8f + /// The threshold, where the effect decided what is bright. /// public float Threshold = .8f; /// - /// Increases the brightness of the resulting effect. - /// Default: 1 + /// The radius of the effect. /// - public float Power = 1; + public float Radius = 6.5f; + /// + /// Makes transition between under/over-threshold gradual. + /// + public float Knee = .5f; + /// + /// The intensity of the effect. + /// + public float Intensity = .5f; + /// + /// The tint of the effect. + /// + public Color4 Color = Color4.White; /// - /// Radius of the effect - /// Default: 2 + /// This creates a more prettier bloom effect. /// - public float Radius = 1; - - /// - /// This can disable the bloom calculation. - /// Default: true - /// - public bool Enable = true; - - /// - /// This defines the weight curve. - /// - public BezierCurve WeightCurve - { - get => _weightCurve; - set - { - _weightCurve = value; - UpdateWeights(); - } - } - /// - /// This defines how many picks the effect should pick from the weight curve. - /// - public int WeightCurvePickAmount = 4; - - /// - /// This creates a bloom effect. - /// - /// This can specify a own source framebuffer. If not set, it will take the Pipeline MainFramebuffer. /// This allows to enable hdr returns. - /// This allows for a increase in performance, by lowering the calculating texture scale. - public BloomEffect(Framebuffer source = null, bool hdr = false, float? textureScale = null) + public BloomEffect(bool hdr = false) { - _source = source; _hdr = hdr; - _textureScale = textureScale.GetValueOrDefault(_defaultTextureScale); - - WeightCurve = _defaultCurve; } + /// + protected override void InitProcess() => CreateFramebuffers(); - - private void UpdateWeights() + private void CreateFramebuffers() { - _weights = new float[WeightCurvePickAmount]; + if (_downsampler != null) _downsampler.ForEach(a => a.Reset()); + if (_upsample != null) _upsample.ForEach(a => a.Reset()); - for (int i = 0; i < WeightCurvePickAmount; i++) - _weights[i] = _weightCurve.CalculatePoint((float) (i + 1) / (WeightCurvePickAmount + 1)).Y; + _downsampler = new List(); + _upsample = new List(); + + Vector2 windowSize = Pipeline.ConnectedWindow.WindowSize; + + float minDim = (float)Math.Min(windowSize.X, windowSize.Y); + float maxIter = (Radius - 8.0f) + (float)(Math.Log(minDim) / Math.Log(2)); + int maxIterInt = (int)maxIter; + + _iterations = Math.Max(Math.Min(MAXBLOOMSTEPS, maxIterInt), 1); + + _sampleSize = .5f + maxIter - maxIterInt; + _thresholdCurve = new Vector4( + Threshold - Knee, + Knee * 2, + 0.25f / Math.Max(1e-5f, Knee), + Threshold); + + float intens = (Intensity * INTENSITY); + _bloomColor = new Color4(Color.R * intens, Color.G * intens, Color.B * intens, 1f); + + PixelInformation pixel = new PixelInformation(PixelInternalFormat.R11fG11fB10f, PixelFormat.Rgb, PixelType.Float); + + Vector2 texSize = windowSize; + Framebuffer f = new Framebuffer(texSize); + f.Append("0", new ColorAttachment(0, pixel)); + f.Append("1", new ColorAttachment(1, pixel)); + _downsampler.Add(f); + for (int i = 0; i < _iterations; i++) + { + texSize /= 2; + + + + f = new Framebuffer(texSize); + f.Append("0", new ColorAttachment(0, pixel)); + _downsampler.Add(f); + + if (i == _iterations - 1) break; + f = new Framebuffer(texSize); + f.Append("0", new ColorAttachment(0, pixel)); + _upsample.Add(f); + } } /// - protected override void InitProcess() + public override void ScreenSizeChanged(IGenericWindow window) { - _source ??= Pipeline.MainFramebuffer; - - _source.ColorAttachments["color"].PixelInformation = PixelInformation.RGBA_HDR; - - _bloomBuffer1 = new Framebuffer(Pipeline.ConnectedWindow, _textureScale) - { - Name = "BloomX" - }; - _bloomBuffer1.Append("xBuffer", _xBuffer = new ColorAttachment(0, PixelInformation.RGBA_HDR)); - _bloomBuffer1.Compile(); - _bloomBuffer2 = new Framebuffer(Pipeline.ConnectedWindow, _textureScale) - { - Name = "BloomY" - }; - _bloomBuffer2.Append("yBuffer", _yBuffer = new ColorAttachment(0, PixelInformation.RGBA_HDR)); - _bloomBuffer2.Compile(); - - Pipeline.Framebuffers.Add(_bloomBuffer1); - Pipeline.Framebuffers.Add(_bloomBuffer2); + CreateFramebuffers(); } /// - public override void Draw(ColorAttachment source, DrawContext context) + protected override void Drawing(ColorAttachment source, DrawContext context) { - if (Enable) - { - GL.Viewport(0, 0, (int) (Pipeline.ConnectedWindow.Width * _textureScale), - (int) (Pipeline.ConnectedWindow.Height * _textureScale)); + Framebuffer target = Framebuffer.GetCurrentlyActive(); - Framebuffer target = Framebuffer.GetCurrentlyActive(); - bool first = true, hoz = true; - int iter = Iterations * 2; - for (int i = 0; i < iter; i++) + // Filtering + _downsampler[0].Activate(true); + _filterShader.Draw(source, col => + { + col["ThresholdCurve"].SetVector4(_thresholdCurve); + }); + + // Downsampling + ColorAttachment last = _downsampler[0]["0"]; + for(int i = 1; i < _iterations; i++) + { + ColorAttachment downsampleSource = last; + Framebuffer downsampleTarget = _downsampler[i]; + downsampleTarget.Activate(true); + _downsampleShader.Draw(downsampleSource); + + last = downsampleTarget["0"]; + } + + // Upsampling + for (int i = _iterations - 2; i >= 0; i--) + { + ColorAttachment downsampleSource = _downsampler[i]["0"]; + Framebuffer upsampleTarget = _upsample[i]; + + upsampleTarget.Activate(true); + + _upsampleShader.Draw(last, (a) => { - (hoz ? _bloomBuffer1 : _bloomBuffer2).Activate(false); + if (last != null) a["baseBuffer"].SetTexture(downsampleSource); + a["sampleSize"].SetFloat(_sampleSize); + }); - _shader.Draw(collection => - { - collection["renderedTexture"].SetTexture(first ? source : (hoz ? _yBuffer : _xBuffer)); - - collection["First"].SetUniform1(first); - collection["Threshold"].SetUniform1(Threshold); - - collection["Horizontal"].SetUniform1(hoz); - - collection["Weights"].SetUniform1(_weights); - collection["WeightCount"].SetUniform1(WeightCurvePickAmount); - collection["Power"].SetUniform1(Power); - - collection["Radius"].SetUniform1(_textureScale * Radius); - }); - - hoz = !hoz; - if (first) first = false; - } - - GL.Viewport(Pipeline.ConnectedWindow.ClientRectangle); - target.Activate(); + last = upsampleTarget["0"]; } - _mergeShader.Draw(collection => + // combine + target.Activate(true); + _combineShader.Draw(last, (a) => { - collection["Scene"].SetTexture(source); - collection["Bloom"].SetTexture(_yBuffer); + a["sampleSize"].SetFloat(_sampleSize); - collection["MinAmount"].SetUniform1(MinAmount); - collection["MaxAmount"].SetUniform1(MaxAmount); - collection["AmountMap"].SetTexture(AmountMap, collection["HasAmountMap"]); - collection["TextureTransform"].SetMatrix3(AmountTransform.GetMatrix()); + a["scene"].SetTexture(_downsampler[0]["1"]); + a["bloomColor"].SetColor(_bloomColor); - collection["Exposure"].SetUniform1(context.UseCamera.Exposure); - collection["HDR"].SetUniform1(_hdr); + a["HDR"].SetBool(_hdr); }); } } -} \ No newline at end of file +} diff --git a/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs b/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs index 55bef36..c925965 100644 --- a/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs +++ b/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs @@ -52,8 +52,8 @@ namespace SM.Base.PostEffects { _hdrExposureShader.Draw(u => { - u["Gamma"].SetUniform1(Gamma); - u["Exposure"].SetUniform1(exposure); + u["Gamma"].SetFloat(Gamma); + u["Exposure"].SetFloat(exposure); u["Scene"].SetTexture(attachment); }); } @@ -66,7 +66,7 @@ namespace SM.Base.PostEffects { _gammaShader.Draw(u => { - u["Gamma"].SetUniform1(Gamma); + u["Gamma"].SetFloat(Gamma); u["Scene"].SetTexture(attachment); }); } diff --git a/src/renderer/SM.Base/PostEffects/Shaders/bloom/combine.frag b/src/renderer/SM.Base/PostEffects/Shaders/bloom/combine.frag new file mode 100644 index 0000000..e72ba87 --- /dev/null +++ b/src/renderer/SM.Base/PostEffects/Shaders/bloom/combine.frag @@ -0,0 +1,32 @@ +#version 330 core + +in vec2 vTexture; + +uniform sampler2D scene; +uniform vec4 bloomColor; +uniform bool HDR; + +vec3 safe_color(vec3 c) { + return clamp(c, vec3(0.0), vec3(1e20)); +} + +vec3 upsample_filter_high(); + +layout(location = 0) out vec4 color; + +vec3 reinhardTone(vec3 col) { + return col / (col + vec3(1.0)); +} + +void main() { + + vec3 scene = safe_color(texture2D(scene, vTexture).rgb); + vec3 blur = upsample_filter_high() * bloomColor.rgb; + + if (HDR) { + color = vec4(scene + blur, 1); + return; + } + + color = vec4(scene + reinhardTone(blur), 1); +} diff --git a/src/renderer/SM.Base/PostEffects/Shaders/bloom/downsample.frag b/src/renderer/SM.Base/PostEffects/Shaders/bloom/downsample.frag new file mode 100644 index 0000000..b2fec34 --- /dev/null +++ b/src/renderer/SM.Base/PostEffects/Shaders/bloom/downsample.frag @@ -0,0 +1,41 @@ +#version 330 core + +uniform vec2 renderedTextureTexelSize; + +vec4 GetRenderColor(); +vec4 GetRenderColorOffset(vec2); + +float getBrightness(vec3 col) { + return max(col.r, max(col.g, col.b)); + return (col.r + col.r + col.b + col.g + col.g + col.g) / 6.0; +} + +layout(location = 0) out vec4 color; + +vec3 downsample_high() { + vec4 d = renderedTextureTexelSize.xyxy * vec4(-1,-1, +1, +1); + vec3 s1 = GetRenderColorOffset(d.xy).rgb; // - - + // X - + + vec3 s2 = GetRenderColorOffset(d.zy).rgb; // - - + // - X + + vec3 s3 = GetRenderColorOffset(d.xw).rgb; // X - + // - - + + vec3 s4 = GetRenderColorOffset(d.zw).rgb; // X - + // - - + + float s1w = 1.0 / (getBrightness(s1) + 1.0); + float s2w = 1.0 / (getBrightness(s2) + 1.0); + float s3w = 1.0 / (getBrightness(s3) + 1.0); + float s4w = 1.0 / (getBrightness(s4) + 1.0); + float one_div = 1.0 / (s1w + s2w + s3w + s4w); + + return (s1 * s1w + s2 * s2w + s3 * s3w + s4 * s4w) * one_div; +} + +void main() { + + color = vec4(downsample_high(),1); +} diff --git a/src/renderer/SM.Base/PostEffects/Shaders/bloom/filter.frag b/src/renderer/SM.Base/PostEffects/Shaders/bloom/filter.frag new file mode 100644 index 0000000..c14ccf8 --- /dev/null +++ b/src/renderer/SM.Base/PostEffects/Shaders/bloom/filter.frag @@ -0,0 +1,48 @@ +#version 330 core + +uniform vec4 ThresholdCurve; +uniform vec2 renderedTextureTexelSize; + +vec4 GetRenderColorOffset(vec2); + +layout(location = 0) out vec4 color; +layout(location = 1) out vec4 scene; + +vec3 safe_color(vec3 c) { + return clamp(c, vec3(0.0), vec3(1e20)); +} +vec3 median(vec3 a, vec3 b, vec3 c) +{ + return a + b + c - min(min(a, b), c) - max(max(a, b), c); +} + +float getBrightness(vec3 col) { + + return max(col.r, max(col.g, col.b)); + return (col.r + col.r + col.b + col.g + col.g + col.g) / 6.0; +} + +void main() { + scene = vec4(safe_color(GetRenderColorOffset(vec2(0)).rgb), 1); + + vec3 d = renderedTextureTexelSize.xyx * vec3(1,1,0); + vec3 s0 = scene.rgb + vec3(.1); + vec3 s1 = safe_color(GetRenderColorOffset(-d.xz).rgb) + vec3(.1); + vec3 s2 = safe_color(GetRenderColorOffset(+d.xz).rgb) + vec3(.1); + vec3 s3 = safe_color(GetRenderColorOffset(-d.zy).rgb) + vec3(.1); + vec3 s4 = safe_color(GetRenderColorOffset(+d.zy).rgb) + vec3(.1); + vec3 col = median(median(s0, s1, s2), s3, s4); + float br = getBrightness(col); + + /*vec3 col = safe_color(GetRenderColor().rgb); + float br = getBrightness(col);*/ + + + float rq = clamp(br - ThresholdCurve.x, 0, ThresholdCurve.y); + rq = ThresholdCurve.z * rq * rq; + + float resultBr = max(rq, br - ThresholdCurve.w) / max(1e-5, br); + col *= resultBr; + + color = vec4(col, 1); +} diff --git a/src/renderer/SM.Base/PostEffects/Shaders/bloom/sampling.frag b/src/renderer/SM.Base/PostEffects/Shaders/bloom/sampling.frag new file mode 100644 index 0000000..46054ee --- /dev/null +++ b/src/renderer/SM.Base/PostEffects/Shaders/bloom/sampling.frag @@ -0,0 +1,30 @@ +#version 330 core + + +uniform vec2 renderedTextureTexelSize; +uniform float sampleSize; + +vec4 GetRenderColorOffset(vec2); + + +vec3 upsample_filter_high() { + vec4 d = renderedTextureTexelSize.xyxy * vec4(1, 1,-1,0); + + vec3 s; + // Line + 1 + s = GetRenderColorOffset(d.zy).rgb; // x - - + s += GetRenderColorOffset(d.wy).rgb * 2; // - X - + s += GetRenderColorOffset(d.xy).rgb; // - - X + + // Line 0 + s += GetRenderColorOffset(d.zw).rgb * 2; // X - - + s += GetRenderColorOffset(vec2(0)).rgb * 4; // - X - + s += GetRenderColorOffset(d.xw).rgb * 2; // - - X + + // Line - 1 + s += GetRenderColorOffset(d.zz).rgb; // X - - + s += GetRenderColorOffset(d.wz).rgb * 2; // - X - + s += GetRenderColorOffset(d.xz).rgb; // - - X + + return s * 0.0625; // 1 / 16 = 0.0625 +} \ No newline at end of file diff --git a/src/renderer/SM.Base/PostEffects/Shaders/bloom/upsample.frag b/src/renderer/SM.Base/PostEffects/Shaders/bloom/upsample.frag new file mode 100644 index 0000000..38c530f --- /dev/null +++ b/src/renderer/SM.Base/PostEffects/Shaders/bloom/upsample.frag @@ -0,0 +1,13 @@ +#version 330 core + +in vec2 vTexture; + +uniform sampler2D baseBuffer; + +layout(location = 0) out vec4 color; + +vec3 upsample_filter_high(); + +void main() { + color = vec4(texture2D(baseBuffer, vTexture).rgb + upsample_filter_high(),1); +} diff --git a/src/renderer/SM.Base/PostEffects/Shaders/bloom_merge_vert.glsl b/src/renderer/SM.Base/PostEffects/Shaders/bloom_merge_vert.glsl deleted file mode 100644 index 127a8b5..0000000 --- a/src/renderer/SM.Base/PostEffects/Shaders/bloom_merge_vert.glsl +++ /dev/null @@ -1,11 +0,0 @@ -#version 330 - -layout(location = 1) in vec2 aTex; - -uniform mat3 TextureTransform; - -out vec2 TransformedTexture; - -void vertex() { - TransformedTexture = vec2(TextureTransform * vec3(aTex, 1)); -} \ No newline at end of file diff --git a/src/renderer/SM.Base/PostEffects/Shaders/finalize_hdr.glsl b/src/renderer/SM.Base/PostEffects/Shaders/finalize_hdr.glsl index 59406bc..696e186 100644 --- a/src/renderer/SM.Base/PostEffects/Shaders/finalize_hdr.glsl +++ b/src/renderer/SM.Base/PostEffects/Shaders/finalize_hdr.glsl @@ -8,8 +8,28 @@ uniform float Gamma; layout(location = 0) out vec4 color; +vec3 ACES(vec3 x) { + const float a = 2.51; + const float b = 0.03; + const float c = 2.43; + const float d = 0.59; + const float e = 0.14; + + return clamp((x * (a * x + b)) / (x * (c * x + d) + e), 0,1.0); +} + +vec3 reinhardTone(vec3 col) { + return col / (col + vec3(1.0)); +} + +vec3 exposure(vec3 scene) { + return vec3(1) - exp(-texture(Scene, vTexture).rgb * Exposure); +} + void main() { - vec3 result = vec3(1) - exp(-texture(Scene, vTexture).rgb * Exposure); + + vec3 scene = texture2D(Scene, vTexture).rgb; + vec3 result = reinhardTone(scene); color = vec4(pow(result, vec3(1 / Gamma)), 1); } \ No newline at end of file diff --git a/src/renderer/SM.Base/PostProcess/PostProcessEffect.cs b/src/renderer/SM.Base/PostProcess/PostProcessEffect.cs index 3767ace..d60d22b 100644 --- a/src/renderer/SM.Base/PostProcess/PostProcessEffect.cs +++ b/src/renderer/SM.Base/PostProcess/PostProcessEffect.cs @@ -24,6 +24,12 @@ namespace SM.Base.PostProcess /// protected RenderPipeline Pipeline; + /// + /// Enables the effect. + /// Default: true + /// + public bool Enable = true; + /// /// Initialize the effect. /// @@ -41,11 +47,20 @@ namespace SM.Base.PostProcess { } + /// + /// This executes + /// + /// + /// + public void Draw(ColorAttachment source, DrawContext context) + { + if (Enable) Drawing(source, context); + } /// /// Method to draw the actual effect. /// - public abstract void Draw(ColorAttachment source, DrawContext context); + protected abstract void Drawing(ColorAttachment source, DrawContext context); /// /// Event, when the scene changed. @@ -53,5 +68,14 @@ namespace SM.Base.PostProcess public virtual void SceneChanged(GenericScene scene) { } + + /// + /// Event, when the screen size changed. + /// + /// Window that changed + public virtual void ScreenSizeChanged(IGenericWindow window) + { + + } } } \ No newline at end of file diff --git a/src/renderer/SM.Base/PostProcess/PostProcessShader.cs b/src/renderer/SM.Base/PostProcess/PostProcessShader.cs index c364588..e2477b8 100644 --- a/src/renderer/SM.Base/PostProcess/PostProcessShader.cs +++ b/src/renderer/SM.Base/PostProcess/PostProcessShader.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using OpenTK.Graphics.OpenGL4; using SM.Base.Objects.Static; using SM.Base.Utility; +using SM.OGL.Framebuffer; using SM.OGL.Shaders; #endregion @@ -25,6 +26,20 @@ namespace SM.Base.PostProcess private static readonly string _normalVertexWithExt = AssemblyUtility.ReadAssemblyFile("SM.Base.PostProcess.DefaultFiles.vertexWithExt.vert"); + /// + /// Generates an action for the texture handling. + /// + /// + /// + public static Action DefaultTextureAction(ColorAttachment renderedTexture) + { + return (col) => + { + col["renderedTexture"].SetTexture(renderedTexture); + col["renderedTextureTexelSize"].SetVector2(renderedTexture.TexelSize); + }; + } + /// /// Creates the shader with the default vertex shader and custom fragment. /// @@ -44,6 +59,14 @@ namespace SM.Base.PostProcess }, new ShaderFile(fragment)) { } + /// + /// Creates the shader with an vertex extension and custom fragment. + /// + /// + /// + public PostProcessShader(ShaderFile vertex, string fragment) : this(vertex, new ShaderFile(fragment)) + { + } private PostProcessShader(ShaderFile vertex, ShaderFile fragment) : base( new ShaderFileCollection(vertex, fragment)) @@ -51,10 +74,33 @@ namespace SM.Base.PostProcess fragment.GLSLExtensions.Add(_fragExtensions); } + /// + /// Draws the shader with the color attachment as texture. + /// + /// + public void Draw(ColorAttachment renderedTexture) + { + Draw(DefaultTextureAction(renderedTexture)); + } + + /// + /// Draws the shader with the color attachment as texture and provides access to the uniforms. + /// + /// + /// + public void Draw(ColorAttachment renderedTexture, Action setUniformAction) + { + var texAction = DefaultTextureAction(renderedTexture); + Draw((a) => { + texAction(a); + setUniformAction(a); + }); + } + /// /// Draws the shader with special uniforms. /// - /// + /// public void Draw(Action setUniformAction) { Activate(); diff --git a/src/renderer/SM.Base/SM.Base.csproj b/src/renderer/SM.Base/SM.Base.csproj index f0ea177..dd59076 100644 --- a/src/renderer/SM.Base/SM.Base.csproj +++ b/src/renderer/SM.Base/SM.Base.csproj @@ -13,11 +13,12 @@ Properties SM.Base SM.Base - v4.5.2 + v4.7.1 512 true + true @@ -51,6 +52,7 @@ + @@ -61,6 +63,7 @@ + @@ -71,7 +74,7 @@ - + @@ -115,13 +118,12 @@ - - + + - @@ -139,7 +141,6 @@ ..\..\..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll - True ..\..\..\packages\SharpFont.4.0.1\lib\net45\SharpFont.dll @@ -159,8 +160,14 @@ + + + + + + diff --git a/src/renderer/SM.Base/Shaders/SimpleShader.cs b/src/renderer/SM.Base/Shaders/SimpleShader.cs index e068e12..5db13b4 100644 --- a/src/renderer/SM.Base/Shaders/SimpleShader.cs +++ b/src/renderer/SM.Base/Shaders/SimpleShader.cs @@ -101,17 +101,19 @@ namespace SM.Base.Shaders .SetMatrix4(context.Instances[0].ModelMatrix * context.ModelMatrix * context.View * context.World); uniforms["MasterTextureMatrix"].SetMatrix3(context.Instances[0].TextureMatrix * context.TextureMatrix); uniforms["HasVColor"] - .SetUniform1(context.Mesh.Attributes.Has("color")); + .SetBool(context.Mesh.Attributes.Has("color")); DrawObject(context.ForcedType.GetValueOrDefault(context.Mesh.PrimitiveType), context.Mesh); } private static void InstancedSetUniforms(UniformCollection uniforms, DrawContext context) { + if (context.Instances == null || context.Instances.Count < 1) return; + uniforms["MVP"].SetMatrix4(context.ModelMatrix * context.View * context.World); uniforms["MasterTextureMatrix"].SetMatrix3(context.TextureMatrix); uniforms["HasVColor"] - .SetUniform1(context.Mesh.Attributes.Has("color")); + .SetBool(context.Mesh.Attributes.Has("color")); UniformArray instances = uniforms.GetArray("Instances"); diff --git a/src/renderer/SM.Base/Shaders/SimpleShaderPresets/basic_vertex.glsl b/src/renderer/SM.Base/Shaders/SimpleShaderPresets/basic_vertex.glsl index 503fb5a..5dd3936 100644 --- a/src/renderer/SM.Base/Shaders/SimpleShaderPresets/basic_vertex.glsl +++ b/src/renderer/SM.Base/Shaders/SimpleShaderPresets/basic_vertex.glsl @@ -1,5 +1,4 @@ #version 330 -#define SM_SIMPLE_EXTENSION //!extension layout(location = 0) in vec3 a_Position; layout(location = 1) in vec2 a_Texture; @@ -13,10 +12,6 @@ out vec3 v_VertexPosition; out vec2 v_TexCoords; out vec4 v_Color; -#if (SM_SIMPLE_EXTENSION == 1) -void v_Extension(); -#endif - void main() { v_Color = vec4(1); if (HasVColor) v_Color = a_Color; @@ -26,7 +21,5 @@ void main() { v_VertexPosition = a_Position; gl_Position = MVP * vec4(a_Position, 1); - #if (SM_SIMPLE_EXTENSION == 1) - v_Extension(); - #endif + } \ No newline at end of file diff --git a/src/renderer/SM.Base/Shaders/SimpleShaderPresets/instanced_vertex.glsl b/src/renderer/SM.Base/Shaders/SimpleShaderPresets/instanced_vertex.glsl index 3565cf6..1f594ae 100644 --- a/src/renderer/SM.Base/Shaders/SimpleShaderPresets/instanced_vertex.glsl +++ b/src/renderer/SM.Base/Shaders/SimpleShaderPresets/instanced_vertex.glsl @@ -1,6 +1,5 @@ #version 330 #define maxInstances //!instanceMax -#define SM_SIMPLE_EXTENSION //!extension struct Instance { mat4 ModelMatrix; @@ -20,10 +19,6 @@ out vec3 v_VertexPosition; out vec2 v_TexCoords; out vec4 v_Color; -#if (SM_SIMPLE_EXTENSION == 1) -void v_Extension(); -#endif - void main() { v_Color = vec4(1); if (HasVColor) v_Color = a_Color; @@ -33,7 +28,4 @@ void main() { v_VertexPosition = a_Position; gl_Position = MVP * Instances[gl_InstanceID].ModelMatrix * vec4(a_Position, 1); - #if (SM_SIMPLE_EXTENSION == 1) - v_Extension(); - #endif } \ No newline at end of file diff --git a/src/renderer/SM.Base/Types/CVector1.cs b/src/renderer/SM.Base/Types/CVector1.cs index b2a80f9..891e8ea 100644 --- a/src/renderer/SM.Base/Types/CVector1.cs +++ b/src/renderer/SM.Base/Types/CVector1.cs @@ -28,21 +28,6 @@ namespace SM.Base.Types /// public float X { get; set; } - /// - /// Interpolates the motion to the target. - /// - /// How long the interpolation should take. - /// The value it should interpolate. - /// The curve how he interpolates. Preset values can be found under . Default: - /// A handle to control the interpolation process. - public InterpolationProcess Interpolate(TimeSpan duration, float to, BezierCurve? interpolationCurve = null) - { - InterpolationProcess process = new InterpolationProcess(this, duration, ConvertToVector4(), new Vector4(to, 0, 0, 0), interpolationCurve.GetValueOrDefault(AnimationCurves.Linear)); - process.Start(); - - return process; - } - /// /// Sets the X-Component. /// diff --git a/src/renderer/SM.Base/Types/CVector2.cs b/src/renderer/SM.Base/Types/CVector2.cs index 8063c6b..5f89219 100644 --- a/src/renderer/SM.Base/Types/CVector2.cs +++ b/src/renderer/SM.Base/Types/CVector2.cs @@ -34,26 +34,7 @@ namespace SM.Base.Types /// Y-component /// public float Y { get; set; } - - /// - /// Interpolates the motion to the target. - /// - /// How long the interpolation should take. - /// The value it should interpolate. - /// The curve how he interpolates. - /// When creating a curve, its recommended the Y-component is always between 0 -> 1. But it could make cool effects if not... - /// Preset curves can be found under . - /// Default: - /// - /// A handle to control the interpolation process. - public InterpolationProcess Interpolate(TimeSpan duration, Vector2 to, BezierCurve? interpolationCurve = null) - { - InterpolationProcess process = new InterpolationProcess(this, duration, ConvertToVector4(), new Vector4(to), interpolationCurve.GetValueOrDefault(AnimationCurves.Linear)); - process.Start(); - - return process; - } - + /// public override string ToString() { diff --git a/src/renderer/SM.Base/Types/CVector3.cs b/src/renderer/SM.Base/Types/CVector3.cs index 64231f0..e5dfd92 100644 --- a/src/renderer/SM.Base/Types/CVector3.cs +++ b/src/renderer/SM.Base/Types/CVector3.cs @@ -34,22 +34,7 @@ namespace SM.Base.Types /// Z-component /// public float Z { get; set; } - - /// - /// Interpolates the motion to the target. - /// - /// How long the interpolation should take. - /// The value it should interpolate. - /// The curve how he interpolates. Preset values can be found under . Default: - /// A handle to control the interpolation process. - public InterpolationProcess Interpolate(TimeSpan duration, Vector3 to, BezierCurve? interpolationCurve = null) - { - InterpolationProcess process = new InterpolationProcess(this, duration, ConvertToVector4(), new Vector4(to, 0), interpolationCurve.GetValueOrDefault(AnimationCurves.Linear)); - process.Start(); - - return process; - } - + /// public override string ToString() diff --git a/src/renderer/SM.Base/Types/CVector4.cs b/src/renderer/SM.Base/Types/CVector4.cs index 5429a41..90addab 100644 --- a/src/renderer/SM.Base/Types/CVector4.cs +++ b/src/renderer/SM.Base/Types/CVector4.cs @@ -23,22 +23,7 @@ namespace SM.Base.Types { W = w; } - - /// - /// Interpolates the motion to the target. - /// - /// How long the interpolation should take. - /// The value it should interpolate. - /// The curve how he interpolates. Preset values can be found under . Default: - /// A handle to control the interpolation process. - public InterpolationProcess Interpolate(TimeSpan duration, Vector4 to, BezierCurve? interpolationCurve = null) - { - InterpolationProcess process = new InterpolationProcess(this, duration, ConvertToVector4(), to, interpolationCurve.GetValueOrDefault(AnimationCurves.Linear)); - process.Start(); - - return process; - } - + /// public override void Set(float uniform, bool triggerChanged = true) { diff --git a/src/renderer/SM.Base/Types/CVectorBase.cs b/src/renderer/SM.Base/Types/CVectorBase.cs index 2340b84..39d5831 100644 --- a/src/renderer/SM.Base/Types/CVectorBase.cs +++ b/src/renderer/SM.Base/Types/CVectorBase.cs @@ -1,5 +1,8 @@ using System; using OpenTK; +using OpenTK.Audio.OpenAL; +using OpenTK.Graphics.OpenGL; +using SM.Base.Animation; namespace SM.Base.Types { @@ -48,6 +51,62 @@ namespace SM.Base.Types NormalizationProcess(length); } + /// + /// Interpolates the motion to the target. + /// + /// How long the interpolation should take. + /// The value it should interpolate. + /// The curve how he interpolates. Preset values can be found under . Default: + /// Auto-starts the interpolation process. + /// A handle to control the interpolation process. + public InterpolationProcess Interpolate(TimeSpan duration, TInterpolateType to, BezierCurve? interpolationCurve = null, bool autoStart = true) + where TInterpolateType : struct + { + return Interpolate(duration, ConvertToVector4(), to, interpolationCurve, autoStart); + } + + /// + /// Interpolates the motion to the target. + /// + /// How long the interpolation should take. + /// The value it should start with. + /// The value it should interpolate. + /// The curve how he interpolates. Preset values can be found under . Default: + /// Auto-starts the interpolation process. + /// A handle to control the interpolation process. + public InterpolationProcess Interpolate(TimeSpan duration, TInterpolateType from, TInterpolateType to, BezierCurve? interpolationCurve = null, bool autoStart = true) + where TInterpolateType : struct + { + Vector4 start = from switch + { + float f => new Vector4(f, 0, 0, 0), + Vector2 v2 => new Vector4(v2.X, v2.Y, 0, 0), + Vector3 v3 => new Vector4(v3.X, v3.Y, v3.Z, 0), + Vector4 v4 => v4, + _ => throw new Exception("[INTERPOLATION] Only float, OpenTK.Vector2, OpenTK.Vector3, OpenTK.Vector4 are allowed as types.") + }; + + return Interpolate(duration, start, to, interpolationCurve, autoStart); + } + + internal InterpolationProcess Interpolate(TimeSpan duration, Vector4 from, TInterpolateType to, BezierCurve? interpolationCurve = null, bool autoStart = true) + where TInterpolateType : struct + { + Vector4 target = to switch + { + float f => new Vector4(f, 0, 0, 0), + Vector2 v2 => new Vector4(v2.X, v2.Y, 0, 0), + Vector3 v3 => new Vector4(v3.X, v3.Y, v3.Z, 0), + Vector4 v4 => v4, + _ => throw new Exception("[INTERPOLATION] Only float, OpenTK.Vector2, OpenTK.Vector3, OpenTK.Vector4 are allowed as types.") + }; + + InterpolationProcess process = new InterpolationProcess(this, duration, from, target, interpolationCurve.GetValueOrDefault(AnimationCurves.Linear)); + if (autoStart) process.Start(); + + return process; + } + /// /// Sets the values of the vector, by providing the values over an array. /// diff --git a/src/renderer/SM.Base/Utility/MathUtils.cs b/src/renderer/SM.Base/Utility/MathUtils.cs new file mode 100644 index 0000000..0e92156 --- /dev/null +++ b/src/renderer/SM.Base/Utility/MathUtils.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SM.Base.Utility +{ + class MathUtils + { + public static float Lerp(float start, float end, float t) + { + return start + t * (end - start); + } + } +} diff --git a/src/renderer/SM.Base/Window/RenderPipeline.cs b/src/renderer/SM.Base/Window/RenderPipeline.cs index b9f89dd..906a288 100644 --- a/src/renderer/SM.Base/Window/RenderPipeline.cs +++ b/src/renderer/SM.Base/Window/RenderPipeline.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Threading; using SM.Base.Drawing; +using SM.Base.PostProcess; using SM.Base.Shaders; using SM.Base.Utility; using SM.OGL.Framebuffer; @@ -17,6 +18,11 @@ namespace SM.Base.Window /// public abstract class RenderPipeline : IInitializable { + /// + /// All post processing effects should go here, that should be automaticly managed. + /// + protected List PostProcessEffects = new List(); + /// /// This contains the windows its connected to. /// @@ -47,9 +53,7 @@ namespace SM.Base.Window /// public virtual void Activate() - { - } - + { } /// public virtual void Initialization() { @@ -73,11 +77,26 @@ namespace SM.Base.Window /// /// The event when resizing. /// - public virtual void Resize() + public virtual void Resize(IGenericWindow window) { Recompile(); + + foreach (PostProcessEffect effect in PostProcessEffects) + { + effect.ScreenSizeChanged(window); + } } + /// + /// Initilizes the collected post processing effects. + /// + protected void InitizePostProcessing() + { + foreach (PostProcessEffect effect in PostProcessEffects) + { + effect.Initilize(this); + } + } /// /// Compiles the framebuffers. @@ -116,11 +135,11 @@ namespace SM.Base.Window public Framebuffer CreateWindowFramebuffer(int multisamples = 0, PixelInformation? pixelInformation = null, bool depth = true) { Framebuffer framebuffer = new(ConnectedWindow); - framebuffer.Append("color", new ColorAttachment(0, pixelInformation.GetValueOrDefault(PixelInformation.RGBA_LDR), multisamples)); + framebuffer.Append("color", new ColorAttachment(0, pixelInformation.GetValueOrDefault(PixelInformation.RGBA_LDR), multisamples:multisamples)); if (depth) { - RenderbufferAttachment depthAttach = RenderbufferAttachment.Depth; + RenderbufferAttachment depthAttach = RenderbufferAttachment.GenerateDepth(); depthAttach.Multisample = multisamples; framebuffer.AppendRenderbuffer(depthAttach); } diff --git a/src/renderer/SM.Base/Window/WindowCode.cs b/src/renderer/SM.Base/Window/WindowCode.cs index 6270a52..8cdd501 100644 --- a/src/renderer/SM.Base/Window/WindowCode.cs +++ b/src/renderer/SM.Base/Window/WindowCode.cs @@ -60,14 +60,17 @@ namespace SM.Base.Window { window.WindowSize = new Vector2(window.Width, window.Height); window.AspectRatio = (float) window.Width / window.Height; - GL.Viewport(window.ClientRectangle); - window.CurrentRenderPipeline?.Resize(); + if (window.WindowSize.LengthSquared == 0) return; + + GL.Viewport(window.ClientRectangle); + PostProcessEffect.Mvp = Matrix4.CreateScale(window.Width, -window.Height, 1) * Matrix4.LookAt(Vector3.UnitZ, Vector3.Zero, Vector3.UnitY) * Matrix4.CreateOrthographic(window.Width, window.Height, .1f, 100f); + window.CurrentRenderPipeline?.Resize(window); window.AppliedSetup?.Resize(window); } diff --git a/src/renderer/SM.Base/packages.config b/src/renderer/SM.Base/packages.config index e8dfb8b..85e4bbb 100644 --- a/src/renderer/SM.Base/packages.config +++ b/src/renderer/SM.Base/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file diff --git a/src/renderer/SM.OGL/Framebuffer/ColorAttachment.cs b/src/renderer/SM.OGL/Framebuffer/ColorAttachment.cs index cf3678a..d95c6e1 100644 --- a/src/renderer/SM.OGL/Framebuffer/ColorAttachment.cs +++ b/src/renderer/SM.OGL/Framebuffer/ColorAttachment.cs @@ -1,6 +1,7 @@ #region usings using System; +using OpenTK; using OpenTK.Graphics.OpenGL4; using SM.OGL.Texture; @@ -21,6 +22,14 @@ namespace SM.OGL.Framebuffer /// public int AttachmentID { get; } + /// + /// Contains the framebuffer its connected. + /// Usually the last framebuffer, that called the Compile-method. + /// + public Framebuffer ConnectedFramebuffer { get; private set; } + + public Vector2? AttachmentSize = null; + /// /// Returns the of this ColorAttachment. /// @@ -47,7 +56,7 @@ namespace SM.OGL.Framebuffer /// Creates a attachment with a specific id. /// /// - public ColorAttachment(int attachmentId) : this(attachmentId, PixelInformation.RGBA_LDR) + public ColorAttachment(int attachmentId, Vector2? size = null) : this(attachmentId, PixelInformation.RGBA_LDR, size) { } /// @@ -56,12 +65,16 @@ namespace SM.OGL.Framebuffer /// /// /// - public ColorAttachment(int attachmentID, PixelInformation pixelInformation, int multisamples = 0) + public ColorAttachment(int attachmentID, PixelInformation pixelInformation, Vector2? size = null, int multisamples = 0) { AttachmentID = attachmentID; PixelInformation = pixelInformation; + AttachmentSize = size; + _multisamples = multisamples; Target = IsMultisampled ? TextureTarget.Texture2DMultisample : TextureTarget.Texture2D; + + WrapMode = TextureWrapMode.ClampToEdge; } /// /// Generates the attachment. @@ -70,6 +83,7 @@ namespace SM.OGL.Framebuffer public void Generate(Framebuffer f) { _id = GL.GenTexture(); + ConnectedFramebuffer = f; if (IsMultisampled) GenerateMultisampledTexture(f); else GenerateTexture(f); @@ -77,29 +91,33 @@ namespace SM.OGL.Framebuffer private void GenerateTexture(Framebuffer f) { - GL.BindTexture(TextureTarget.Texture2D, _id); - GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInformation.InternalFormat, - (int)f.Size.X, (int)f.Size.Y, - 0, PixelInformation.Format, PixelInformation.DataType, IntPtr.Zero); + Vector2 size = AttachmentSize.GetValueOrDefault(f.Size); - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, - (int)TextureMinFilter.Linear); - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, - - (int)TextureMinFilter.Linear); - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, - (int)TextureParameterName.ClampToEdge); - GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, - (int)TextureParameterName.ClampToEdge); - - GL.BindTexture(TextureTarget.Texture2D, 0); + GenerateBaseTexture(size); } private void GenerateMultisampledTexture(Framebuffer f) { - GL.BindTexture(TextureTarget.Texture2DMultisample, _id); - GL.TexImage2DMultisample(TextureTargetMultisample.Texture2DMultisample, _multisamples, PixelInformation.InternalFormat, (int)f.Size.X, (int)f.Size.Y, true); - GL.BindTexture(TextureTarget.Texture2DMultisample, 0); + Vector2 size = AttachmentSize.GetValueOrDefault(f.Size); + + Width = (int)size.X; + Height = (int)size.Y; + + const TextureTarget target = TextureTarget.Texture2DMultisample; + + GL.BindTexture(target, _id); + GL.TexImage2DMultisample((TextureTargetMultisample)target, _multisamples, PixelInformation.InternalFormat, + Width, Height, true); + /* + GL.TexParameter(target, TextureParameterName.TextureMinFilter, (int)Filter); + GL.TexParameter(target, TextureParameterName.TextureMagFilter, (int)Filter); + + GL.TexParameter(target, TextureParameterName.TextureWrapS, + (int)WrapMode); + GL.TexParameter(target, TextureParameterName.TextureWrapT, + (int)WrapMode);*/ + + GL.BindTexture(target, 0); } } } \ No newline at end of file diff --git a/src/renderer/SM.OGL/Framebuffer/Framebuffer.cs b/src/renderer/SM.OGL/Framebuffer/Framebuffer.cs index 628e807..da98b79 100644 --- a/src/renderer/SM.OGL/Framebuffer/Framebuffer.cs +++ b/src/renderer/SM.OGL/Framebuffer/Framebuffer.cs @@ -15,6 +15,10 @@ namespace SM.OGL.Framebuffer /// public class Framebuffer : GLObject { + static Framebuffer CurrentlyActiveFramebuffer; + static Framebuffer CurrentlyActiveDrawFramebuffer; + static Framebuffer CurrentlyActiveReadFramebuffer; + /// protected override bool AutoCompile { get; set; } = true; @@ -48,6 +52,8 @@ namespace SM.OGL.Framebuffer public bool DefaultApplyViewport { get; set; } = true; + public ColorAttachment FirstColorAttachment { get; private set; } + /// /// Contains all color attachments. /// @@ -56,7 +62,7 @@ namespace SM.OGL.Framebuffer /// /// Contains the current renderbuffer attachments of the framebuffer. /// - public Dictionary RenderbufferAttachments { get; } = new Dictionary(); + public List RenderbufferAttachments { get; } = new List(); /// /// Gets the color attachment with the specified color name. @@ -116,15 +122,19 @@ namespace SM.OGL.Framebuffer foreach (var pair in ColorAttachments) GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, pair.Value.FramebufferAttachment, pair.Value.Target, pair.Value.ID, 0); + FramebufferErrorCode err; - foreach (RenderbufferAttachment attachment in RenderbufferAttachments.Keys.ToArray()) + err = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer); + if (err != FramebufferErrorCode.FramebufferComplete) + throw new Exception("Failed loading framebuffer.\nProblem: " + err); + + foreach (RenderbufferAttachment attachment in RenderbufferAttachments) { - int att = attachment.Generate(this); - GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, attachment.FramebufferAttachment, RenderbufferTarget.Renderbuffer, att); - RenderbufferAttachments[attachment] = att; + attachment.Generate(this); + GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, attachment.FramebufferAttachment, RenderbufferTarget.Renderbuffer, attachment.ID); } - var err = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer); + err = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer); if (err != FramebufferErrorCode.FramebufferComplete) throw new Exception("Failed loading framebuffer.\nProblem: " + err); @@ -132,15 +142,25 @@ namespace SM.OGL.Framebuffer GL.BindTexture(TextureTarget.Texture2D, 0); } + /// + /// Disposes and clears the attachment + /// + public void Reset() + { + Dispose(); + ColorAttachments.Clear(); + RenderbufferAttachments.Clear(); + } + /// public override void Dispose() { - + foreach (var attachment in ColorAttachments.Values) attachment.Dispose(); - foreach (KeyValuePair pair in RenderbufferAttachments.ToArray()) + FirstColorAttachment = null; + foreach (RenderbufferAttachment pair in RenderbufferAttachments.ToArray()) { - GL.DeleteRenderbuffer(pair.Value); - RenderbufferAttachments[pair.Key] = -1; + GL.DeleteRenderbuffer(pair.ID); } GL.DeleteFramebuffer(this); base.Dispose(); @@ -150,12 +170,14 @@ namespace SM.OGL.Framebuffer /// /// Appends a color attachment. /// - public void Append(string key, int pos) => Append(key, new ColorAttachment(pos)); + public void Append(string key, int pos) => Append(key, new ColorAttachment(pos, null)); + public void Append(string key, Vector2 size, int pos) => Append(key, new ColorAttachment(pos, size)); /// /// Appends a color attachment. /// public void Append(string key, ColorAttachment value) { + if (ColorAttachments.Count == 0) FirstColorAttachment = value; ColorAttachments.Add(key, value); } @@ -165,7 +187,8 @@ namespace SM.OGL.Framebuffer /// public void AppendRenderbuffer(RenderbufferAttachment attachment) { - RenderbufferAttachments.Add(attachment, -1); + if (RenderbufferAttachments.Contains(attachment)) return; + RenderbufferAttachments.Add(attachment); } /// @@ -201,17 +224,55 @@ namespace SM.OGL.Framebuffer /// public void Activate(FramebufferTarget target, ClearBufferMask clear, bool? applyViewport = null) { + switch (target) + { + case FramebufferTarget.ReadFramebuffer: + CurrentlyActiveReadFramebuffer = this; + break; + case FramebufferTarget.DrawFramebuffer: + CurrentlyActiveDrawFramebuffer = this; + break; + case FramebufferTarget.Framebuffer: + CurrentlyActiveFramebuffer = this; + break; + } + GL.BindFramebuffer(target, this); - if (applyViewport.GetValueOrDefault(DefaultApplyViewport)) GL.Viewport(0, 0, (int)Size.X, (int)Size.Y); + if (applyViewport.GetValueOrDefault(DefaultApplyViewport)) + GL.Viewport(0, 0, (int)Size.X, (int)Size.Y); GL.Clear(clear); } + /// + /// Copies content to the specified Framebuffer. + /// + public void CopyTo(Framebuffer target, ClearBufferMask clear = ClearBufferMask.ColorBufferBit, BlitFramebufferFilter filter = BlitFramebufferFilter.Linear) + { + Activate(FramebufferTarget.ReadFramebuffer, false); + target.Activate(FramebufferTarget.DrawFramebuffer, false); + + GL.BlitFramebuffer(0, 0, (int)Size.X, (int)Size.Y, 0, 0, (int)Size.X, (int)Size.Y, clear, filter); + } + /// /// Returns a handle of the current framebuffer. /// /// /// public static Framebuffer GetCurrentlyActive(FramebufferTarget target = FramebufferTarget.Framebuffer) + { + switch (target) + { + case FramebufferTarget.ReadFramebuffer: + return CurrentlyActiveReadFramebuffer ??= getCurrentlyActive(target); + case FramebufferTarget.DrawFramebuffer: + return CurrentlyActiveDrawFramebuffer ??= getCurrentlyActive(target); + case FramebufferTarget.Framebuffer: + return CurrentlyActiveFramebuffer ??= getCurrentlyActive(target); + } + return null; + } + static Framebuffer getCurrentlyActive(FramebufferTarget target = FramebufferTarget.Framebuffer) { Framebuffer buffer = new Framebuffer() { @@ -232,6 +293,8 @@ namespace SM.OGL.Framebuffer break; } + + return buffer; } } diff --git a/src/renderer/SM.OGL/Framebuffer/RenderbufferAttachment.cs b/src/renderer/SM.OGL/Framebuffer/RenderbufferAttachment.cs index 3988bb4..aa35c13 100644 --- a/src/renderer/SM.OGL/Framebuffer/RenderbufferAttachment.cs +++ b/src/renderer/SM.OGL/Framebuffer/RenderbufferAttachment.cs @@ -5,12 +5,12 @@ namespace SM.OGL.Framebuffer /// /// Describes a renderbuffer attachment. /// - public struct RenderbufferAttachment + public class RenderbufferAttachment { /// /// Preset for the depthbuffer attachment. /// - public static readonly RenderbufferAttachment Depth = new RenderbufferAttachment(RenderbufferStorage.Depth24Stencil8, FramebufferAttachment.DepthStencilAttachment); + public static RenderbufferAttachment GenerateDepth() => new RenderbufferAttachment(RenderbufferStorage.Depth24Stencil8, FramebufferAttachment.DepthStencilAttachment); /// /// Storage describes the internal format for the renderbuffer. @@ -26,6 +26,11 @@ namespace SM.OGL.Framebuffer /// public int Multisample; + /// + /// The id that was given to the renderbuffer. + /// + public int ID; + /// /// Constructor /// @@ -34,6 +39,8 @@ namespace SM.OGL.Framebuffer Storage = storage; FramebufferAttachment = framebufferAttachment; Multisample = multisample; + + ID = -1; } /// @@ -41,18 +48,38 @@ namespace SM.OGL.Framebuffer /// /// The framebuffer /// The ID of the renderbuffer. - public int Generate(Framebuffer f) + public void Generate(Framebuffer f) { - int rb = GL.GenRenderbuffer(); + ID = GL.GenRenderbuffer(); - GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, rb); + GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, ID); if (Multisample != 0) GL.RenderbufferStorageMultisample(RenderbufferTarget.Renderbuffer, Multisample, Storage, (int)f.Size.X, (int)f.Size.Y); else GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, Storage, (int)f.Size.X, (int)f.Size.Y); GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, 0); + } + /// + /// Disposes the renderbuffer. + /// + public void Dispose() + { - return rb; + GL.DeleteRenderbuffer(ID); + ID = -1; + } + + /// + public override bool Equals(object obj) + { + if (obj is RenderbufferAttachment ra) + { + if (ra.FramebufferAttachment == FramebufferAttachment) return true; + + return false; + } + + return false; } } } \ No newline at end of file diff --git a/src/renderer/SM.OGL/GLObject.cs b/src/renderer/SM.OGL/GLObject.cs index 89b0fbe..a0538e6 100644 --- a/src/renderer/SM.OGL/GLObject.cs +++ b/src/renderer/SM.OGL/GLObject.cs @@ -136,7 +136,7 @@ namespace SM.OGL /// public static void DisposeMarkedObjects() { - foreach (GLObject o in _disposableObjects) + foreach (GLObject o in _disposableObjects.ToArray()) { o.Dispose(); } diff --git a/src/renderer/SM.OGL/SM.OGL.csproj b/src/renderer/SM.OGL/SM.OGL.csproj index fcd5e49..432a51b 100644 --- a/src/renderer/SM.OGL/SM.OGL.csproj +++ b/src/renderer/SM.OGL/SM.OGL.csproj @@ -9,9 +9,10 @@ Properties SM.OGL SM.OGL - v4.5.2 + v4.7.1 512 true + true diff --git a/src/renderer/SM.OGL/Shaders/GenericShader.cs b/src/renderer/SM.OGL/Shaders/GenericShader.cs index 27d74e7..fb1df8c 100644 --- a/src/renderer/SM.OGL/Shaders/GenericShader.cs +++ b/src/renderer/SM.OGL/Shaders/GenericShader.cs @@ -19,7 +19,7 @@ namespace SM.OGL.Shaders /// /// Contains the different files for the shader. /// - protected ShaderFileCollection ShaderFileFiles; + public ShaderFileCollection ShaderFiles; /// /// Contains and manage the uniforms from the shader. @@ -67,7 +67,7 @@ namespace SM.OGL.Shaders Console.WriteLine(); - ShaderFileFiles = new ShaderFileCollection(vertex,fragment, geometry); + ShaderFiles = new ShaderFileCollection(vertex,fragment, geometry); } /// @@ -80,7 +80,7 @@ namespace SM.OGL.Shaders /// protected GenericShader(ShaderFileCollection shaderFileFiles) { - ShaderFileFiles = shaderFileFiles; + ShaderFiles = shaderFileFiles; } /// @@ -92,7 +92,7 @@ namespace SM.OGL.Shaders /// public void Update(ShaderFileCollection newShaderFiles) { - ShaderFileFiles = newShaderFiles; + ShaderFiles = newShaderFiles; Recompile(); } @@ -103,9 +103,9 @@ namespace SM.OGL.Shaders { _id = GL.CreateProgram(); - ShaderFileFiles.Append(this); + ShaderFiles.Append(this); GL.LinkProgram(_id); - ShaderFileFiles.Detach(this); + ShaderFiles.Detach(this); Uniforms = new UniformCollection {ParentShader = this}; Uniforms.Import(this); diff --git a/src/renderer/SM.OGL/Shaders/Uniform.cs b/src/renderer/SM.OGL/Shaders/Uniform.cs index 6b498ac..5b5810e 100644 --- a/src/renderer/SM.OGL/Shaders/Uniform.cs +++ b/src/renderer/SM.OGL/Shaders/Uniform.cs @@ -24,6 +24,7 @@ namespace SM.OGL.Shaders /// public UniformCollection Parent { get; } + #region Constructors /// /// This creates a new uniform manager, that has a null parent. /// @@ -63,289 +64,372 @@ namespace SM.OGL.Shaders Parent = parent; } + #endregion + #region Uniform1 - public void SetUniform1(bool value) + /// + /// Set a boolean as value. + /// + /// + public void SetBool(bool value) { GL.Uniform1(Location, value ? 1 : 0); } - public void SetUniform1(int value) + /// + /// Sets a integer. + /// + /// + public void SetInt(int value) { GL.Uniform1(Location, value); } - public void SetUniform1(params int[] values) + /// + /// Sets an array of integers. + /// + /// + public void SetInt(params int[] values) { GL.Uniform1(Location, values.Length, values); } - public void SetUniform1(int count, ref int values) - { - GL.Uniform1(Location, count, ref values); - } - - - public void SetUniform1(uint value) + /// + /// Set a unsigned integer. + /// + /// + public void SetUInt(uint value) { GL.Uniform1(Location, value); } - public void SetUniform1(params uint[] values) + /// + /// Set an array of unsigned integers. + /// + /// + public void SetUInt(params uint[] values) { GL.Uniform1(Location, values.Length, values); } - public void SetUniform1(int count, ref uint values) - { - GL.Uniform1(Location, count, ref values); - } - - - public void SetUniform1(float value) + /// + /// Sets a float. + /// + /// + public void SetFloat(float value) { GL.Uniform1(Location, value); } - public void SetUniform1(params float[] values) + /// + /// Sets an array of floats. + /// + /// + public void SetFloat(params float[] values) { GL.Uniform1(Location, values.Length, values); } - public void SetUniform1(int count, ref float value) - { - GL.Uniform1(Location, count, ref value); - } - - - public void SetUniform1(double value) - { - GL.Uniform1(Location, value); - } - - public void SetUniform1(params double[] values) - { - GL.Uniform1(Location, values.Length, values); - } - - public void SetUniform1(int count, ref double value) - { - GL.Uniform1(Location, count, ref value); - } - #endregion #region Uniform2 - public void SetUniform2(float x, float y) + /// + /// Sets a float vector2 by providing the values. + /// + /// + /// + public void SetVector2(float x, float y) { GL.Uniform2(Location, x, y); } - public void SetUniform2(double x, double y) + /// + /// Sets a unsigned integer vector2 by providing the values. + /// + /// + /// + public void SetVector2(uint x, uint y) { GL.Uniform2(Location, x, y); } - public void SetUniform2(uint x, uint y) + /// + /// Sets a integer vector2 by providing the values. + /// + /// + /// + public void SetVector2(int x, int y) { GL.Uniform2(Location, x, y); } - public void SetUniform2(int x, int y) - { - GL.Uniform2(Location, x, y); - } - - public void SetUniform2(params float[] values) - { - GL.Uniform2(Location, values.Length / 2, values); - } - - public void SetUniform2(params double[] values) - { - GL.Uniform2(Location, values.Length / 2, values); - } - - public void SetUniform2(params int[] values) - { - GL.Uniform2(Location, values.Length / 2, values); - } - - public void SetUniform2(params uint[] values) - { - GL.Uniform2(Location, values.Length / 2, values); - } - - public void SetUniform2(int count, ref float values) - { - GL.Uniform2(Location, count, ref values); - } - - public void SetUniform2(int count, ref double values) - { - GL.Uniform2(Location, count, ref values); - } - - public void SetUniform2(int count, ref uint values) - { - GL.Uniform2(Location, count, ref values); - } - - public void SetUniform2(Vector2 vector2) + /// + /// Sets a float vector2. + /// + /// + public void SetVector2(Vector2 vector2) { GL.Uniform2(Location, vector2); } - public void SetUniform2(ref Vector2 vector2) + /// + /// Sets a float vector2 by refencing. + /// + /// + public void SetVector2(ref Vector2 vector2) { GL.Uniform2(Location, ref vector2); } + /// + /// Sets a array of vector2. + /// + /// + public void SetVector2(params Vector2[] values) + { + float[] newValues = new float[values.Length * 2]; + for(int i = 0; i < values.Length; i++) + { + Vector2 val = values[i]; + int newi = i * 2; + newValues[newi] = val.X; + newValues[newi + 1] = val.Y; + } + GL.Uniform2(Location, values.Length, newValues); + } + + /// + /// Sets a float array that get converted to a vector2 array. + /// + /// + public void SetVector2(params float[] values) + { + GL.Uniform2(Location, values.Length / 2, values); + } + + /// + /// Sets a integer array that get converted to a ivector2 array. + /// + /// + public void SetVector2(params int[] values) + { + GL.Uniform2(Location, values.Length / 2, values); + } + + /// + /// Sets a unsigned integer array that get converted to a unsigned integer vector2 array. + /// + /// + public void SetVector2(params uint[] values) + { + GL.Uniform2(Location, values.Length / 2, values); + } + #endregion #region Uniform3 - public void SetUniform3(float x, float y, float z) + /// + /// Sets a float vector3 by providing the values. + /// + /// + /// + /// + public void SetVector3(float x, float y, float z) { GL.Uniform3(Location, x, y, z); } - public void SetUniform3(double x, double y, double z) + /// + /// Sets a unsigned integer vector3 by providing the values. + /// + /// + /// + /// + public void SetVector3(uint x, uint y, uint z) { GL.Uniform3(Location, x, y, z); } - public void SetUniform3(uint x, uint y, uint z) + /// + /// Sets a integer vector3 by providing the values. + /// + /// + /// + /// + public void SetVector3(int x, int y, int z) { GL.Uniform3(Location, x, y, z); } - public void SetUniform3(int x, int y, int z) - { - GL.Uniform3(Location, x, y, z); - } - - public void SetUniform3(params float[] values) - { - GL.Uniform3(Location, values.Length / 3, values); - } - - public void SetUniform3(params double[] values) - { - GL.Uniform3(Location, values.Length / 3, values); - } - - public void SetUniform3(params int[] values) - { - GL.Uniform3(Location, values.Length / 3, values); - } - - public void SetUniform3(params uint[] values) - { - GL.Uniform3(Location, values.Length / 3, values); - } - - public void SetUniform3(int count, ref float values) - { - GL.Uniform3(Location, count, ref values); - } - - public void SetUniform3(int count, ref double values) - { - GL.Uniform3(Location, count, ref values); - } - - public void SetUniform3(int count, ref uint values) - { - GL.Uniform3(Location, count, ref values); - } - - public void SetUniform3(Vector3 vector) + /// + /// Sets a vector3. + /// + /// + public void SetVector3(Vector3 vector) { GL.Uniform3(Location, vector); } - - public void SetUniform3(ref Vector3 vector) + /// + /// Sets a vector3 by reference. + /// + /// + public void SetVector3(ref Vector3 vector) { GL.Uniform3(Location, ref vector); } + /// + /// Sets a array of vector3. + /// + /// + public void SetVector3(params Vector3[] values) + { + float[] newValues = new float[values.Length * 3]; + for (int i = 0; i < values.Length; i++) + { + Vector3 val = values[i]; + int newi = i * 3; + newValues[newi] = val.X; + newValues[newi + 1] = val.Y; + newValues[newi + 2] = val.Z; + } + GL.Uniform3(Location, values.Length, newValues); + } + + /// + /// Sets a array by providing the components. + /// + /// + public void SetVector3(params float[] values) + { + GL.Uniform3(Location, values.Length / 3, values); + } + /// + /// Sets a array by providing the components. + /// + /// + public void SetVector3(params int[] values) + { + GL.Uniform3(Location, values.Length / 3, values); + } + /// + /// Sets a array by providing the components. + /// + /// + public void SetVector3(params uint[] values) + { + GL.Uniform3(Location, values.Length / 3, values); + } + + #endregion #region Uniform4 - public void SetUniform4(float x, float y, float z, float w) + /// + /// Sets a vector4 by providing the values. + /// + /// + /// + /// + /// + public void SetVector4(float x, float y, float z, float w) + { + GL.Uniform4(Location, x, y, z, w); + } + /// + /// Sets a vector4 by providing the values. + /// + /// + /// + /// + /// + public void SetVector4(uint x, uint y, uint z, uint w) + { + GL.Uniform4(Location, x, y, z, w); + } + /// + /// Sets a vector4 by providing the values. + /// + /// + /// + /// + /// + public void SetVector4(int x, int y, int z, int w) { GL.Uniform4(Location, x, y, z, w); } - public void SetUniform4(double x, double y, double z, double w) - { - GL.Uniform4(Location, x, y, z, w); - } - - public void SetUniform4(uint x, uint y, uint z, uint w) - { - GL.Uniform4(Location, x, y, z, w); - } - - public void SetUniform4(int x, int y, int z, int w) - { - GL.Uniform4(Location, x, y, z, w); - } - - public void SetUniform4(params float[] values) - { - GL.Uniform4(Location, values.Length / 4, values); - } - - public void SetUniform4(params double[] values) - { - GL.Uniform4(Location, values.Length / 4, values); - } - - public void SetUniform4(params int[] values) - { - GL.Uniform4(Location, values.Length / 4, values); - } - - public void SetUniform4(params uint[] values) - { - GL.Uniform4(Location, values.Length / 4, values); - } - - public void SetUniform4(int count, ref float values) - { - GL.Uniform4(Location, count, ref values); - } - - public void SetUniform4(int count, ref double values) - { - GL.Uniform4(Location, count, ref values); - } - - public void SetUniform4(int count, ref uint values) - { - GL.Uniform4(Location, count, ref values); - } - - public void SetUniform4(Vector4 vector) + /// + /// Sets a vector4. + /// + /// + public void SetVector4(Vector4 vector) { GL.Uniform4(Location, vector); } - public void SetUniform4(ref Vector4 vector) + /// + /// Sets a vector4. + /// + /// + public void SetVector4(ref Vector4 vector) { GL.Uniform4(Location, ref vector); } - public void SetUniform4(Color4 color) + /// + /// Sets a array of Vector4. + /// + /// + public void SetVector4(params Vector4[] values) { - GL.Uniform4(Location, color); + float[] newValues = new float[values.Length * 4]; + for (int i = 0; i < values.Length; i++) + { + Vector4 val = values[i]; + int newi = i * 3; + newValues[newi] = val.X; + newValues[newi + 1] = val.Y; + newValues[newi + 2] = val.Z; + newValues[newi + 3] = val.W; + } + GL.Uniform3(Location, values.Length, newValues); } - public void SetUniform4(Quaternion quaternion) + /// + /// Sets a array by providing the components. + /// + /// + public void SetVector4(params float[] values) + { + GL.Uniform4(Location, values.Length / 4, values); + } + /// + /// Sets a array by providing the components. + /// + /// + public void SetVector4(params int[] values) + { + GL.Uniform4(Location, values.Length / 4, values); + } + /// + /// Sets a array by providing the components. + /// + /// + public void SetVector4(params uint[] values) + { + GL.Uniform4(Location, values.Length / 4, values); + } + + /// + /// Sets a quaternion. + /// + /// + public void SetQuaternion(Quaternion quaternion) { GL.Uniform4(Location, quaternion); } @@ -354,26 +438,22 @@ namespace SM.OGL.Shaders #region Matrix2 + /// + /// Sets a matrix2. + /// + /// + /// If true, the matrix will be transposed. public void SetMatrix2(Matrix2 matrix, bool transpose = false) { GL.UniformMatrix2(Location, transpose, ref matrix); } - public void SetMatrix2(int count, ref double value, bool transpose = false) - { - GL.UniformMatrix2(Location, count, transpose, ref value); - } - - public void SetMatrix2(int count, ref float value, bool transpose = false) - { - GL.UniformMatrix2(Location, count, transpose, ref value); - } - - public void SetMatrix2(int count, double[] value, bool transpose = false) - { - GL.UniformMatrix2(Location, count, transpose, value); - } - + /// + /// Sets a matrix2 array. + /// + /// + /// + /// If true, the matrix will be transposed. public void SetMatrix2(int count, float[] value, bool transpose = false) { GL.UniformMatrix2(Location, count, transpose, value); @@ -382,27 +462,22 @@ namespace SM.OGL.Shaders #endregion #region Matrix3 - + /// + /// Sets a matrix3. + /// + /// + /// If true, the matrix will be transposed. public void SetMatrix3(Matrix3 matrix, bool transpose = false) { GL.UniformMatrix3(Location, transpose, ref matrix); } - public void SetMatrix3(int count, ref double value, bool transpose = false) - { - GL.UniformMatrix3(Location, count, transpose, ref value); - } - - public void SetMatrix3(int count, ref float value, bool transpose = false) - { - GL.UniformMatrix3(Location, count, transpose, ref value); - } - - public void SetMatrix3(int count, double[] value, bool transpose = false) - { - GL.UniformMatrix3(Location, count, transpose, value); - } - + /// + /// Sets a matrix3 array. + /// + /// + /// + /// If true, the matrix will be transposed. public void SetMatrix3(int count, float[] value, bool transpose = false) { GL.UniformMatrix3(Location, count, transpose, value); @@ -412,31 +487,31 @@ namespace SM.OGL.Shaders #region Matrix4 + /// + /// Sets a matrix4. + /// + /// + /// If true, the matrix will be transposed. public void SetMatrix4(Matrix4 matrix, bool transpose = false) { GL.UniformMatrix4(Location, transpose, ref matrix); } - + /// + /// Sets a matrix4 by reference. + /// + /// + /// If true, the matrix will be transposed. public void SetMatrix4(ref Matrix4 matrix, bool transpose = false) { GL.UniformMatrix4(Location, transpose, ref matrix); } - public void SetMatrix4(int count, ref double value, bool transpose = false) - { - GL.UniformMatrix4(Location, count, transpose, ref value); - } - - public void SetMatrix4(int count, ref float value, bool transpose = false) - { - GL.UniformMatrix4(Location, count, transpose, ref value); - } - - public void SetMatrix4(int count, double[] value, bool transpose = false) - { - GL.UniformMatrix4(Location, count, transpose, value); - } - + /// + /// Sets a matrix4 array. + /// + /// + /// + /// If true, the matrix will be transposed. public void SetMatrix4(int count, float[] value, bool transpose = false) { GL.UniformMatrix4(Location, count, transpose, value); @@ -444,6 +519,15 @@ namespace SM.OGL.Shaders #endregion + /// + /// Sets the color. + /// + /// + public void SetColor(Color4 color) + { + GL.Uniform4(Location, color); + } + /// /// Try to sets the texture at the next possible position and tells the checkUniform, if worked or not. /// @@ -451,7 +535,7 @@ namespace SM.OGL.Shaders /// The check uniform. public void SetTexture(TextureBase texture, Uniform checkUniform) { - checkUniform.SetUniform1(texture != null); + checkUniform.SetBool(texture != null); if (texture != null) SetTexture(texture); } @@ -463,7 +547,7 @@ namespace SM.OGL.Shaders /// The check uniform. public void SetTexture(TextureBase texture, int pos, Uniform checkUniform) { - checkUniform.SetUniform1(texture != null); + checkUniform.SetBool(texture != null); if (texture != null) SetTexture(texture); } @@ -486,7 +570,7 @@ namespace SM.OGL.Shaders Parent.NextTexture = texturePos + 1; GL.ActiveTexture(TextureUnit.Texture0 + texturePos); GL.BindTexture(texture.Target, texture); - SetUniform1(texturePos); + SetInt(texturePos); } /// diff --git a/src/renderer/SM.OGL/Texture/TextureBase.cs b/src/renderer/SM.OGL/Texture/TextureBase.cs index 495fe74..b496f6d 100644 --- a/src/renderer/SM.OGL/Texture/TextureBase.cs +++ b/src/renderer/SM.OGL/Texture/TextureBase.cs @@ -1,6 +1,8 @@ #region usings +using OpenTK; using OpenTK.Graphics.OpenGL4; +using System; #endregion @@ -10,6 +12,7 @@ namespace SM.OGL.Texture /// Works as a basis for textures. /// public abstract class TextureBase : GLObject + { /// protected override bool AutoCompile { get; set; } = true; @@ -50,11 +53,35 @@ namespace SM.OGL.Texture /// public virtual int Height { get; protected set; } + public Vector2 Size => new Vector2(Width, Height); + public Vector2 TexelSize => new Vector2(1f / Width, 1f / Height); + /// public override void Dispose() { GL.DeleteTexture(_id); base.Dispose(); } + + protected void GenerateBaseTexture(Vector2 size) + { + Width = (int)size.X; + Height = (int)size.Y; + + GL.BindTexture(TextureTarget.Texture2D, _id); + GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInformation.InternalFormat, + Width, Height, 0, + PixelInformation.Format, PixelInformation.DataType, IntPtr.Zero); + + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)Filter); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)Filter); + + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, + (int)WrapMode); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, + (int)WrapMode); + + GL.BindTexture(TextureTarget.Texture2D, 0); + } } } \ No newline at end of file diff --git a/src/renderer/SM.OGL/packages.config b/src/renderer/SM.OGL/packages.config index 82cdaeb..1f65eab 100644 --- a/src/renderer/SM.OGL/packages.config +++ b/src/renderer/SM.OGL/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/src/renderer/SM2D/SM2D.csproj b/src/renderer/SM2D/SM2D.csproj index 67ed6ca..384bc93 100644 --- a/src/renderer/SM2D/SM2D.csproj +++ b/src/renderer/SM2D/SM2D.csproj @@ -8,9 +8,10 @@ Properties SM2D SMRenderer2D - v4.5.2 + v4.7.1 512 true + true @@ -30,9 +31,13 @@ prompt 4 + + false + ..\..\..\packages\OpenTK.3.3.1\lib\net20\OpenTK.dll + True diff --git a/src/renderer/SM2D/Shader/ShaderCollection.cs b/src/renderer/SM2D/Shader/ShaderCollection.cs index e7dacf8..2886b20 100644 --- a/src/renderer/SM2D/Shader/ShaderCollection.cs +++ b/src/renderer/SM2D/Shader/ShaderCollection.cs @@ -18,7 +18,7 @@ namespace SM2D.Shader static void SetUniforms(UniformCollection uniforms, DrawContext context) { - uniforms["Tint"].SetUniform4(context.Material.Tint); + uniforms["Tint"].SetColor(context.Material.Tint); uniforms["Texture"].SetTexture(context.Material.Texture, uniforms["UseTexture"]); } } diff --git a/src/renderer/SM2D/packages.config b/src/renderer/SM2D/packages.config index 82cdaeb..1f65eab 100644 --- a/src/renderer/SM2D/packages.config +++ b/src/renderer/SM2D/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/tests/SM_TEST/App.config b/tests/SM_TEST/App.config index 88fa402..ecdcf8a 100644 --- a/tests/SM_TEST/App.config +++ b/tests/SM_TEST/App.config @@ -1,6 +1,6 @@ - + - + - \ No newline at end of file + diff --git a/tests/SM_TEST/Default Fragment Shader1.frag b/tests/SM_TEST/Default Fragment Shader1.frag new file mode 100644 index 0000000..e97c5eb --- /dev/null +++ b/tests/SM_TEST/Default Fragment Shader1.frag @@ -0,0 +1,10 @@ +#version 330 core + +uniform vec4 Color; +uniform float Scale; + +layout(location = 0) out vec4 color; + +void main() { + color = Color * Scale; +} diff --git a/tests/SM_TEST/Program.cs b/tests/SM_TEST/Program.cs index 70bd0b0..be64d6a 100644 --- a/tests/SM_TEST/Program.cs +++ b/tests/SM_TEST/Program.cs @@ -3,15 +3,20 @@ using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.Linq; +using System.Runtime.InteropServices.WindowsRuntime; using OpenTK; using OpenTK.Graphics; using OpenTK.Graphics.OpenGL; using ShaderToolParser; +using SharpDX.XInput; using SM.Base; using SM.Base.Animation; using SM.Base.Controls; using SM.Base.Drawing; +using SM.Base.Drawing.Text; +using SM.Base.Shaders; using SM.Base.Time; +using SM.Base.Utility; using SM.Base.Window; using SM.Intergrations.ShaderTool; using SM.Utils.Controls; @@ -28,25 +33,25 @@ namespace SM_TEST { static Scene scene; private static GLWindow window; - private static PolyLine line; + private static GameController controller; - private static ItemCollection test; - private static DrawParticles particles; - - private static InterpolationProcess interpolation; + private static GameKeybindActor actor; public static STPProject portal; - static void Main(string[] args) - { + static void Main(string[] args){ Font font = new Font(@".\GapSansBold.ttf") { FontSize = 51, - CharSet = new char[] - { - 'I', 'A','M','T','W','O' - } }; - font.RegenerateTexture(); + + controller = new GameController(0); + GameKeybindHost host = new GameKeybindHost(new GameKeybindList() + { + {"g_test", context => Keyboard.IsAnyKeyPressed, context => context.ControllerState.Buttons[GamepadButtonFlags.A, true]} + }); + actor = GameKeybindActor.CreateControllerActor(controller); + actor.ConnectHost(host); + portal = STPProject.CreateFromZIP("portal.zip"); @@ -58,18 +63,45 @@ namespace SM_TEST { ShowAxisHelper = true }); - scene.Background.Color = Color4.Red; + //scene.Background.Color = Color4.Red; scene.Camera = new Camera() { }; - DrawText obj = new DrawText(font, "I AM\n\tTWO") - {}; + SimpleShader shader = new SimpleShader("basic", AssemblyUtility.ReadAssemblyFile("SM_TEST.Default Fragment Shader1.frag"), (a, b) => { + a["Color"].SetColor(b.Material.Tint); + a["Scale"].SetFloat(b.Material.ShaderArguments.Get("Scale", 1f)); + + }); + DrawObject2D obj = new DrawObject2D() + { + Material = + { + CustomShader = shader, + Tint = new Color4(1f, 0.151217f, 0.050313f, 1), + ShaderArguments = + { + ["Scale"] = 50f + } + } + };/* + DrawObject2D obj2 = new DrawObject2D() + { + Material = + { + Tint = Color4.Aqua, + CustomShader = shader, + ShaderArguments = + { + ["Scale"] = 1000f + } + } + }; + obj2.Transform.Position.Set(300);*/ scene.Objects.Add(obj); - window.UpdateFrame += WindowOnUpdateFrame; window.RenderFrame += Window_RenderFrame; window.Run(); @@ -80,11 +112,5 @@ namespace SM_TEST { window.Title = Math.Floor(e.Time * 1000) + "ms"; } - - private static void WindowOnUpdateFrame(object sender, FrameEventArgs e) - { - bool interactions = new GameController(0).GetState().AnyInteraction; - Console.WriteLine(); - } } } \ No newline at end of file diff --git a/tests/SM_TEST/SM_TEST.csproj b/tests/SM_TEST/SM_TEST.csproj index a520d91..479cccf 100644 --- a/tests/SM_TEST/SM_TEST.csproj +++ b/tests/SM_TEST/SM_TEST.csproj @@ -10,12 +10,13 @@ WinExe SM_TEST SM_TEST - v4.5.2 + v4.7.2 512 true true + AnyCPU @@ -66,6 +67,7 @@ + diff --git a/tests/SM_TEST/TestRenderPipeline.cs b/tests/SM_TEST/TestRenderPipeline.cs index 5eecd9c..fea1bc0 100644 --- a/tests/SM_TEST/TestRenderPipeline.cs +++ b/tests/SM_TEST/TestRenderPipeline.cs @@ -1,4 +1,5 @@ using OpenTK.Graphics.OpenGL4; +using SM.Base.Legacy.PostProcessing; using SM.Base.PostEffects; using SM.Base.Window; using SM.Intergrations.ShaderTool; @@ -9,6 +10,7 @@ namespace SM_TEST { public class TestRenderPipeline : RenderPipeline { + private BloomEffectOld _bloomObsolete; private BloomEffect _bloom; private STPostProcessEffect _vittage; @@ -17,16 +19,15 @@ namespace SM_TEST public override void Initialization() { - MainFramebuffer = CreateWindowFramebuffer(16, PixelInformation.RGBA_HDR); + MainFramebuffer = CreateWindowFramebuffer(0, PixelInformation.RGBA_HDR, true); - _postBuffer = CreateWindowFramebuffer(0, PixelInformation.RGBA_HDR, depth: true); - Framebuffers.Add(_postBuffer); - _bloom = new BloomEffect(_postBuffer, hdr: true, .75f) + _bloom = new BloomEffect(true) { + Radius = 20, }; - _bloom.Initilize(this); + PostProcessEffects.Add(_bloom); - _vittage = new STPostProcessEffect(Program.portal.DrawNodes.Find(a => a.Variables.ContainsKey("_ViewportSize"))) + /*_vittage = new STPostProcessEffect(Program.portal.DrawNodes.Find(a => a.Variables.ContainsKey("_ViewportSize"))) { Arguments = { @@ -36,7 +37,8 @@ namespace SM_TEST {"Move", 3.33f} } }; - _vittage.Initilize(this); + _vittage.Initilize(this);*/ + InitizePostProcessing(); base.Initialization(); } @@ -50,16 +52,17 @@ namespace SM_TEST context.Scene.DrawHUD(context); GL.Disable(EnableCap.DepthTest); - _postBuffer.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); - PostProcessUtility.ResolveMultisampledBuffers(MainFramebuffer, _postBuffer); + //_postBuffer.Activate(ClearBufferMask.ColorBufferBit); + //PostProcessUtility.ResolveMultisampledBuffers(MainFramebuffer, _postBuffer); - _vittage.Draw(_postBuffer["color"], context); - _bloom.Draw(_postBuffer["color"], context); + //_vittage.Draw(MainFramebuffer["color"], context); + //_bloom.Draw(MainFramebuffer["color"], context); + _bloomObsolete.Draw(MainFramebuffer["color"], context); Framebuffer.Screen.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); - PostProcessUtility.FinalizeHDR(_postBuffer["color"], .1f); + PostProcessUtility.FinalizeHDR(MainFramebuffer["color"], 1f); - context.Scene.DrawDebug(context); + //context.Scene.DrawDebug(context); } } } \ No newline at end of file From 2c0517ca48f41e06c16b614f497bb6f41d11c67d Mon Sep 17 00:00:00 2001 From: Nineto Nine Date: Sun, 26 Sep 2021 21:33:58 +0200 Subject: [PATCH 06/10] More Summaries --- .../SM.OGL/Framebuffer/ColorAttachment.cs | 6 ++++++ src/renderer/SM.OGL/Framebuffer/Framebuffer.cs | 15 +++++++++++++++ .../SM.OGL/Framebuffer/RenderbufferAttachment.cs | 11 +++++++++++ src/renderer/SM.OGL/Texture/TextureBase.cs | 11 +++++++++++ 4 files changed, 43 insertions(+) diff --git a/src/renderer/SM.OGL/Framebuffer/ColorAttachment.cs b/src/renderer/SM.OGL/Framebuffer/ColorAttachment.cs index d95c6e1..7ef84e4 100644 --- a/src/renderer/SM.OGL/Framebuffer/ColorAttachment.cs +++ b/src/renderer/SM.OGL/Framebuffer/ColorAttachment.cs @@ -28,6 +28,10 @@ namespace SM.OGL.Framebuffer /// 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; /// @@ -56,6 +60,7 @@ namespace SM.OGL.Framebuffer /// Creates a attachment with a specific id. /// /// + /// public ColorAttachment(int attachmentId, Vector2? size = null) : this(attachmentId, PixelInformation.RGBA_LDR, size) { } @@ -64,6 +69,7 @@ namespace SM.OGL.Framebuffer /// /// /// + /// /// public ColorAttachment(int attachmentID, PixelInformation pixelInformation, Vector2? size = null, int multisamples = 0) { diff --git a/src/renderer/SM.OGL/Framebuffer/Framebuffer.cs b/src/renderer/SM.OGL/Framebuffer/Framebuffer.cs index da98b79..6a817de 100644 --- a/src/renderer/SM.OGL/Framebuffer/Framebuffer.cs +++ b/src/renderer/SM.OGL/Framebuffer/Framebuffer.cs @@ -50,8 +50,14 @@ 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; } /// @@ -171,6 +177,12 @@ namespace SM.OGL.Framebuffer /// Appends a color attachment. /// 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. @@ -203,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); @@ -212,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); @@ -222,6 +236,7 @@ namespace SM.OGL.Framebuffer /// /// /// + /// public void Activate(FramebufferTarget target, ClearBufferMask clear, bool? applyViewport = null) { switch (target) diff --git a/src/renderer/SM.OGL/Framebuffer/RenderbufferAttachment.cs b/src/renderer/SM.OGL/Framebuffer/RenderbufferAttachment.cs index aa35c13..de00fb9 100644 --- a/src/renderer/SM.OGL/Framebuffer/RenderbufferAttachment.cs +++ b/src/renderer/SM.OGL/Framebuffer/RenderbufferAttachment.cs @@ -81,5 +81,16 @@ namespace SM.OGL.Framebuffer 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/src/renderer/SM.OGL/Texture/TextureBase.cs b/src/renderer/SM.OGL/Texture/TextureBase.cs index b496f6d..524c528 100644 --- a/src/renderer/SM.OGL/Texture/TextureBase.cs +++ b/src/renderer/SM.OGL/Texture/TextureBase.cs @@ -53,7 +53,14 @@ 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); /// @@ -63,6 +70,10 @@ namespace SM.OGL.Texture base.Dispose(); } + /// + /// Generates a basic texture, that applies all settings from the -class. + /// + /// protected void GenerateBaseTexture(Vector2 size) { Width = (int)size.X; From 17cbebcf6af7d3297408622eaa3da5b7a7c75d68 Mon Sep 17 00:00:00 2001 From: Nineto Nine Date: Mon, 27 Sep 2021 17:17:38 +0200 Subject: [PATCH 07/10] 27 Sep 2021 + Added Amount Map to the new Bloom system. ~ Moved all projects to .NetFramework 4.5.2 ~ Made sure, you can't get a higher multisampling as 8. --- .../SMRenderer.Intergrations.csproj | 2 +- .../SM.Utils/SMRenderer.Utils.csproj | 2 +- .../Legacy/PostProcessing/bloom_merge.vert | 2 +- .../SM.Base/PostEffects/BloomEffect.cs | 26 +++++++++ .../SM.Base/PostEffects/PostProcessUtility.cs | 2 +- .../PostEffects/Shaders/bloom/combine.frag | 9 ++++ .../PostEffects/Shaders/bloom/combine.vert | 17 ++++++ src/renderer/SM.Base/SM.Base.csproj | 4 +- src/renderer/SM.Base/Types/MinMax.cs | 53 +++++++++++++++++++ .../SM.OGL/Framebuffer/ColorAttachment.cs | 1 + src/renderer/SM.OGL/SM.OGL.csproj | 2 +- src/renderer/SM2D/SM2D.csproj | 2 +- tests/SM_TEST/App.config | 2 +- tests/SM_TEST/SM_TEST.csproj | 2 +- tests/SM_TEST/TestRenderPipeline.cs | 20 +++---- 15 files changed, 125 insertions(+), 21 deletions(-) create mode 100644 src/renderer/SM.Base/PostEffects/Shaders/bloom/combine.vert create mode 100644 src/renderer/SM.Base/Types/MinMax.cs diff --git a/src/optionals/SM.Intergrations/SMRenderer.Intergrations.csproj b/src/optionals/SM.Intergrations/SMRenderer.Intergrations.csproj index 580452a..aeea189 100644 --- a/src/optionals/SM.Intergrations/SMRenderer.Intergrations.csproj +++ b/src/optionals/SM.Intergrations/SMRenderer.Intergrations.csproj @@ -9,7 +9,7 @@ Properties SM.Intergrations SM.Intergrations - v4.7.2 + v4.5.2 512 true diff --git a/src/optionals/SM.Utils/SMRenderer.Utils.csproj b/src/optionals/SM.Utils/SMRenderer.Utils.csproj index 30b4822..3e2f80f 100644 --- a/src/optionals/SM.Utils/SMRenderer.Utils.csproj +++ b/src/optionals/SM.Utils/SMRenderer.Utils.csproj @@ -9,7 +9,7 @@ Properties SM.Utils SM.Utils - v4.7.2 + v4.5.2 512 true diff --git a/src/renderer/SM.Base/Legacy/PostProcessing/bloom_merge.vert b/src/renderer/SM.Base/Legacy/PostProcessing/bloom_merge.vert index 5875eb3..4d20506 100644 --- a/src/renderer/SM.Base/Legacy/PostProcessing/bloom_merge.vert +++ b/src/renderer/SM.Base/Legacy/PostProcessing/bloom_merge.vert @@ -12,7 +12,7 @@ out vec2 TransformedTexture; void main() { vTexture = aTex; - //TransformedTexture = vec2(TextureTransform * vec3(aTex, 1)); + TransformedTexture = vec2(TextureTransform * vec3(aTex, 1)); gl_Position = MVP * vec4(aPos, 1); } \ No newline at end of file diff --git a/src/renderer/SM.Base/PostEffects/BloomEffect.cs b/src/renderer/SM.Base/PostEffects/BloomEffect.cs index 8c5cac7..347a082 100644 --- a/src/renderer/SM.Base/PostEffects/BloomEffect.cs +++ b/src/renderer/SM.Base/PostEffects/BloomEffect.cs @@ -1,7 +1,9 @@ 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; @@ -33,6 +35,7 @@ namespace SM.Base.PostEffects 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") ); @@ -76,6 +79,21 @@ namespace SM.Base.PostEffects /// 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. /// @@ -193,6 +211,14 @@ namespace SM.Base.PostEffects 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/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs b/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs index c925965..1665148 100644 --- a/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs +++ b/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs @@ -38,7 +38,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(); } diff --git a/src/renderer/SM.Base/PostEffects/Shaders/bloom/combine.frag b/src/renderer/SM.Base/PostEffects/Shaders/bloom/combine.frag index e72ba87..2c67f8b 100644 --- a/src/renderer/SM.Base/PostEffects/Shaders/bloom/combine.frag +++ b/src/renderer/SM.Base/PostEffects/Shaders/bloom/combine.frag @@ -1,11 +1,16 @@ #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)); } @@ -23,6 +28,10 @@ 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; 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/SM.Base.csproj b/src/renderer/SM.Base/SM.Base.csproj index dd59076..e40c61b 100644 --- a/src/renderer/SM.Base/SM.Base.csproj +++ b/src/renderer/SM.Base/SM.Base.csproj @@ -13,7 +13,7 @@ Properties SM.Base SM.Base - v4.7.1 + v4.5.2 512 true @@ -62,6 +62,7 @@ + @@ -168,6 +169,7 @@ + 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/src/renderer/SM.OGL/Framebuffer/ColorAttachment.cs b/src/renderer/SM.OGL/Framebuffer/ColorAttachment.cs index 7ef84e4..0592e2e 100644 --- a/src/renderer/SM.OGL/Framebuffer/ColorAttachment.cs +++ b/src/renderer/SM.OGL/Framebuffer/ColorAttachment.cs @@ -77,6 +77,7 @@ namespace SM.OGL.Framebuffer PixelInformation = pixelInformation; AttachmentSize = size; + if (multisamples > 8) multisamples = 8; _multisamples = multisamples; Target = IsMultisampled ? TextureTarget.Texture2DMultisample : TextureTarget.Texture2D; diff --git a/src/renderer/SM.OGL/SM.OGL.csproj b/src/renderer/SM.OGL/SM.OGL.csproj index 432a51b..fd8ec5d 100644 --- a/src/renderer/SM.OGL/SM.OGL.csproj +++ b/src/renderer/SM.OGL/SM.OGL.csproj @@ -9,7 +9,7 @@ Properties SM.OGL SM.OGL - v4.7.1 + v4.5.2 512 true diff --git a/src/renderer/SM2D/SM2D.csproj b/src/renderer/SM2D/SM2D.csproj index 384bc93..247194f 100644 --- a/src/renderer/SM2D/SM2D.csproj +++ b/src/renderer/SM2D/SM2D.csproj @@ -8,7 +8,7 @@ Properties SM2D SMRenderer2D - v4.7.1 + v4.5.2 512 true diff --git a/tests/SM_TEST/App.config b/tests/SM_TEST/App.config index ecdcf8a..8227adb 100644 --- a/tests/SM_TEST/App.config +++ b/tests/SM_TEST/App.config @@ -1,6 +1,6 @@ - + diff --git a/tests/SM_TEST/SM_TEST.csproj b/tests/SM_TEST/SM_TEST.csproj index 479cccf..3050d81 100644 --- a/tests/SM_TEST/SM_TEST.csproj +++ b/tests/SM_TEST/SM_TEST.csproj @@ -10,7 +10,7 @@ WinExe SM_TEST SM_TEST - v4.7.2 + v4.5.2 512 true true diff --git a/tests/SM_TEST/TestRenderPipeline.cs b/tests/SM_TEST/TestRenderPipeline.cs index fea1bc0..04ba92f 100644 --- a/tests/SM_TEST/TestRenderPipeline.cs +++ b/tests/SM_TEST/TestRenderPipeline.cs @@ -1,6 +1,7 @@ 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; @@ -10,20 +11,19 @@ namespace SM_TEST { public class TestRenderPipeline : RenderPipeline { - private BloomEffectOld _bloomObsolete; private BloomEffect _bloom; - private STPostProcessEffect _vittage; private Framebuffer _postBuffer; public override void Initialization() { - - MainFramebuffer = CreateWindowFramebuffer(0, PixelInformation.RGBA_HDR, true); + MainFramebuffer = CreateWindowFramebuffer(8, PixelInformation.RGBA_HDR, true); + _postBuffer = CreateWindowFramebuffer(0, PixelInformation.RGB_HDR, false); _bloom = new BloomEffect(true) { Radius = 20, + AmountMap = new Texture(new System.Drawing.Bitmap("bloom_amountMap.png")) }; PostProcessEffects.Add(_bloom); @@ -52,17 +52,13 @@ namespace SM_TEST context.Scene.DrawHUD(context); GL.Disable(EnableCap.DepthTest); - //_postBuffer.Activate(ClearBufferMask.ColorBufferBit); - //PostProcessUtility.ResolveMultisampledBuffers(MainFramebuffer, _postBuffer); + _postBuffer.Activate(ClearBufferMask.ColorBufferBit); + PostProcessUtility.ResolveMultisampledBuffers(MainFramebuffer, _postBuffer); - //_vittage.Draw(MainFramebuffer["color"], context); - //_bloom.Draw(MainFramebuffer["color"], context); - _bloomObsolete.Draw(MainFramebuffer["color"], context); + _bloom.Draw(_postBuffer["color"], context); Framebuffer.Screen.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); - PostProcessUtility.FinalizeHDR(MainFramebuffer["color"], 1f); - - //context.Scene.DrawDebug(context); + PostProcessUtility.FinalizeHDR(_postBuffer["color"], 1f); } } } \ No newline at end of file From 443877019b700a070a39dd0f3189d78df33b7b01 Mon Sep 17 00:00:00 2001 From: Nineto Nine Date: Mon, 27 Sep 2021 17:48:17 +0200 Subject: [PATCH 08/10] Allowed PostProcessUtility.FinalizeHDR to select a color curve. --- .../SM.Base/PostEffects/PostProcessUtility.cs | 23 +++++++++++++++---- .../PostEffects/Shaders/finalize_hdr.glsl | 8 ++++++- .../SM.Base/PostProcess/PostProcessShader.cs | 18 +++++++++++---- tests/SM_TEST/TestRenderPipeline.cs | 2 +- 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs b/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs index 1665148..67431d9 100644 --- a/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs +++ b/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs @@ -4,18 +4,33 @@ 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")); + 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) { StringOverrides = { { "TYPE", "0" } } }) }, + { HDRColorCurve.Reinhard, new PostProcessShader(new ShaderFile(_finalizeHdrCode) { StringOverrides = { { "TYPE", "1" } } }) }, + { HDRColorCurve.ACES, new PostProcessShader(new ShaderFile(_finalizeHdrCode) { StringOverrides = { { "TYPE", "2" } } }) }, + }; private static readonly PostProcessShader _gammaShader = new PostProcessShader( @@ -48,9 +63,9 @@ 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"].SetFloat(Gamma); u["Exposure"].SetFloat(exposure); diff --git a/src/renderer/SM.Base/PostEffects/Shaders/finalize_hdr.glsl b/src/renderer/SM.Base/PostEffects/Shaders/finalize_hdr.glsl index 696e186..bf754bb 100644 --- a/src/renderer/SM.Base/PostEffects/Shaders/finalize_hdr.glsl +++ b/src/renderer/SM.Base/PostEffects/Shaders/finalize_hdr.glsl @@ -1,4 +1,5 @@ #version 330 +#define TYPE //!TYPE in vec2 vTexture; @@ -29,7 +30,12 @@ vec3 exposure(vec3 scene) { void main() { vec3 scene = texture2D(Scene, vTexture).rgb; - vec3 result = reinhardTone(scene); + vec3 result = exposure(scene); + #if (TYPE == 1) + result = reinhardTone(result); + #elif (TYPE == 2) + 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/PostProcess/PostProcessShader.cs b/src/renderer/SM.Base/PostProcess/PostProcessShader.cs index e2477b8..1ef0498 100644 --- a/src/renderer/SM.Base/PostProcess/PostProcessShader.cs +++ b/src/renderer/SM.Base/PostProcess/PostProcessShader.cs @@ -43,8 +43,13 @@ namespace SM.Base.PostProcess /// /// Creates the shader with the default vertex shader and custom fragment. /// - public PostProcessShader(string fragment) : this(_normalVertex, - new ShaderFile(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) { } @@ -60,7 +65,7 @@ namespace SM.Base.PostProcess { } /// - /// Creates the shader with an vertex extension and custom fragment. + /// Creates the shader with an vertex shader and custom fragment. /// /// /// @@ -68,7 +73,12 @@ namespace SM.Base.PostProcess { } - private PostProcessShader(ShaderFile vertex, ShaderFile fragment) : base( + /// + /// 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); diff --git a/tests/SM_TEST/TestRenderPipeline.cs b/tests/SM_TEST/TestRenderPipeline.cs index 04ba92f..1c8368a 100644 --- a/tests/SM_TEST/TestRenderPipeline.cs +++ b/tests/SM_TEST/TestRenderPipeline.cs @@ -58,7 +58,7 @@ namespace SM_TEST _bloom.Draw(_postBuffer["color"], context); Framebuffer.Screen.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); - PostProcessUtility.FinalizeHDR(_postBuffer["color"], 1f); + PostProcessUtility.FinalizeHDR(_postBuffer["color"], HDRColorCurve.OnlyExposure, .1f); } } } \ No newline at end of file From 8a841825632e95cb959db8a9c2d7dc6026a546c9 Mon Sep 17 00:00:00 2001 From: Nineto Nine Date: Fri, 1 Oct 2021 19:43:00 +0200 Subject: [PATCH 09/10] 1 Oct 2021 ~ Made Shaders now able to use Defines. ~ Moved complete Bloom-shader code in a single file (not working at the moment) --- .../SM.Base/PostEffects/BloomEffect.cs | 58 +++++- .../SM.Base/PostEffects/PostProcessUtility.cs | 7 +- .../SM.Base/PostEffects/Shaders/bloom.frag | 188 ++++++++++++++++++ .../PostEffects/Shaders/bloom/downsample.frag | 1 - .../PostEffects/Shaders/bloom/sampling.frag | 2 +- .../PostEffects/Shaders/finalize_hdr.glsl | 23 +-- .../PostEffects/Shaders/hdr_curves.frag | 21 ++ .../SM.Base/PostProcess/PostProcessShader.cs | 2 + src/renderer/SM.Base/SM.Base.csproj | 2 + .../SM.Base/Shaders/MaterialShader.cs | 1 + src/renderer/SM.OGL/Shaders/GenericShader.cs | 11 +- src/renderer/SM.OGL/Shaders/ShaderFile.cs | 37 +++- .../SM.OGL/Shaders/ShaderFileCollection.cs | 12 +- tests/SM_TEST/Program.cs | 2 +- tests/SM_TEST/TestRenderPipeline.cs | 2 +- 15 files changed, 325 insertions(+), 44 deletions(-) create mode 100644 src/renderer/SM.Base/PostEffects/Shaders/bloom.frag create mode 100644 src/renderer/SM.Base/PostEffects/Shaders/hdr_curves.frag diff --git a/src/renderer/SM.Base/PostEffects/BloomEffect.cs b/src/renderer/SM.Base/PostEffects/BloomEffect.cs index 347a082..32b0e30 100644 --- a/src/renderer/SM.Base/PostEffects/BloomEffect.cs +++ b/src/renderer/SM.Base/PostEffects/BloomEffect.cs @@ -17,6 +17,14 @@ 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. @@ -38,13 +46,47 @@ namespace SM.Base.PostEffects 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; @@ -52,6 +94,7 @@ namespace SM.Base.PostEffects private List _downsampler; private List _upsample; + private PostProcessShader[] shaders; private int _iterations; private float _sampleSize; @@ -98,9 +141,12 @@ namespace SM.Base.PostEffects /// This creates a more prettier bloom effect. /// /// This allows to enable hdr returns. - public BloomEffect(bool hdr = false) + /// 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(); @@ -168,7 +214,7 @@ namespace SM.Base.PostEffects // Filtering _downsampler[0].Activate(true); - _filterShader.Draw(source, col => + shaders[0].Draw(source, col => { col["ThresholdCurve"].SetVector4(_thresholdCurve); }); @@ -180,7 +226,7 @@ namespace SM.Base.PostEffects ColorAttachment downsampleSource = last; Framebuffer downsampleTarget = _downsampler[i]; downsampleTarget.Activate(true); - _downsampleShader.Draw(downsampleSource); + shaders[1].Draw(downsampleSource); last = downsampleTarget["0"]; } @@ -193,7 +239,7 @@ namespace SM.Base.PostEffects upsampleTarget.Activate(true); - _upsampleShader.Draw(last, (a) => + shaders[2].Draw(last, (a) => { if (last != null) a["baseBuffer"].SetTexture(downsampleSource); a["sampleSize"].SetFloat(_sampleSize); @@ -204,7 +250,7 @@ namespace SM.Base.PostEffects // combine target.Activate(true); - _combineShader.Draw(last, (a) => + shaders[3].Draw(last, (a) => { a["sampleSize"].SetFloat(_sampleSize); diff --git a/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs b/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs index 67431d9..0d77ac4 100644 --- a/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs +++ b/src/renderer/SM.Base/PostEffects/PostProcessUtility.cs @@ -23,13 +23,14 @@ namespace SM.Base.PostEffects /// public static class PostProcessUtility { + 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) { StringOverrides = { { "TYPE", "0" } } }) }, - { HDRColorCurve.Reinhard, new PostProcessShader(new ShaderFile(_finalizeHdrCode) { StringOverrides = { { "TYPE", "1" } } }) }, - { HDRColorCurve.ACES, new PostProcessShader(new ShaderFile(_finalizeHdrCode) { StringOverrides = { { "TYPE", "2" } } }) }, + { 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 = 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/downsample.frag b/src/renderer/SM.Base/PostEffects/Shaders/bloom/downsample.frag index b2fec34..c0c5178 100644 --- a/src/renderer/SM.Base/PostEffects/Shaders/bloom/downsample.frag +++ b/src/renderer/SM.Base/PostEffects/Shaders/bloom/downsample.frag @@ -2,7 +2,6 @@ uniform vec2 renderedTextureTexelSize; -vec4 GetRenderColor(); vec4 GetRenderColorOffset(vec2); float getBrightness(vec3 col) { diff --git a/src/renderer/SM.Base/PostEffects/Shaders/bloom/sampling.frag b/src/renderer/SM.Base/PostEffects/Shaders/bloom/sampling.frag index 46054ee..9f08e3d 100644 --- a/src/renderer/SM.Base/PostEffects/Shaders/bloom/sampling.frag +++ b/src/renderer/SM.Base/PostEffects/Shaders/bloom/sampling.frag @@ -8,7 +8,7 @@ vec4 GetRenderColorOffset(vec2); vec3 upsample_filter_high() { - vec4 d = renderedTextureTexelSize.xyxy * vec4(1, 1,-1,0); + vec4 d = renderedTextureTexelSize.xyxy * vec4(1, 1,-1,0) * sampleSize; vec3 s; // Line + 1 diff --git a/src/renderer/SM.Base/PostEffects/Shaders/finalize_hdr.glsl b/src/renderer/SM.Base/PostEffects/Shaders/finalize_hdr.glsl index bf754bb..eeacf82 100644 --- a/src/renderer/SM.Base/PostEffects/Shaders/finalize_hdr.glsl +++ b/src/renderer/SM.Base/PostEffects/Shaders/finalize_hdr.glsl @@ -1,5 +1,4 @@ #version 330 -#define TYPE //!TYPE in vec2 vTexture; @@ -9,31 +8,19 @@ uniform float Gamma; layout(location = 0) out vec4 color; -vec3 ACES(vec3 x) { - const float a = 2.51; - const float b = 0.03; - const float c = 2.43; - const float d = 0.59; - const float e = 0.14; +vec3 ACES(vec3); - return clamp((x * (a * x + b)) / (x * (c * x + d) + e), 0,1.0); -} +vec3 reinhardTone(vec3); -vec3 reinhardTone(vec3 col) { - return col / (col + vec3(1.0)); -} - -vec3 exposure(vec3 scene) { - return vec3(1) - exp(-texture(Scene, vTexture).rgb * Exposure); -} +vec3 exposure(vec3); void main() { vec3 scene = texture2D(Scene, vTexture).rgb; vec3 result = exposure(scene); - #if (TYPE == 1) + #if defined(TYPE_REINHARD) result = reinhardTone(result); - #elif (TYPE == 2) + #elif defined(TYPE_ACES) result = ACES(result); #endif 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/src/renderer/SM.Base/PostProcess/PostProcessShader.cs b/src/renderer/SM.Base/PostProcess/PostProcessShader.cs index 1ef0498..b1a4744 100644 --- a/src/renderer/SM.Base/PostProcess/PostProcessShader.cs +++ b/src/renderer/SM.Base/PostProcess/PostProcessShader.cs @@ -113,6 +113,8 @@ namespace SM.Base.PostProcess /// public void Draw(Action setUniformAction) { + if (ErrorInShader) return; + Activate(); Plate.Object.Activate(); diff --git a/src/renderer/SM.Base/SM.Base.csproj b/src/renderer/SM.Base/SM.Base.csproj index e40c61b..2f713e0 100644 --- a/src/renderer/SM.Base/SM.Base.csproj +++ b/src/renderer/SM.Base/SM.Base.csproj @@ -170,6 +170,8 @@ + + diff --git a/src/renderer/SM.Base/Shaders/MaterialShader.cs b/src/renderer/SM.Base/Shaders/MaterialShader.cs index 6aa9a48..10c3387 100644 --- a/src/renderer/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(); diff --git a/src/renderer/SM.OGL/Shaders/GenericShader.cs b/src/renderer/SM.OGL/Shaders/GenericShader.cs index fb1df8c..c6617a6 100644 --- a/src/renderer/SM.OGL/Shaders/GenericShader.cs +++ b/src/renderer/SM.OGL/Shaders/GenericShader.cs @@ -16,6 +16,8 @@ namespace SM.OGL.Shaders /// protected override bool AutoCompile { get; set; } = true; + public bool ErrorInShader { get; private set; } + /// /// Contains the different files for the shader. /// @@ -102,12 +104,17 @@ namespace SM.OGL.Shaders public void Load() { _id = GL.CreateProgram(); + Uniforms = new UniformCollection { ParentShader = this }; - ShaderFiles.Append(this); + ErrorInShader = !ShaderFiles.Append(this); + if (ErrorInShader) + { + GL.DeleteProgram(_id); + return; + } GL.LinkProgram(_id); 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/src/renderer/SM.OGL/Shaders/ShaderFile.cs b/src/renderer/SM.OGL/Shaders/ShaderFile.cs index 5cb23f8..4e395b5 100644 --- a/src/renderer/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/src/renderer/SM.OGL/Shaders/ShaderFileCollection.cs b/src/renderer/SM.OGL/Shaders/ShaderFileCollection.cs index 0b6f2a7..33b92ed 100644 --- a/src/renderer/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/tests/SM_TEST/Program.cs b/tests/SM_TEST/Program.cs index be64d6a..d122521 100644 --- a/tests/SM_TEST/Program.cs +++ b/tests/SM_TEST/Program.cs @@ -110,7 +110,7 @@ namespace SM_TEST private static void Window_RenderFrame(object sender, FrameEventArgs e) { - window.Title = Math.Floor(e.Time * 1000) + "ms"; + window.Title = Math.Round(e.Time * 1000,2) + "ms"; } } } \ No newline at end of file diff --git a/tests/SM_TEST/TestRenderPipeline.cs b/tests/SM_TEST/TestRenderPipeline.cs index 1c8368a..978c66a 100644 --- a/tests/SM_TEST/TestRenderPipeline.cs +++ b/tests/SM_TEST/TestRenderPipeline.cs @@ -20,7 +20,7 @@ namespace SM_TEST MainFramebuffer = CreateWindowFramebuffer(8, PixelInformation.RGBA_HDR, true); _postBuffer = CreateWindowFramebuffer(0, PixelInformation.RGB_HDR, false); - _bloom = new BloomEffect(true) + _bloom = new BloomEffect(true, true) { Radius = 20, AmountMap = new Texture(new System.Drawing.Bitmap("bloom_amountMap.png")) From 687125cc3e9b844e91552ec919bd9425966089d9 Mon Sep 17 00:00:00 2001 From: Nineto Nine Date: Fri, 8 Oct 2021 22:09:47 +0200 Subject: [PATCH 10/10] 08 Oct 2021 ~ Fixed Issue with SM.Intergrations.STPostProcessEffect where it would create wierd artifacts when rendered. ~ Moved the initialization process to the RenderPipeline.InitializationProcess-method. ~ PixelInformation.RGB_HDR now use PixelInternalFormat.R11fG11fB10f --- .../ShaderTool/STPostProcessEffect.cs | 17 +++++++++++++ .../SM.Base/PostEffects/BloomEffect.cs | 2 -- src/renderer/SM.Base/Window/RenderPipeline.cs | 25 +++++++++++++++---- .../SM.OGL/Texture/PixelInformation.cs | 2 +- tests/SM_TEST/Program.cs | 2 +- tests/SM_TEST/TestRenderPipeline.cs | 12 ++++----- 6 files changed, 45 insertions(+), 15 deletions(-) diff --git a/src/optionals/SM.Intergrations/ShaderTool/STPostProcessEffect.cs b/src/optionals/SM.Intergrations/ShaderTool/STPostProcessEffect.cs index 461b046..6b70f88 100644 --- a/src/optionals/SM.Intergrations/ShaderTool/STPostProcessEffect.cs +++ b/src/optionals/SM.Intergrations/ShaderTool/STPostProcessEffect.cs @@ -16,6 +16,7 @@ namespace SM.Intergrations.ShaderTool public class STPostProcessEffect : PostProcessEffect { private STPostProcessShader _shader; + private Framebuffer tempFramebuffer; public ShaderArguments Arguments; @@ -39,13 +40,29 @@ namespace SM.Intergrations.ShaderTool } } + 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/renderer/SM.Base/PostEffects/BloomEffect.cs b/src/renderer/SM.Base/PostEffects/BloomEffect.cs index 32b0e30..0a75569 100644 --- a/src/renderer/SM.Base/PostEffects/BloomEffect.cs +++ b/src/renderer/SM.Base/PostEffects/BloomEffect.cs @@ -188,8 +188,6 @@ namespace SM.Base.PostEffects { texSize /= 2; - - f = new Framebuffer(texSize); f.Append("0", new ColorAttachment(0, pixel)); _downsampler.Add(f); diff --git a/src/renderer/SM.Base/Window/RenderPipeline.cs b/src/renderer/SM.Base/Window/RenderPipeline.cs index 906a288..19afdb0 100644 --- a/src/renderer/SM.Base/Window/RenderPipeline.cs +++ b/src/renderer/SM.Base/Window/RenderPipeline.cs @@ -54,16 +54,25 @@ namespace SM.Base.Window /// public virtual void Activate() { } - /// - public virtual void Initialization() + public void Initialization() { - if (MainFramebuffer != null) { + InitializationProcess(); + + 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); @@ -132,9 +141,15 @@ 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 framebuffer = new Framebuffer(window); framebuffer.Append("color", new ColorAttachment(0, pixelInformation.GetValueOrDefault(PixelInformation.RGBA_LDR), multisamples:multisamples)); if (depth) diff --git a/src/renderer/SM.OGL/Texture/PixelInformation.cs b/src/renderer/SM.OGL/Texture/PixelInformation.cs index e52e75c..109f513 100644 --- a/src/renderer/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/tests/SM_TEST/Program.cs b/tests/SM_TEST/Program.cs index d122521..f36bd80 100644 --- a/tests/SM_TEST/Program.cs +++ b/tests/SM_TEST/Program.cs @@ -63,7 +63,7 @@ namespace SM_TEST { ShowAxisHelper = true }); - //scene.Background.Color = Color4.Red; + scene.Background.Color = Color4.DarkGray; scene.Camera = new Camera() { diff --git a/tests/SM_TEST/TestRenderPipeline.cs b/tests/SM_TEST/TestRenderPipeline.cs index 978c66a..dcd7b22 100644 --- a/tests/SM_TEST/TestRenderPipeline.cs +++ b/tests/SM_TEST/TestRenderPipeline.cs @@ -14,11 +14,13 @@ namespace SM_TEST private BloomEffect _bloom; private Framebuffer _postBuffer; + private STPostProcessEffect _vittage; - public override void Initialization() + 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) { @@ -27,7 +29,7 @@ namespace SM_TEST }; PostProcessEffects.Add(_bloom); - /*_vittage = new STPostProcessEffect(Program.portal.DrawNodes.Find(a => a.Variables.ContainsKey("_ViewportSize"))) + _vittage = new STPostProcessEffect(Program.portal.DrawNodes.Find(a => a.Variables.ContainsKey("_ViewportSize"))) { Arguments = { @@ -37,10 +39,7 @@ namespace SM_TEST {"Move", 3.33f} } }; - _vittage.Initilize(this);*/ - InitizePostProcessing(); - - base.Initialization(); + PostProcessEffects.Add(_vittage); } protected override void RenderProcess(ref DrawContext context) @@ -56,6 +55,7 @@ namespace SM_TEST 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);