27.09.2020
~ Moved Default-Shader to 2D to provied 2D-specific feature ~ Fixed UVs in Polygon
This commit is contained in:
parent
617a7ef044
commit
2aa12f8d25
19 changed files with 166 additions and 83 deletions
47
SMCode/SM2D/Shader/Default2DShader.cs
Normal file
47
SMCode/SM2D/Shader/Default2DShader.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
using OpenTK.Graphics.OpenGL4;
|
||||
using SM.Base.Contexts;
|
||||
using SM.Base.Scene;
|
||||
using SM.OGL.Shaders;
|
||||
using SM.Utility;
|
||||
|
||||
namespace SM2D.Shader
|
||||
{
|
||||
public class Default2DShader : GenericShader, IShader
|
||||
{
|
||||
protected override bool AutoCompile { get; } = true;
|
||||
|
||||
public Default2DShader() : base(new ShaderFileCollection(
|
||||
AssemblyUtility.ReadAssemblyFile("Shader.ShaderFiles.default.vert"),
|
||||
AssemblyUtility.ReadAssemblyFile("Shader.ShaderFiles.default.frag")))
|
||||
{
|
||||
|
||||
}
|
||||
public void Draw(DrawContext context)
|
||||
{
|
||||
GL.UseProgram(this);
|
||||
|
||||
GL.BindVertexArray(context.Mesh);
|
||||
|
||||
// Vertex Uniforms
|
||||
Uniforms["MVP"].SetMatrix4(context.View * context.World);
|
||||
Uniforms["HasVColor"].SetUniform1(context.Mesh.AttribDataIndex.ContainsKey(3) && context.Mesh.AttribDataIndex[3] != null);
|
||||
|
||||
for (int i = 0; i < context.Instances.Length; i++)
|
||||
{
|
||||
GL.UniformMatrix4(Uniforms["ModelMatrix"] + i, false, ref context.Instances[i].ModelMatrix);
|
||||
GL.Uniform2(Uniforms["TextureOffset"] + i, context.Instances[i].TexturePosition);
|
||||
GL.Uniform2(Uniforms["TextureScale"] + i, context.Instances[i].TextureScale);
|
||||
}
|
||||
|
||||
// Fragment Uniforms
|
||||
Uniforms["Tint"].SetUniform4(context.Material.Tint);
|
||||
Uniforms["Texture"].SetTexture(context.Material.Texture, Uniforms["UseTexture"]);
|
||||
|
||||
DrawObject(context.Mesh, context.Instances.Length);
|
||||
|
||||
CleanUp();
|
||||
|
||||
GL.UseProgram(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue