Added Ambient-Light

This commit is contained in:
Michel Fedde 2020-12-13 16:30:57 +01:00
parent e4e7db8dc0
commit 597a14743b
7 changed files with 40 additions and 10 deletions

View file

@ -66,10 +66,15 @@ namespace SM.Base.Scene
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <returns></returns> /// <returns></returns>
/// <exception cref="Exception"></exception> /// <exception cref="Exception"></exception>
public virtual T GetExtension<T>() public virtual T GetExtension<T>() where T : class
{ {
object ext = _extensions[typeof(T)]; object ext = _extensions[typeof(T)];
if (ext == null) throw new Exception("[Error] Tried to get a extension, that doesn't exist."); if (ext == null)
{
Log.Write(LogType.Warning, $"Tried to get the extension '{typeof(T).Name}', that doesn't exist in the scene.");
return null;
}
return (T)ext; return (T)ext;
} }

View file

@ -113,10 +113,10 @@ namespace SM.Base
{ {
_loading = false; _loading = false;
OnLoaded();
_actionsAfterLoading.ForEach(a => a()); _actionsAfterLoading.ForEach(a => a());
_actionsAfterLoading = null; _actionsAfterLoading = null;
OnLoaded();
} }
} }

View file

@ -8,13 +8,23 @@ namespace SM2D.Light
{ {
public class LightPostEffect : PostProcessEffect public class LightPostEffect : PostProcessEffect
{ {
PostProcessShader _shader = new PostProcessShader(AssemblyUtility.ReadAssemblyFile("SM2D.Light.light.frag")); private PostProcessShader _shader = new PostProcessShader(AssemblyUtility.ReadAssemblyFile("SM2D.Light.light.frag"));
private LightSceneExtension sceneExtension;
public override void Draw(Framebuffer main) public override void Draw(Framebuffer main)
{ {
base.Draw(main); base.Draw(main);
_shader.Draw(main.ColorAttachments["color"]); _shader.Draw(main.ColorAttachments["color"], collection =>
{
collection["Ambient"].SetUniform4(sceneExtension.Ambient);
});
}
public override void SceneChanged(GenericScene scene)
{
base.SceneChanged(scene);
sceneExtension = scene.GetExtension<LightSceneExtension>();
} }
} }
} }

View file

@ -4,6 +4,8 @@ namespace SM2D.Light
{ {
public class LightSceneExtension public class LightSceneExtension
{ {
public Color4 Ambient; public Color4 Ambient = Color4.White;
} }
} }

View file

@ -39,7 +39,14 @@ namespace SM2D.Pipelines
_lightEffect.Draw(_tempWindow); _lightEffect.Draw(_tempWindow);
scene.DrawHUD(context); scene.DrawHUD(context);
scene.DrawDebug(context);
} }
} }
protected override void SceneChanged(Scene.Scene scene)
{
base.SceneChanged(scene);
_lightEffect.SceneChanged(scene);
}
} }
} }

View file

@ -6,6 +6,7 @@ using SM.Base.Contexts;
using SM.Base.Objects.Static; using SM.Base.Objects.Static;
using SM.Base.Scene; using SM.Base.Scene;
using SM2D.Drawing; using SM2D.Drawing;
using SM2D.Light;
#endregion #endregion
@ -16,6 +17,7 @@ namespace SM2D.Scene
private static DrawObject2D _axisHelper; private static DrawObject2D _axisHelper;
public float AxisHelperSize = 100; public float AxisHelperSize = 100;
public LightSceneExtension LightInformations;
static Scene() static Scene()
{ {
_axisHelper = new DrawObject2D(); _axisHelper = new DrawObject2D();
@ -25,6 +27,8 @@ namespace SM2D.Scene
public Scene() public Scene()
{ {
_Background = new DrawBackground(Color4.Black); _Background = new DrawBackground(Color4.Black);
SetExtension(LightInformations = new LightSceneExtension());
} }

View file

@ -55,7 +55,7 @@ namespace SM_TEST
private static void WindowOnLoad(object sender, EventArgs e) private static void WindowOnLoad(object sender, EventArgs e)
{ {
//scene.ShowAxisHelper = true; scene.ShowAxisHelper = true;
kasten = new DrawObject2D(); kasten = new DrawObject2D();
kasten.Texture = new Texture(new Bitmap("herosword.png")); kasten.Texture = new Texture(new Bitmap("herosword.png"));
@ -64,7 +64,9 @@ namespace SM_TEST
DrawText text = new DrawText(font, "Text"); DrawText text = new DrawText(font, "Text");
text.Transform.Position.Set(0, 500); text.Transform.Position.Set(0, 500);
scene.Objects.Add(text); scene.HUD.Add(text);
scene.LightInformations.Ambient = Color4.Blue;
//particles.Trigger(); //particles.Trigger();
} }