05.01.2021

+ Bloom effect
+ PixelInformation
+ Many Summaries
+ Add-methods for CVectors
+ Exposure-Field in GenericCamera for HDR.

~ ColorAttachments now can have PixelInformation
~ Transformed MeshAttributes to a own class
~ Fixed the non-applying of transformations at texts
~ Added more information to the context
~ Improved Pipeline-Process.
~ Changed how Uniform takes arrays

- Light system
This commit is contained in:
Michel Fedde 2021-01-06 17:04:15 +01:00
parent 9b917ac181
commit 4c18127c88
52 changed files with 697 additions and 373 deletions

View file

@ -21,6 +21,65 @@ namespace SM.Base.Contexts
/// </summary>
public bool ForceViewport;
/// <summary>
/// Contains the currently used render pipeline.
/// </summary>
public RenderPipeline ActivePipeline;
public GenericScene ActiveScene;
public GenericWindow Window;
public GenericCamera UsedCamera =>
ForceViewport || ActiveScene._camera == null ? Window._viewportCamera : ActiveScene._camera;
/// <summary>
/// The mesh.
/// </summary>
public GenericMesh Mesh;
/// <summary>
/// The material.
/// </summary>
public Material Material;
/// <summary>
/// The drawing instances.
/// <para>If there is only one, it's index 0</para>
/// </summary>
public IList<Instance> Instances;
/// <summary>
/// The current world scale.
/// </summary>
public Vector2 WorldScale;
/// <summary>
/// The last collection the context was passed though.
/// </summary>
public object LastPassthough;
/// <summary>
/// Returns the appropriate shader.
/// <para>
/// Returns the material shader, if available, otherwise it will take the default shader from the render
/// pipeline.
/// </para>
/// </summary>
public MaterialShader Shader => Material.CustomShader ?? ActivePipeline._defaultShader;
/// <summary>
/// Arguments for shaders
/// </summary>
public IDictionary<string, object> ShaderArguments;
/// <summary>
/// The current world matrix.
/// </summary>
@ -40,50 +99,5 @@ namespace SM.Base.Contexts
/// The master model matrix.
/// </summary>
public Matrix4 ModelMaster;
/// <summary>
/// The drawing instances.
/// <para>If there is only one, it's index 0</para>
/// </summary>
public IList<Instance> Instances;
/// <summary>
/// The mesh.
/// </summary>
public GenericMesh Mesh;
/// <summary>
/// The material.
/// </summary>
public Material Material;
/// <summary>
/// Contains the currently used render pipeline.
/// </summary>
public RenderPipeline ActivePipeline;
/// <summary>
/// The current world scale.
/// </summary>
public Vector2 WorldScale;
/// <summary>
/// The last collection the context was passed though.
/// </summary>
public object LastPassthough;
/// <summary>
/// Arguments for shaders
/// </summary>
public IDictionary<string, object> ShaderArguments;
/// <summary>
/// Returns the appropriate shader.
/// <para>
/// Returns the material shader, if available, otherwise it will take the default shader from the render
/// pipeline.
/// </para>
/// </summary>
public MaterialShader Shader => Material.CustomShader ?? ActivePipeline._defaultShader;
}
}

View file

@ -49,6 +49,8 @@ namespace SM.Base
/// </summary>
public bool ReactWhileUnfocused = false;
internal GenericCamera _viewportCamera;
/// <inheritdoc />
protected GenericWindow() : this(1280, 720, "Generic OGL Title", GameWindowFlags.Default)
{
@ -223,13 +225,16 @@ namespace SM.Base
/// <inheritdoc />
protected GenericWindow()
{
ViewportCamera = new TCamera();
_viewportCamera = new TCamera();
}
/// <summary>
/// The viewport camera.
/// </summary>
public TCamera ViewportCamera { get; }
public TCamera ViewportCamera {
get => (TCamera)_viewportCamera;
set => _viewportCamera = value;
}
/// <summary>
/// This forces the render to use the viewport camera.
@ -258,29 +263,37 @@ namespace SM.Base
{
if (!ReactWhileUnfocused && !Focused) return;
if (CurrentScene == null) return;
SMRenderer.CurrentFrame++;
Deltatime.RenderDelta = (float) e.Time;
var drawContext = new DrawContext
{
World = ViewportCamera.World,
View = ViewportCamera.CalculateViewMatrix(),
ModelMaster = Matrix4.Identity,
ForceViewport = ForceViewportCamera,
ActiveScene = CurrentScene,
Window = this,
Instances = new[]
{
new Instance
{ModelMatrix = Matrix4.Identity, TexturePosition = Vector2.Zero, TextureScale = Vector2.One}
},
ShaderArguments = new Dictionary<string, object>(),
Mesh = Plate.Object,
ForceViewport = ForceViewportCamera,
WorldScale = _worldScale,
LastPassthough = this
LastPassthough = this,
ShaderArguments = new Dictionary<string, object>(),
World = ViewportCamera.World,
View = ViewportCamera.CalculateViewMatrix(),
ModelMaster = Matrix4.Identity
};
base.OnRenderFrame(e);
RenderPipeline.Render(ref drawContext, CurrentScene);
RenderPipeline.Render(ref drawContext);
SwapBuffers();

View file

@ -29,12 +29,14 @@ namespace SM.Base
/// <summary>
/// The framebuffers, that are used in this Pipeline.
/// </summary>
protected virtual List<Framebuffer> _framebuffers { get; }
public virtual List<Framebuffer> Framebuffers { get; private set; }
/// <summary>
/// The default shader for the pipeline.
/// </summary>
protected internal virtual MaterialShader _defaultShader { get; } = SMRenderer.DefaultMaterialShader;
protected internal virtual MaterialShader _defaultShader { get; set; }
public virtual Framebuffer MainFramebuffer { get; protected set; }= Framebuffer.Screen;
/// <summary>
/// Occurs, when the window is loading.
@ -48,14 +50,14 @@ namespace SM.Base
/// </summary>
protected internal virtual void Resize()
{
if (_framebuffers == null) return;
if (Framebuffers == null) return;
foreach (var framebuffer in _framebuffers)
foreach (var framebuffer in Framebuffers)
framebuffer.Dispose();
Thread.Sleep(50);
foreach (Framebuffer framebuffer in _framebuffers)
foreach (Framebuffer framebuffer in Framebuffers)
{
framebuffer.Compile();
}
@ -67,7 +69,13 @@ namespace SM.Base
if (!IsInitialized)
{
if (_defaultShader == null) _defaultShader = SMRenderer.DefaultMaterialShader;
Framebuffers = new List<Framebuffer>();
Initialization(window);
Framebuffers.Add(MainFramebuffer);
IsInitialized = true;
}
@ -106,7 +114,6 @@ namespace SM.Base
{
Framebuffer framebuffer = new Framebuffer(window: SMRenderer.CurrentWindow);
framebuffer.Append("color", 0);
framebuffer.Compile();
return framebuffer;
}
}
@ -121,11 +128,15 @@ namespace SM.Base
/// <summary>
/// The system to render stuff.
/// </summary>
protected internal virtual void Render(ref DrawContext context, TScene scene)
internal void Render(ref DrawContext context)
{
context.ActivePipeline = this;
RenderProcess(ref context, (TScene)context.ActiveScene);
}
protected abstract void RenderProcess(ref DrawContext context, TScene scene);
/// <summary>
/// Event, that triggers, when the scene in the current window changes.
/// </summary>