#MERGE 21eaa49 & 777c2f62
This commit is contained in:
commit
cf22c67e6f
11 changed files with 165 additions and 32 deletions
|
|
@ -15,6 +15,8 @@ namespace SM.Base.PostEffects
|
||||||
{
|
{
|
||||||
public class BloomEffect : PostProcessEffect
|
public class BloomEffect : PostProcessEffect
|
||||||
{
|
{
|
||||||
|
private static BezierCurve _defaultCurve = new BezierCurve(Vector2.UnitY, new Vector2(0.32f, 1), new Vector2(0.432f, 0), new Vector2(1,0));
|
||||||
|
|
||||||
private const float _defaultTextureScale = .75f;
|
private const float _defaultTextureScale = .75f;
|
||||||
|
|
||||||
private static readonly BezierCurve _defaultCurve = new BezierCurve(Vector2.UnitY, new Vector2(0.32f, 1),
|
private static readonly BezierCurve _defaultCurve = new BezierCurve(Vector2.UnitY, new Vector2(0.32f, 1),
|
||||||
|
|
@ -39,10 +41,9 @@ namespace SM.Base.PostEffects
|
||||||
private BezierCurve _weightCurve;
|
private BezierCurve _weightCurve;
|
||||||
private float[] _weights;
|
private float[] _weights;
|
||||||
|
|
||||||
private ColorAttachment _xBuffer;
|
public int Iterations = 1;
|
||||||
private ColorAttachment _yBuffer;
|
public float Threshold = .8f;
|
||||||
public TextureBase AmountMap;
|
public float Power = 1;
|
||||||
public TextureTransformation AmountTransform = new TextureTransformation();
|
|
||||||
|
|
||||||
public bool Enable = true;
|
public bool Enable = true;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,7 @@
|
||||||
<Compile Include="Drawing\ShaderArguments.cs" />
|
<Compile Include="Drawing\ShaderArguments.cs" />
|
||||||
<Compile Include="Drawing\TextureTransformation.cs" />
|
<Compile Include="Drawing\TextureTransformation.cs" />
|
||||||
<Compile Include="PostEffects\PostProcessFinals.cs" />
|
<Compile Include="PostEffects\PostProcessFinals.cs" />
|
||||||
|
<Compile Include="Scene\IFixedScriptable.cs" />
|
||||||
<Compile Include="Shaders\MaterialShader.cs" />
|
<Compile Include="Shaders\MaterialShader.cs" />
|
||||||
<Compile Include="Drawing\Particles\ParticleContext.cs" />
|
<Compile Include="Drawing\Particles\ParticleContext.cs" />
|
||||||
<Compile Include="Drawing\Particles\ParticleMovement.cs" />
|
<Compile Include="Drawing\Particles\ParticleMovement.cs" />
|
||||||
|
|
@ -75,6 +76,7 @@
|
||||||
<Compile Include="Utility\Ray.cs" />
|
<Compile Include="Utility\Ray.cs" />
|
||||||
<Compile Include="Utility\Util.cs" />
|
<Compile Include="Utility\Util.cs" />
|
||||||
<Compile Include="Window\Contexts\DrawContext.cs" />
|
<Compile Include="Window\Contexts\DrawContext.cs" />
|
||||||
|
<Compile Include="Window\Contexts\FixedUpdateContext.cs" />
|
||||||
<Compile Include="Window\Contexts\UpdateContext.cs" />
|
<Compile Include="Window\Contexts\UpdateContext.cs" />
|
||||||
<Compile Include="Window\GLWindow.cs" />
|
<Compile Include="Window\GLWindow.cs" />
|
||||||
<Compile Include="Log.cs" />
|
<Compile Include="Log.cs" />
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using SM.Base.Drawing;
|
using SM.Base.Drawing;
|
||||||
using SM.Base.Window;
|
using SM.Base.Windows;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
@ -12,9 +12,9 @@ namespace SM.Base.Scene
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains a list of show items.
|
/// Contains a list of show items.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class GenericItemCollection : List<IShowItem>, IShowItem, IShowCollection, IScriptable
|
public abstract class GenericItemCollection : List<IShowItem>, IShowItem, IShowCollection, IScriptable, IFixedScriptable
|
||||||
{
|
{
|
||||||
private readonly List<IScriptable> _scriptableObjects = new List<IScriptable>();
|
private List<IScriptable> _scriptableObjects = new List<IScriptable>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Currently active script objects.
|
/// Currently active script objects.
|
||||||
|
|
@ -43,6 +43,16 @@ namespace SM.Base.Scene
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool RenderActive { get; set; } = true;
|
public bool RenderActive { get; set; } = true;
|
||||||
|
|
||||||
|
public virtual void FixedUpdate(FixedUpdateContext context)
|
||||||
|
{
|
||||||
|
if (!Active || !UpdateActive) return;
|
||||||
|
|
||||||
|
for (int i = 0; i < _fixedScriptables.Count; i++)
|
||||||
|
{
|
||||||
|
_fixedScriptables[i].FixedUpdate(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="IShowCollection.Draw" />
|
/// <inheritdoc cref="IShowCollection.Draw" />
|
||||||
public virtual void Draw(DrawContext context)
|
public virtual void Draw(DrawContext context)
|
||||||
{
|
{
|
||||||
|
|
@ -88,6 +98,8 @@ namespace SM.Base.Scene
|
||||||
|
|
||||||
if (item is IScriptable scriptable)
|
if (item is IScriptable scriptable)
|
||||||
AddScript(scriptable);
|
AddScript(scriptable);
|
||||||
|
|
||||||
|
if (item is IFixedScriptable fixedScriptable) _fixedScriptables.Add(fixedScriptable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -109,6 +121,7 @@ namespace SM.Base.Scene
|
||||||
public void AddScript(IScriptable item)
|
public void AddScript(IScriptable item)
|
||||||
{
|
{
|
||||||
_scriptableObjects.Add(item);
|
_scriptableObjects.Add(item);
|
||||||
|
if (item is IFixedScriptable fs) _fixedScriptables.Add(fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Remove(params IShowItem[] items)
|
public void Remove(params IShowItem[] items)
|
||||||
|
|
@ -119,6 +132,9 @@ namespace SM.Base.Scene
|
||||||
|
|
||||||
if (item is IScriptable scriptable)
|
if (item is IScriptable scriptable)
|
||||||
RemoveScript(scriptable);
|
RemoveScript(scriptable);
|
||||||
|
|
||||||
|
if (item is IFixedScriptable fixedScriptable)
|
||||||
|
_fixedScriptables.Remove(fixedScriptable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -140,6 +156,7 @@ namespace SM.Base.Scene
|
||||||
public void RemoveScript(IScriptable item)
|
public void RemoveScript(IScriptable item)
|
||||||
{
|
{
|
||||||
_scriptableObjects.Remove(item);
|
_scriptableObjects.Remove(item);
|
||||||
|
if (item is IFixedScriptable fs) _fixedScriptables.Remove(fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICollection<IShowItem> GetAllItems(bool includeCollections = false)
|
public ICollection<IShowItem> GetAllItems(bool includeCollections = false)
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,12 @@ namespace SM.Base.Scene
|
||||||
_hud?.Update(context);
|
_hud?.Update(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void FixedUpdate(FixedUpdateContext context)
|
||||||
|
{
|
||||||
|
_objectCollection?.FixedUpdate(context);
|
||||||
|
_hud?.FixedUpdate(context);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Draws this scene.
|
/// Draws this scene.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
15
SMCode/SM.Base/Scene/IFixedScriptable.cs
Normal file
15
SMCode/SM.Base/Scene/IFixedScriptable.cs
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
using SM.Base.Window.Contexts;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SM.Base.Scene
|
||||||
|
{
|
||||||
|
public interface IFixedScriptable
|
||||||
|
{
|
||||||
|
void FixedUpdate(FixedUpdateContext context);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -14,6 +14,8 @@ namespace SM.Base.Shaders
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class MaterialShader : GenericShader
|
public abstract class MaterialShader : GenericShader
|
||||||
{
|
{
|
||||||
|
static bool _canLineWidth = true;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected MaterialShader(string combinedData) : base(combinedData)
|
protected MaterialShader(string combinedData) : base(combinedData)
|
||||||
{
|
{
|
||||||
|
|
@ -39,10 +41,20 @@ namespace SM.Base.Shaders
|
||||||
|
|
||||||
context.Mesh.Activate();
|
context.Mesh.Activate();
|
||||||
|
|
||||||
|
if (_canLineWidth)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
if (context.Mesh is ILineMesh lineMesh)
|
if (context.Mesh is ILineMesh lineMesh)
|
||||||
GL.LineWidth(context.Material.ShaderArguments.Get("LineWidth", lineMesh.LineWidth));
|
GL.LineWidth(context.Material.ShaderArguments.Get("LineWidth", lineMesh.LineWidth));
|
||||||
else if (context.Material.ShaderArguments.ContainsKey("LineWidth"))
|
else if (context.Material.ShaderArguments.ContainsKey("LineWidth"))
|
||||||
GL.LineWidth((float)context.Material.ShaderArguments["LineWidth"]);
|
GL.LineWidth((float)context.Material.ShaderArguments["LineWidth"]);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
_canLineWidth = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (context.Material.Blending)
|
if (context.Material.Blending)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,24 @@
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool UseRender;
|
public bool UseRender;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The current update delta time.
|
||||||
|
/// </summary>
|
||||||
|
public static float UpdateDelta { get; internal set; }
|
||||||
|
|
||||||
|
public static float FixedUpdateDelta { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The current render delta time.
|
||||||
|
/// </summary>
|
||||||
|
public static float RenderDelta { get; internal set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The calculated delta time.
|
||||||
|
/// </summary>
|
||||||
|
public float DeltaTime => (UseRender ? RenderDelta : UpdateDelta) * Scale;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a delta time assistant.
|
/// Creates a delta time assistant.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -30,20 +48,5 @@
|
||||||
UseRender = useRender;
|
UseRender = useRender;
|
||||||
Scale = scale;
|
Scale = scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The current update delta time.
|
|
||||||
/// </summary>
|
|
||||||
public static float UpdateDelta { get; internal set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The current render delta time.
|
|
||||||
/// </summary>
|
|
||||||
public static float RenderDelta { get; internal set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The calculated delta time.
|
|
||||||
/// </summary>
|
|
||||||
public float DeltaTime => (UseRender ? RenderDelta : UpdateDelta) * Scale;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
13
SMCode/SM.Base/Window/Contexts/FixedUpdateContext.cs
Normal file
13
SMCode/SM.Base/Window/Contexts/FixedUpdateContext.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SM.Base.Window.Contexts
|
||||||
|
{
|
||||||
|
public struct FixedUpdateContext
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,9 @@ using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using OpenTK.Input;
|
using OpenTK.Input;
|
||||||
using SM.Base.Scene;
|
using SM.Base.Scene;
|
||||||
|
using SM.Base.Window.Contexts;
|
||||||
using SM.OGL;
|
using SM.OGL;
|
||||||
|
using SM.Utility;
|
||||||
using Mouse = SM.Base.Controls.Mouse;
|
using Mouse = SM.Base.Controls.Mouse;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
@ -16,6 +18,7 @@ namespace SM.Base.Window
|
||||||
public class GLWindow : GameWindow, IGenericWindow
|
public class GLWindow : GameWindow, IGenericWindow
|
||||||
{
|
{
|
||||||
private Vector2 _flagWindowSize;
|
private Vector2 _flagWindowSize;
|
||||||
|
private Thread _fixedUpdateThread;
|
||||||
|
|
||||||
public WindowFlags WindowFlags;
|
public WindowFlags WindowFlags;
|
||||||
|
|
||||||
|
|
@ -149,6 +152,47 @@ namespace SM.Base.Window
|
||||||
Mouse.MouseMoveEvent(e, this);
|
Mouse.MouseMoveEvent(e, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnClosing(CancelEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnClosing(e);
|
||||||
|
_fixedUpdateThread.Abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(UpdateContext context)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ApplySetup(ISetup setup)
|
||||||
|
{
|
||||||
|
AppliedSetup = setup;
|
||||||
|
setup.Applied(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetScene(GenericScene scene)
|
||||||
|
{
|
||||||
|
if (Loading)
|
||||||
|
{
|
||||||
|
Loaded += window => SetScene(scene);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowCode.PrepareScene(this, scene);
|
||||||
|
CurrentScene = scene;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetRenderPipeline(RenderPipeline renderPipeline)
|
||||||
|
{
|
||||||
|
if (Loading)
|
||||||
|
{
|
||||||
|
Loaded += window => SetRenderPipeline(renderPipeline);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
WindowCode.PreparePipeline(this, renderPipeline);
|
||||||
|
CurrentRenderPipeline = renderPipeline;
|
||||||
|
}
|
||||||
|
|
||||||
public void ChangeWindowFlag(WindowFlags newFlag)
|
public void ChangeWindowFlag(WindowFlags newFlag)
|
||||||
{
|
{
|
||||||
WindowFlags = newFlag;
|
WindowFlags = newFlag;
|
||||||
|
|
@ -175,12 +219,29 @@ namespace SM.Base.Window
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException(nameof(newFlag), newFlag, null);
|
throw new ArgumentOutOfRangeException(nameof(newFlag), newFlag, null);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (newFlag == WindowFlags.BorderlessWindow)
|
public void RunFixedUpdate(float updatesPerSecond)
|
||||||
{
|
{
|
||||||
WindowBorder = WindowBorder.Hidden;
|
Deltatime.FixedUpdateDelta = 1 / (float)updatesPerSecond;
|
||||||
X = Screen.PrimaryScreen.Bounds.X;
|
|
||||||
Y = Screen.PrimaryScreen.Bounds.Y;
|
_fixedUpdateThread = new Thread(ExecuteFixedUpdate);
|
||||||
|
_fixedUpdateThread.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ExecuteFixedUpdate()
|
||||||
|
{
|
||||||
|
Stopwatch deltaStop = new Stopwatch();
|
||||||
|
while (Thread.CurrentThread.ThreadState != System.Threading.ThreadState.AbortRequested)
|
||||||
|
{
|
||||||
|
deltaStop.Restart();
|
||||||
|
|
||||||
|
FixedUpdateContext context = new FixedUpdateContext();
|
||||||
|
|
||||||
|
CurrentScene?.FixedUpdate(context);
|
||||||
|
|
||||||
|
long delta = deltaStop.ElapsedMilliseconds;
|
||||||
|
Thread.Sleep(Math.Max((int)(Deltatime.FixedUpdateDelta * 1000) - (int)delta, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ namespace SM_TEST
|
||||||
DrawObject2D box = new DrawObject2D();
|
DrawObject2D box = new DrawObject2D();
|
||||||
scene.Objects.Add(box);
|
scene.Objects.Add(box);
|
||||||
|
|
||||||
DrawText text = new DrawText(font, "Text");
|
DrawText text = new DrawText(font, "Test Text");
|
||||||
text.Transform.Position.Set(50, 0);
|
text.Transform.Position.Set(50, 0);
|
||||||
text.Transform.Size.Set(2);
|
text.Transform.Size.Set(2);
|
||||||
scene.Objects.Add(text);
|
scene.Objects.Add(text);
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,12 @@ namespace SM_TEST
|
||||||
|
|
||||||
_postBuffer = CreateWindowFramebuffer();
|
_postBuffer = CreateWindowFramebuffer();
|
||||||
Framebuffers.Add(_postBuffer);
|
Framebuffers.Add(_postBuffer);
|
||||||
|
_bloom = new BloomEffect(hdr: true)
|
||||||
|
{
|
||||||
|
Threshold = .8f,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
_bloom = new BloomEffect(_postBuffer, hdr: true);
|
|
||||||
_bloom.Initilize(this);
|
_bloom.Initilize(this);
|
||||||
base.Initialization();
|
base.Initialization();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue