~ Changed Pipelines
(Default2DPipeline: Has Lights, Post-ProcessingEffects, etc.) (Basic2DPipeline: Simple Color and Texture stuff, thats it)
This commit is contained in:
parent
1ed03fec3f
commit
5d4b360b05
23 changed files with 243 additions and 59 deletions
40
SMCode/SM2D/Shader/Basic2DShader.cs
Normal file
40
SMCode/SM2D/Shader/Basic2DShader.cs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
using SM.Base.Contexts;
|
||||
using SM.Base.Drawing;
|
||||
using SM.OGL.Shaders;
|
||||
using SM.Utility;
|
||||
|
||||
namespace SM2D.Shader
|
||||
{
|
||||
public class Basic2DShader : MaterialShader
|
||||
{
|
||||
|
||||
public static Basic2DShader Shader = new Basic2DShader();
|
||||
private Basic2DShader() : base(AssemblyUtility.ReadAssemblyFile("SM2D.Shader.ShaderFiles.basic.glsl"))
|
||||
{
|
||||
}
|
||||
|
||||
protected override void DrawProcess(DrawContext context)
|
||||
{
|
||||
// Vertex Uniforms
|
||||
Uniforms["MVP"].SetMatrix4(context.ModelMaster * context.View * context.World);
|
||||
Uniforms["HasVColor"]
|
||||
.SetUniform1(context.Mesh.Attributes["color"] != null);
|
||||
|
||||
UniformArray instances = Uniforms.GetArray("Instances");
|
||||
for (int i = 0; i < context.Instances.Count; i++)
|
||||
{
|
||||
var shaderInstance = instances[i];
|
||||
var instance = context.Instances[i];
|
||||
shaderInstance["ModelMatrix"].SetMatrix4(instance.ModelMatrix);
|
||||
shaderInstance["TextureOffset"].SetUniform2(instance.TexturePosition);
|
||||
shaderInstance["TextureScale"].SetUniform2(instance.TextureScale);
|
||||
}
|
||||
|
||||
// Fragment Uniforms
|
||||
Uniforms["Tint"].SetUniform4(context.Material.Tint);
|
||||
Uniforms["Texture"].SetTexture(context.Material.Texture, Uniforms["UseTexture"]);
|
||||
|
||||
DrawObject(context.Mesh, context.Instances.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -27,6 +27,7 @@ namespace SM2D.Shader
|
|||
Uniforms["MVP"].SetMatrix4(context.ModelMaster * context.View * context.World);
|
||||
Uniforms["HasVColor"]
|
||||
.SetUniform1(context.Mesh.Attributes["color"] != null);
|
||||
Uniforms["occlude"].SetUniform1(context.ShaderArguments.ContainsKey("occluder"));
|
||||
|
||||
UniformArray instances = Uniforms.GetArray("Instances");
|
||||
for (int i = 0; i < context.Instances.Count; i++)
|
||||
|
|
|
|||
28
SMCode/SM2D/Shader/ShaderFiles/basic.glsl
Normal file
28
SMCode/SM2D/Shader/ShaderFiles/basic.glsl
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#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);
|
||||
}
|
||||
|
|
@ -17,13 +17,18 @@ void vmain() {
|
|||
in vec2 vTexture;
|
||||
in vec4 vColor;
|
||||
|
||||
uniform bool occlude;
|
||||
|
||||
uniform vec4 Tint;
|
||||
uniform bool UseTexture;
|
||||
uniform sampler2D Texture;
|
||||
|
||||
layout(location = 0) out vec4 color;
|
||||
layout(location = 1) out vec4 occluder;
|
||||
|
||||
void fmain() {
|
||||
color = vColor * Tint;
|
||||
if (UseTexture) color *= texture(Texture, vTexture);
|
||||
|
||||
occluder = vec4(occlude,0,0,1);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue