28.10.2020
SM.Core: + Particle System + scriptable system for scripts ~ Moved Texts- and Particles-namespace to SM.Base.Drawing ~ Changed how you tell the stopwatch to pause. (From method to property) ~ Fixed Randomize.GetFloat(min, max) ~ Now automaticly adds the DrawingBase.Transformation to DrawContext.ModelMatrix. No need to change DrawContext.Instances[0], anymore. SM.OGL: + "one-file-shader"-support SM2D: + DrawParticles (Control for Texture and Color not there yet) ~ Changed coordnate system to upper-right as (1,1) ~ Changed default shader to "one-file-shader"
This commit is contained in:
parent
03b3942732
commit
beb9c19081
45 changed files with 580 additions and 190 deletions
|
|
@ -5,6 +5,7 @@ using System.Drawing;
|
|||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using SM.Base.Contexts;
|
||||
using SM.Base.Drawing;
|
||||
using SM.Base.Objects.Static;
|
||||
using SM.Base.Scene;
|
||||
using SM.Base.Textures;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using SM.Base.Contexts;
|
||||
using SM.Base.Drawing;
|
||||
using SM.Base.Scene;
|
||||
using SM2D.Scene;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
using OpenTK.Graphics;
|
||||
using SM.Base.Contexts;
|
||||
using SM.Base.Drawing;
|
||||
using SM.Base.Scene;
|
||||
using SM2D.Scene;
|
||||
using SM2D.Types;
|
||||
|
|
@ -31,8 +32,6 @@ namespace SM2D.Drawing
|
|||
|
||||
protected override void DrawContext(ref DrawContext context)
|
||||
{
|
||||
context.Instances[0].ModelMatrix = Transform.GetMatrix();
|
||||
|
||||
context.Shader.Draw(context);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#region usings
|
||||
|
||||
using SM.Base.Contexts;
|
||||
using SM.Base.Drawing;
|
||||
using SM.Base.Scene;
|
||||
using SM.OGL.Mesh;
|
||||
using SM2D.Scene;
|
||||
|
|
@ -28,7 +29,7 @@ namespace SM2D.Drawing
|
|||
|
||||
protected override void DrawContext(ref DrawContext context)
|
||||
{
|
||||
context.Instances[0].ModelMatrix = Transform.GetMatrix();
|
||||
base.DrawContext(ref context);
|
||||
|
||||
context.Shader.Draw(context);
|
||||
}
|
||||
|
|
|
|||
34
SMCode/SM2D/Drawing/DrawParticles.cs
Normal file
34
SMCode/SM2D/Drawing/DrawParticles.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
using System;
|
||||
using OpenTK;
|
||||
using SM.Base.Drawing.Particles;
|
||||
using SM.Utility;
|
||||
using SM2D.Scene;
|
||||
using SM2D.Types;
|
||||
|
||||
namespace SM2D.Drawing
|
||||
{
|
||||
public class DrawParticles : ParticleDrawingBasis<Transformation, Vector2>, I2DShowItem
|
||||
{
|
||||
public int ZIndex { get; set; }
|
||||
public override Func<Vector2, ParticleContext, Vector2> MovementCalculation { get; set; } = ParticleMovement.Default2D;
|
||||
|
||||
public DrawParticles(TimeSpan duration) : base(duration)
|
||||
{
|
||||
}
|
||||
|
||||
protected override ParticleStruct<Vector2> CreateObject(int index)
|
||||
{
|
||||
return new ParticleStruct<Vector2>()
|
||||
{
|
||||
Matrix = Matrix4.CreateScale(1),
|
||||
Direction = new Vector2(Randomize.GetFloat(-1, 1), Randomize.GetFloat(-1, 1)),
|
||||
Speed = Randomize.GetFloat(MaxSpeed)
|
||||
};
|
||||
}
|
||||
|
||||
protected override Matrix4 CreateMatrix(ParticleStruct<Vector2> Struct, Vector2 direction)
|
||||
{
|
||||
return Struct.Matrix * Matrix4.CreateTranslation(direction.X, direction.Y, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using SM.Base.Contexts;
|
||||
using SM.Base.Drawing;
|
||||
using SM.Base.Scene;
|
||||
using SM2D.Scene;
|
||||
using SM2D.Types;
|
||||
|
|
@ -16,8 +17,7 @@ namespace SM2D.Drawing
|
|||
|
||||
protected override void DrawContext(ref DrawContext context)
|
||||
{
|
||||
context.Instances[0].ModelMatrix = Transform.GetMatrix();
|
||||
|
||||
base.DrawContext(ref context);
|
||||
_material.CustomShader.Draw(context);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#region usings
|
||||
|
||||
using SM.Base.Contexts;
|
||||
using SM.Base.Text;
|
||||
using SM.Base.Drawing.Text;
|
||||
using SM.Base.Types;
|
||||
using SM2D.Scene;
|
||||
using SM2D.Types;
|
||||
|
|
@ -24,9 +24,7 @@ namespace SM2D.Drawing
|
|||
{
|
||||
base.DrawContext(ref context);
|
||||
context.Instances = _instances;
|
||||
|
||||
context.View = Transform.GetMatrix() * context.View;
|
||||
|
||||
|
||||
context.Shader.Draw(context);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@
|
|||
<Compile Include="Drawing\DrawBackgroundShader.cs" />
|
||||
<Compile Include="Drawing\DrawColor.cs" />
|
||||
<Compile Include="Drawing\DrawComplex.cs" />
|
||||
<Compile Include="Drawing\DrawParticles.cs" />
|
||||
<Compile Include="Drawing\DrawPolygon.cs" />
|
||||
<Compile Include="Drawing\DrawShader.cs" />
|
||||
<Compile Include="Drawing\DrawText.cs" />
|
||||
|
|
@ -71,13 +72,10 @@
|
|||
<Name>SM.OGL</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Shader\ShaderFiles\default.frag" />
|
||||
<EmbeddedResource Include="Shader\ShaderFiles\default.vert" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="OpenTK.dll.config" />
|
||||
<None Include="packages.config" />
|
||||
<EmbeddedResource Include="Shader\ShaderFiles\default.glsl" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
|
|
@ -21,7 +21,7 @@ namespace SM2D.Scene
|
|||
public override void RecalculateWorld(Vector2 world, float aspect)
|
||||
{
|
||||
OrthographicWorld =
|
||||
Matrix4.CreateOrthographicOffCenter(-world.X / 2, world.X / 2, world.Y / 2, -world.Y / 2, 0.1f, 4f);
|
||||
Matrix4.CreateOrthographic(world.X, world.Y, 0.1f, 100f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using SM.Base.Contexts;
|
||||
using SM.Base.Drawing;
|
||||
using SM.Base.Scene;
|
||||
using SM.OGL.Shaders;
|
||||
using SM.Utility;
|
||||
|
|
@ -13,12 +14,9 @@ namespace SM2D.Shader
|
|||
public class Default2DShader : MaterialShader
|
||||
{
|
||||
public static Default2DShader MaterialShader = new Default2DShader();
|
||||
|
||||
|
||||
//protected override bool AutoCompile { get; } = true;
|
||||
|
||||
private Default2DShader() : base(new ShaderFileCollection(
|
||||
AssemblyUtility.ReadAssemblyFile("SM2D.Shader.ShaderFiles.default.vert"),
|
||||
AssemblyUtility.ReadAssemblyFile("SM2D.Shader.ShaderFiles.default.frag")))
|
||||
private Default2DShader() : base(AssemblyUtility.ReadAssemblyFile("SM2D.Shader.ShaderFiles.default.glsl"))
|
||||
{
|
||||
Load();
|
||||
}
|
||||
|
|
@ -32,7 +30,7 @@ namespace SM2D.Shader
|
|||
|
||||
Uniforms.GetArray("Instances").Set((i, uniforms) =>
|
||||
{
|
||||
if (i >= context.Instances.Length) return false;
|
||||
if (i >= context.Instances.Count) return false;
|
||||
|
||||
var instance = context.Instances[i];
|
||||
uniforms["ModelMatrix"].SetMatrix4(instance.ModelMatrix);
|
||||
|
|
@ -46,7 +44,7 @@ namespace SM2D.Shader
|
|||
Uniforms["Tint"].SetUniform4(context.Material.Tint);
|
||||
Uniforms["Texture"].SetTexture(context.Material.Texture, Uniforms["UseTexture"]);
|
||||
|
||||
DrawObject(context.Mesh, context.Instances.Length);
|
||||
DrawObject(context.Mesh, context.Instances.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
#version 330
|
||||
|
||||
in vec2 vTexture;
|
||||
in vec4 vColor;
|
||||
|
||||
uniform vec4 Tint;
|
||||
uniform bool UseTexture;
|
||||
uniform sampler2D Texture;
|
||||
|
||||
layout(location = 0) out vec4 color;
|
||||
|
||||
void main() {
|
||||
color = vColor * Tint;
|
||||
if (UseTexture) color *= texture(Texture, vTexture);
|
||||
}
|
||||
29
SMCode/SM2D/Shader/ShaderFiles/default.glsl
Normal file
29
SMCode/SM2D/Shader/ShaderFiles/default.glsl
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#version 330
|
||||
|
||||
//# region vertex
|
||||
|
||||
//# import SM_base_vertex_basic
|
||||
void ApplyTexModifier();
|
||||
void CheckVertexColor();
|
||||
void ApplyModelTransformation();
|
||||
|
||||
void vmain() {
|
||||
ApplyTexModifier();
|
||||
CheckVertexColor();
|
||||
ApplyModelTransformation();
|
||||
}
|
||||
|
||||
//# region fragment
|
||||
in vec2 vTexture;
|
||||
in vec4 vColor;
|
||||
|
||||
uniform vec4 Tint;
|
||||
uniform bool UseTexture;
|
||||
uniform sampler2D Texture;
|
||||
|
||||
layout(location = 0) out vec4 color;
|
||||
|
||||
void fmain() {
|
||||
color = vColor * Tint;
|
||||
if (UseTexture) color *= texture(Texture, vTexture);
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
#version 330
|
||||
|
||||
//# import SM_base_vertex_basic
|
||||
void ApplyTexModifier();
|
||||
void CheckVertexColor();
|
||||
void ApplyModelTransformation();
|
||||
|
||||
void main() {
|
||||
ApplyTexModifier();
|
||||
CheckVertexColor();
|
||||
ApplyModelTransformation();
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
#region usings
|
||||
|
||||
using OpenTK;
|
||||
using SM.Base.Drawing;
|
||||
using SM.Base.Scene;
|
||||
using SM.Base.Types;
|
||||
using SM.Utility;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue