Skip to content

Commit

Permalink
Deferred Shading #5
Browse files Browse the repository at this point in the history
  • Loading branch information
Selinux24 committed Aug 15, 2015
1 parent 4e3aca8 commit 53c275f
Show file tree
Hide file tree
Showing 11 changed files with 534 additions and 131 deletions.
55 changes: 43 additions & 12 deletions 7 Deferred/TestScene3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ namespace DeferredTest
{
public class TestScene3D : Scene
{
private Random rnd = new Random();

private TextDrawer title = null;
private TextDrawer load = null;
private TextDrawer help = null;
Expand All @@ -20,6 +18,7 @@ public class TestScene3D : Scene
private Terrain terrain = null;

private SpriteTexture bufferDrawer = null;
private int textIntex = 0;

public TestScene3D(Game game)
: base(game, SceneModesEnum.DeferredLightning)
Expand Down Expand Up @@ -295,7 +294,7 @@ public override void Update(GameTime gameTime)
}
else
{
//Shadows
//Shadow factor map
this.bufferDrawer.Texture = this.DrawContext.GeometryMap[1];
this.bufferDrawer.Channels = SpriteTextureChannelsEnum.Alpha;
}
Expand All @@ -305,18 +304,18 @@ public override void Update(GameTime gameTime)
if (this.Game.Input.KeyJustReleased(Keys.F3))
{
if (this.bufferDrawer.Texture == this.DrawContext.GeometryMap[2] &&
this.bufferDrawer.Channels == SpriteTextureChannelsEnum.NoAlpha)
this.bufferDrawer.Channels == SpriteTextureChannelsEnum.Alpha)
{
//Depth
//Position
this.bufferDrawer.Texture = this.DrawContext.GeometryMap[2];
this.bufferDrawer.Channels = SpriteTextureChannelsEnum.Alpha;
this.bufferDrawer.Channels = SpriteTextureChannelsEnum.NoAlpha;
this.bufferDrawer.Visible = true;
}
else
{
//Position
//Depth
this.bufferDrawer.Texture = this.DrawContext.GeometryMap[2];
this.bufferDrawer.Channels = SpriteTextureChannelsEnum.NoAlpha;
this.bufferDrawer.Channels = SpriteTextureChannelsEnum.Alpha;
this.bufferDrawer.Visible = true;
}
}
Expand All @@ -326,16 +325,29 @@ public override void Update(GameTime gameTime)
{
if (this.Game.Input.KeyJustReleased(Keys.F4))
{
this.bufferDrawer.Texture = this.DrawContext.LightMap;
this.bufferDrawer.Channels = SpriteTextureChannelsEnum.All;
this.bufferDrawer.Visible = true;
if (this.bufferDrawer.Texture == this.DrawContext.LightMap &&
this.bufferDrawer.Channels == SpriteTextureChannelsEnum.Alpha)
{
//Light map
this.bufferDrawer.Texture = this.DrawContext.LightMap;
this.bufferDrawer.Channels = SpriteTextureChannelsEnum.NoAlpha;
this.bufferDrawer.Visible = true;
}
else
{
//Specular map
this.bufferDrawer.Texture = this.DrawContext.LightMap;
this.bufferDrawer.Channels = SpriteTextureChannelsEnum.Alpha;
this.bufferDrawer.Visible = true;
}
}
}

if (this.DrawContext.ShadowMap != null)
{
if (this.Game.Input.KeyJustReleased(Keys.F5))
{
//Shadow map
this.bufferDrawer.Texture = this.DrawContext.ShadowMap;
this.bufferDrawer.Channels = SpriteTextureChannelsEnum.Red;
this.bufferDrawer.Visible = true;
Expand Down Expand Up @@ -367,6 +379,18 @@ public override void Update(GameTime gameTime)
this.helicopters.Visible = !this.helicopters.Visible;
}

if (this.Game.Input.KeyJustReleased(Keys.D1))
{
this.textIntex = this.textIntex > 0 ? this.textIntex - 1 : 0;
}

if (this.Game.Input.KeyJustReleased(Keys.D2))
{
int max = (this.DebugText != null ? this.DebugText.Length : 0) - 1;

this.textIntex = this.textIntex < max ? this.textIntex + 1 : max;
}

#endregion

#region Tank
Expand Down Expand Up @@ -431,7 +455,7 @@ public override void Update(GameTime gameTime)

#endregion

#region Light
#region Lights

if (this.Game.Input.KeyPressed(Keys.Left))
{
Expand Down Expand Up @@ -473,12 +497,19 @@ public override void Update(GameTime gameTime)
this.Lights.PointLights[0].Range -= 0.1f;
}

if (this.Game.Input.KeyJustReleased(Keys.Space))
{
this.Lights.EnableShadows = !this.Lights.EnableShadows;
}

#endregion

if (this.Game.Form.IsFullscreen)
{
this.load.Text = this.Game.RuntimeText;
}

this.help.Text = this.DebugText != null && this.DebugText.Length > textIntex ? this.DebugText[textIntex] : null;
}

public override void Draw(GameTime gameTime)
Expand Down
6 changes: 6 additions & 0 deletions Engine/DeferredRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ public void DrawLights(Context context)

var effect = DrawerPool.EffectDeferred;

this.Game.Graphics.SetBlendAlphaToCoverage();

#region Directional Lights

{
Expand Down Expand Up @@ -227,6 +229,8 @@ public void DrawLights(Context context)

#endregion

this.Game.Graphics.SetBlendAdditive();

#region Point Lights

{
Expand Down Expand Up @@ -333,6 +337,8 @@ public void DrawLights(Context context)

#endregion

this.Game.Graphics.SetBlendAlphaToCoverage();

this.Game.Graphics.SetCullCounterClockwiseFaceRasterizer();
}
/// <summary>
Expand Down

0 comments on commit 53c275f

Please sign in to comment.