+ AxisHelper
~ Transformation can now set to be ignored. (Sending a Identity, when requested) ~ Changed how Meshes store Attributes
This commit is contained in:
parent
0895c600cf
commit
2e7051d800
14 changed files with 146 additions and 30 deletions
|
|
@ -11,6 +11,8 @@ namespace SM.Base.Drawing
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class GenericTransformation
|
public abstract class GenericTransformation
|
||||||
{
|
{
|
||||||
|
public bool Ignore = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Contains the current model matrix.
|
/// Contains the current model matrix.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -27,6 +29,8 @@ namespace SM.Base.Drawing
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Matrix4 GetMatrix()
|
public Matrix4 GetMatrix()
|
||||||
{
|
{
|
||||||
|
if (Ignore) return Matrix4.Identity;
|
||||||
|
|
||||||
if (_lastFrame != SMRenderer.CurrentFrame)
|
if (_lastFrame != SMRenderer.CurrentFrame)
|
||||||
{
|
{
|
||||||
_lastFrame = SMRenderer.CurrentFrame;
|
_lastFrame = SMRenderer.CurrentFrame;
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ namespace SM.Base.Objects
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected Mesh()
|
protected Mesh()
|
||||||
{
|
{
|
||||||
AttribDataIndex.Add(3, Color);
|
Attributes.Add(3, "color", Color);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
35
SMCode/SM.Base/Objects/Static/AxisHelper.cs
Normal file
35
SMCode/SM.Base/Objects/Static/AxisHelper.cs
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
using OpenTK.Graphics;
|
||||||
|
using OpenTK.Graphics.OpenGL4;
|
||||||
|
using SM.OGL.Mesh;
|
||||||
|
|
||||||
|
namespace SM.Base.Objects.Static
|
||||||
|
{
|
||||||
|
public class AxisHelper : Mesh
|
||||||
|
{
|
||||||
|
public static AxisHelper Object = new AxisHelper();
|
||||||
|
|
||||||
|
private AxisHelper() {}
|
||||||
|
|
||||||
|
public override VBO Vertex { get; } = new VBO()
|
||||||
|
{
|
||||||
|
{0, 0, 0},
|
||||||
|
{.5f, 0, 0},
|
||||||
|
{0, 0, 0},
|
||||||
|
{0, .5f, 0},
|
||||||
|
{0, 0, -.5f},
|
||||||
|
{0, 0, .5f},
|
||||||
|
};
|
||||||
|
|
||||||
|
public override VBO Color { get; } = new VBO(pointerSize:4)
|
||||||
|
{
|
||||||
|
{Color4.White},
|
||||||
|
{Color4.Red},
|
||||||
|
{Color4.White},
|
||||||
|
{Color4.Green},
|
||||||
|
{Color4.White},
|
||||||
|
{Color4.DarkBlue},
|
||||||
|
};
|
||||||
|
|
||||||
|
public override PrimitiveType PrimitiveType { get; } = PrimitiveType.Lines;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -56,6 +56,7 @@
|
||||||
<Compile Include="Drawing\Particles\ParticleDrawingBasis.cs" />
|
<Compile Include="Drawing\Particles\ParticleDrawingBasis.cs" />
|
||||||
<Compile Include="Log.cs" />
|
<Compile Include="Log.cs" />
|
||||||
<Compile Include="Objects\Mesh.cs" />
|
<Compile Include="Objects\Mesh.cs" />
|
||||||
|
<Compile Include="Objects\Static\AxisHelper.cs" />
|
||||||
<Compile Include="PostProcess\PostProcessEffect.cs" />
|
<Compile Include="PostProcess\PostProcessEffect.cs" />
|
||||||
<Compile Include="PostProcess\PostProcessShader.cs" />
|
<Compile Include="PostProcess\PostProcessShader.cs" />
|
||||||
<Compile Include="Scene\IScriptable.cs" />
|
<Compile Include="Scene\IScriptable.cs" />
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Dynamic;
|
using System.Dynamic;
|
||||||
using SM.Base.Contexts;
|
using SM.Base.Contexts;
|
||||||
|
using SM.Base.Drawing;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
@ -13,8 +14,6 @@ namespace SM.Base.Scene
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class GenericScene
|
public abstract class GenericScene
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
private IBackgroundItem _background;
|
private IBackgroundItem _background;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -34,6 +33,7 @@ namespace SM.Base.Scene
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsInitialized { get; private set; }
|
public bool IsInitialized { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates this scene.
|
/// Updates this scene.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -91,6 +91,8 @@ namespace SM.Base.Scene
|
||||||
private TCollection _hud = new TCollection();
|
private TCollection _hud = new TCollection();
|
||||||
private TCollection _objectCollection = new TCollection();
|
private TCollection _objectCollection = new TCollection();
|
||||||
|
|
||||||
|
public bool ShowAxisHelper { get; set; } = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A collection for cameras to switch easier to different cameras.
|
/// A collection for cameras to switch easier to different cameras.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -154,6 +156,7 @@ namespace SM.Base.Scene
|
||||||
DrawMainObjects(context);
|
DrawMainObjects(context);
|
||||||
|
|
||||||
DrawHUD(context);
|
DrawHUD(context);
|
||||||
|
DrawDebug(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DrawBackground(DrawContext context)
|
public void DrawBackground(DrawContext context)
|
||||||
|
|
@ -174,5 +177,10 @@ namespace SM.Base.Scene
|
||||||
context.View = HUDCamera.CalculateViewMatrix();
|
context.View = HUDCamera.CalculateViewMatrix();
|
||||||
_hud.Draw(context);
|
_hud.Draw(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void DrawDebug(DrawContext context)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,11 +1,6 @@
|
||||||
#version 330
|
#version 330
|
||||||
#define maxInstances //!instanceMax
|
#define maxInstances //!instanceMax
|
||||||
|
|
||||||
struct Instance {
|
|
||||||
mat4 ModelMatrix;
|
|
||||||
vec2 TextureOffset;
|
|
||||||
vec2 TextureScale;
|
|
||||||
};
|
|
||||||
|
|
||||||
layout(location = 0) in vec3 aPos;
|
layout(location = 0) in vec3 aPos;
|
||||||
layout(location = 1) in vec2 aTex;
|
layout(location = 1) in vec2 aTex;
|
||||||
|
|
@ -13,14 +8,13 @@ layout(location = 3) in vec4 aColor;
|
||||||
|
|
||||||
uniform mat4 MVP;
|
uniform mat4 MVP;
|
||||||
uniform bool HasVColor;
|
uniform bool HasVColor;
|
||||||
uniform Instance[maxInstances] Instances;
|
|
||||||
|
|
||||||
out vec2 vTexture;
|
out vec2 vTexture;
|
||||||
out vec4 vColor;
|
out vec4 vColor;
|
||||||
out vec3 FragPos;
|
out vec3 FragPos;
|
||||||
|
|
||||||
void ApplyTexModifier() {
|
void ApplyTexModifier() {
|
||||||
vTexture = aTex * Instances[gl_InstanceID].TextureScale + Instances[gl_InstanceID].TextureOffset;
|
vTexture = aTex;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckVertexColor() {
|
void CheckVertexColor() {
|
||||||
|
|
@ -29,7 +23,7 @@ void CheckVertexColor() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplyModelTransformation() {
|
void ApplyModelTransformation() {
|
||||||
gl_Position = MVP * Instances[gl_InstanceID].ModelMatrix * vec4(aPos, 1);
|
gl_Position = MVP * vec4(aPos, 1);
|
||||||
|
|
||||||
FragPos = vec3(Instances[gl_InstanceID].ModelMatrix * vec4(aPos, 1));
|
FragPos = vec3(vec4(aPos, 1));
|
||||||
}
|
}
|
||||||
|
|
@ -13,16 +13,17 @@ namespace SM.OGL.Mesh
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class GenericMesh : GLObject
|
public abstract class GenericMesh : GLObject
|
||||||
{
|
{
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generates the AttribDataIndex
|
/// Generates the AttribDataIndex
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected GenericMesh()
|
protected GenericMesh()
|
||||||
{
|
{
|
||||||
AttribDataIndex = new Dictionary<int, VBO>
|
Attributes = new MeshAttributeList()
|
||||||
{
|
{
|
||||||
{0, Vertex},
|
{0, "vertex", Vertex},
|
||||||
{1, UVs},
|
{1, "uv", UVs},
|
||||||
{2, Normals}
|
{2, "normal", Normals}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -61,7 +62,7 @@ namespace SM.OGL.Mesh
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Connects the different buffer objects with ids.
|
/// Connects the different buffer objects with ids.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Dictionary<int, VBO> AttribDataIndex { get; }
|
public MeshAttributeList Attributes { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Stores indices for a more performance friendly method to draw objects.
|
/// Stores indices for a more performance friendly method to draw objects.
|
||||||
|
|
@ -74,9 +75,9 @@ namespace SM.OGL.Mesh
|
||||||
_id = GL.GenVertexArray();
|
_id = GL.GenVertexArray();
|
||||||
GL.BindVertexArray(_id);
|
GL.BindVertexArray(_id);
|
||||||
|
|
||||||
if (AttribDataIndex == null) throw new Exception("[Critical] The model requires a attribute data index.");
|
if (Attributes == null) throw new Exception("[Critical] The model requires attributes.");
|
||||||
|
|
||||||
foreach (var kvp in AttribDataIndex) kvp.Value?.BindBuffer(kvp.Key);
|
foreach (var kvp in Attributes) kvp.ConnectedVBO?.BindBuffer(kvp.Index);
|
||||||
|
|
||||||
GL.BindVertexArray(0);
|
GL.BindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
16
SMCode/SM.OGL/Mesh/MeshAttribute.cs
Normal file
16
SMCode/SM.OGL/Mesh/MeshAttribute.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
namespace SM.OGL.Mesh
|
||||||
|
{
|
||||||
|
public struct MeshAttribute
|
||||||
|
{
|
||||||
|
public int Index;
|
||||||
|
public string Name;
|
||||||
|
public VBO ConnectedVBO;
|
||||||
|
|
||||||
|
public MeshAttribute(int index, string name, VBO buffer)
|
||||||
|
{
|
||||||
|
Index = index;
|
||||||
|
Name = name;
|
||||||
|
ConnectedVBO = buffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
31
SMCode/SM.OGL/Mesh/MeshAttributeList.cs
Normal file
31
SMCode/SM.OGL/Mesh/MeshAttributeList.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace SM.OGL.Mesh
|
||||||
|
{
|
||||||
|
public class MeshAttributeList : List<MeshAttribute>
|
||||||
|
{
|
||||||
|
public VBO this[string name]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
for (int i = 0; i < Count; i++)
|
||||||
|
{
|
||||||
|
if (this[i].Name == name)
|
||||||
|
{
|
||||||
|
return this[i].ConnectedVBO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Add(int id, string name, VBO vbo)
|
||||||
|
{
|
||||||
|
if (vbo == null) return;
|
||||||
|
Add(new MeshAttribute(id, name, vbo));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -51,6 +51,8 @@
|
||||||
<Compile Include="GLSystem.cs" />
|
<Compile Include="GLSystem.cs" />
|
||||||
<Compile Include="Mesh\BoundingBox.cs" />
|
<Compile Include="Mesh\BoundingBox.cs" />
|
||||||
<Compile Include="Mesh\GenericMesh.cs" />
|
<Compile Include="Mesh\GenericMesh.cs" />
|
||||||
|
<Compile Include="Mesh\MeshAttribute.cs" />
|
||||||
|
<Compile Include="Mesh\MeshAttributeList.cs" />
|
||||||
<Compile Include="Mesh\VBO.cs" />
|
<Compile Include="Mesh\VBO.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Shaders\GenericShader.cs" />
|
<Compile Include="Shaders\GenericShader.cs" />
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
#region usings
|
#region usings
|
||||||
|
|
||||||
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
|
using SM.Base.Contexts;
|
||||||
|
using SM.Base.Objects.Static;
|
||||||
using SM.Base.Scene;
|
using SM.Base.Scene;
|
||||||
using SM2D.Drawing;
|
using SM2D.Drawing;
|
||||||
|
|
||||||
|
|
@ -10,11 +13,30 @@ namespace SM2D.Scene
|
||||||
{
|
{
|
||||||
public class Scene : GenericScene<Camera, ItemCollection, I2DShowItem>
|
public class Scene : GenericScene<Camera, ItemCollection, I2DShowItem>
|
||||||
{
|
{
|
||||||
|
private static DrawObject2D _axisHelper;
|
||||||
|
|
||||||
|
public float AxisHelperSize = 100;
|
||||||
|
static Scene()
|
||||||
|
{
|
||||||
|
_axisHelper = new DrawObject2D();
|
||||||
|
_axisHelper.ApplyMesh(AxisHelper.Object);
|
||||||
|
}
|
||||||
|
|
||||||
public Scene()
|
public Scene()
|
||||||
{
|
{
|
||||||
_Background = new DrawBackground(Color4.Black);
|
_Background = new DrawBackground(Color4.Black);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public DrawBackground Background => (DrawBackground) _Background;
|
public DrawBackground Background => (DrawBackground) _Background;
|
||||||
|
|
||||||
|
public override void DrawDebug(DrawContext context)
|
||||||
|
{
|
||||||
|
if (ShowAxisHelper)
|
||||||
|
{
|
||||||
|
_axisHelper.Transform.Size.Set(AxisHelperSize, AxisHelperSize);
|
||||||
|
_axisHelper.Draw(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -26,8 +26,8 @@ namespace SM2D.Shader
|
||||||
// Vertex Uniforms
|
// Vertex Uniforms
|
||||||
Uniforms["MVP"].SetMatrix4(context.ModelMaster * context.View * context.World);
|
Uniforms["MVP"].SetMatrix4(context.ModelMaster * context.View * context.World);
|
||||||
Uniforms["HasVColor"]
|
Uniforms["HasVColor"]
|
||||||
.SetUniform1(context.Mesh.AttribDataIndex.ContainsKey(3) && context.Mesh.AttribDataIndex[3] != null);
|
.SetUniform1(context.Mesh.Attributes["color"] != null);
|
||||||
|
/*
|
||||||
Uniforms.GetArray("Instances").Set((i, uniforms) =>
|
Uniforms.GetArray("Instances").Set((i, uniforms) =>
|
||||||
{
|
{
|
||||||
if (i >= context.Instances.Count) return false;
|
if (i >= context.Instances.Count) return false;
|
||||||
|
|
@ -38,7 +38,7 @@ namespace SM2D.Shader
|
||||||
uniforms["TextureScale"].SetUniform2(instance.TextureScale);
|
uniforms["TextureScale"].SetUniform2(instance.TextureScale);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});*/
|
||||||
|
|
||||||
// Fragment Uniforms
|
// Fragment Uniforms
|
||||||
Uniforms["Tint"].SetUniform4(context.Material.Tint);
|
Uniforms["Tint"].SetUniform4(context.Material.Tint);
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,6 @@ uniform sampler2D Texture;
|
||||||
layout(location = 0) out vec4 color;
|
layout(location = 0) out vec4 color;
|
||||||
|
|
||||||
void fmain() {
|
void fmain() {
|
||||||
color = vColor * Tint;
|
color = vColor;
|
||||||
if (UseTexture) color *= texture(Texture, vTexture);
|
//if (UseTexture) color *= texture(Texture, vTexture);
|
||||||
}
|
}
|
||||||
|
|
@ -8,6 +8,7 @@ using OpenTK.Graphics;
|
||||||
using OpenTK.Input;
|
using OpenTK.Input;
|
||||||
using SM.Base;
|
using SM.Base;
|
||||||
using SM.Base.Scene;
|
using SM.Base.Scene;
|
||||||
|
using SM.Base.Textures;
|
||||||
using SM.Base.Time;
|
using SM.Base.Time;
|
||||||
using SM.Utility;
|
using SM.Utility;
|
||||||
using SM2D;
|
using SM2D;
|
||||||
|
|
@ -46,16 +47,17 @@ namespace SM_TEST
|
||||||
{
|
{
|
||||||
if (Keyboard.GetState()[Key.R])
|
if (Keyboard.GetState()[Key.R])
|
||||||
particles.Trigger();
|
particles.Trigger();
|
||||||
particles.Paused = Keyboard.GetState()[Key.P];
|
//particles.Paused = Keyboard.GetState()[Key.P];
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void WindowOnLoad(object sender, EventArgs e)
|
private static void WindowOnLoad(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
particles = new DrawParticles(TimeSpan.FromSeconds(5))
|
scene.ShowAxisHelper = true;
|
||||||
{
|
|
||||||
MaxSpeed = 10
|
DrawObject2D kasten = new DrawObject2D();
|
||||||
};
|
kasten.Transform.Size.Set(50,50);
|
||||||
window.CurrentScene.Objects.Add(particles);
|
kasten.Texture = new Texture(new Bitmap("herosword.png"));
|
||||||
|
scene.Objects.Add(kasten);
|
||||||
|
|
||||||
//particles.Trigger();
|
//particles.Trigger();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue