Improved PostProcessing System
This commit is contained in:
parent
0ab7f29b06
commit
e4e7db8dc0
10 changed files with 181 additions and 6 deletions
20
SMCode/SM2D/Light/LightPostEffect.cs
Normal file
20
SMCode/SM2D/Light/LightPostEffect.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
using System.Reflection;
|
||||
using SM.Base.PostProcess;
|
||||
using SM.Base.Scene;
|
||||
using SM.OGL.Framebuffer;
|
||||
using SM.Utility;
|
||||
|
||||
namespace SM2D.Light
|
||||
{
|
||||
public class LightPostEffect : PostProcessEffect
|
||||
{
|
||||
PostProcessShader _shader = new PostProcessShader(AssemblyUtility.ReadAssemblyFile("SM2D.Light.light.frag"));
|
||||
|
||||
public override void Draw(Framebuffer main)
|
||||
{
|
||||
base.Draw(main);
|
||||
|
||||
_shader.Draw(main.ColorAttachments["color"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
9
SMCode/SM2D/Light/LightSceneExtension.cs
Normal file
9
SMCode/SM2D/Light/LightSceneExtension.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
using OpenTK.Graphics;
|
||||
|
||||
namespace SM2D.Light
|
||||
{
|
||||
public class LightSceneExtension
|
||||
{
|
||||
public Color4 Ambient;
|
||||
}
|
||||
}
|
||||
13
SMCode/SM2D/Light/light.frag
Normal file
13
SMCode/SM2D/Light/light.frag
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#version 330
|
||||
|
||||
in vec2 vTexture;
|
||||
|
||||
vec4 GetRenderColor();
|
||||
|
||||
uniform vec4 Ambient = vec4(1);
|
||||
|
||||
layout(location = 0) out vec4 color;
|
||||
|
||||
void main() {
|
||||
color = GetRenderColor() * Ambient;
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ using SM.Base;
|
|||
using SM.Base.Contexts;
|
||||
using SM.Base.Scene;
|
||||
using SM.OGL.Framebuffer;
|
||||
using SM2D.Light;
|
||||
using SM2D.Shader;
|
||||
|
||||
#endregion
|
||||
|
|
@ -13,14 +14,32 @@ namespace SM2D.Pipelines
|
|||
{
|
||||
public class Basic2DPipeline : RenderPipeline<Scene.Scene>
|
||||
{
|
||||
private Framebuffer _tempWindow;
|
||||
private Light.LightPostEffect _lightEffect;
|
||||
|
||||
protected override void Initialization(GenericWindow window)
|
||||
{
|
||||
_tempWindow = CreateWindowFramebuffer();
|
||||
_lightEffect = new LightPostEffect();
|
||||
}
|
||||
|
||||
protected override void Render(ref DrawContext context, Scene.Scene scene)
|
||||
{
|
||||
base.Render(ref context, scene);
|
||||
|
||||
Framebuffer.Screen.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||
_tempWindow.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||
|
||||
scene?.Draw(context);
|
||||
if (scene != null)
|
||||
{
|
||||
scene.DrawBackground(context);
|
||||
|
||||
scene.DrawMainObjects(context);
|
||||
|
||||
Framebuffer.Screen.Activate(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||
_lightEffect.Draw(_tempWindow);
|
||||
|
||||
scene.DrawHUD(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -45,6 +45,8 @@
|
|||
<Compile Include="Drawing\DrawParticles.cs" />
|
||||
<Compile Include="Drawing\DrawText.cs" />
|
||||
<Compile Include="GLWindow2D.cs" />
|
||||
<Compile Include="Light\LightPostEffect.cs" />
|
||||
<Compile Include="Light\LightSceneExtension.cs" />
|
||||
<Compile Include="Object\Polygon.cs" />
|
||||
<Compile Include="Object\PolygonVertex.cs" />
|
||||
<Compile Include="Pipelines\Adv2DPipeline.cs" />
|
||||
|
|
@ -75,5 +77,8 @@
|
|||
<Version>3.2.1</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Light\light.frag" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
Loading…
Add table
Add a link
Reference in a new issue