Added Ambient-Light
This commit is contained in:
parent
e4e7db8dc0
commit
597a14743b
7 changed files with 40 additions and 10 deletions
|
|
@ -66,10 +66,15 @@ namespace SM.Base.Scene
|
|||
/// <typeparam name="T"></typeparam>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public virtual T GetExtension<T>()
|
||||
public virtual T GetExtension<T>() where T : class
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -113,10 +113,10 @@ namespace SM.Base
|
|||
{
|
||||
_loading = false;
|
||||
|
||||
OnLoaded();
|
||||
|
||||
_actionsAfterLoading.ForEach(a => a());
|
||||
_actionsAfterLoading = null;
|
||||
|
||||
OnLoaded();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,13 +8,23 @@ namespace SM2D.Light
|
|||
{
|
||||
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)
|
||||
{
|
||||
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>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,8 @@ namespace SM2D.Light
|
|||
{
|
||||
public class LightSceneExtension
|
||||
{
|
||||
public Color4 Ambient;
|
||||
public Color4 Ambient = Color4.White;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -39,7 +39,14 @@ namespace SM2D.Pipelines
|
|||
_lightEffect.Draw(_tempWindow);
|
||||
|
||||
scene.DrawHUD(context);
|
||||
scene.DrawDebug(context);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SceneChanged(Scene.Scene scene)
|
||||
{
|
||||
base.SceneChanged(scene);
|
||||
_lightEffect.SceneChanged(scene);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ using SM.Base.Contexts;
|
|||
using SM.Base.Objects.Static;
|
||||
using SM.Base.Scene;
|
||||
using SM2D.Drawing;
|
||||
using SM2D.Light;
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -16,6 +17,7 @@ namespace SM2D.Scene
|
|||
private static DrawObject2D _axisHelper;
|
||||
|
||||
public float AxisHelperSize = 100;
|
||||
public LightSceneExtension LightInformations;
|
||||
static Scene()
|
||||
{
|
||||
_axisHelper = new DrawObject2D();
|
||||
|
|
@ -25,6 +27,8 @@ namespace SM2D.Scene
|
|||
public Scene()
|
||||
{
|
||||
_Background = new DrawBackground(Color4.Black);
|
||||
|
||||
SetExtension(LightInformations = new LightSceneExtension());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ namespace SM_TEST
|
|||
|
||||
private static void WindowOnLoad(object sender, EventArgs e)
|
||||
{
|
||||
//scene.ShowAxisHelper = true;
|
||||
scene.ShowAxisHelper = true;
|
||||
|
||||
kasten = new DrawObject2D();
|
||||
kasten.Texture = new Texture(new Bitmap("herosword.png"));
|
||||
|
|
@ -64,7 +64,9 @@ namespace SM_TEST
|
|||
|
||||
DrawText text = new DrawText(font, "Text");
|
||||
text.Transform.Position.Set(0, 500);
|
||||
scene.Objects.Add(text);
|
||||
scene.HUD.Add(text);
|
||||
|
||||
scene.LightInformations.Ambient = Color4.Blue;
|
||||
|
||||
//particles.Trigger();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue