fixed issue #468

finished issue #465
This commit is contained in:
Glatzemann 2011-11-30 06:59:32 +00:00
parent d4d48ee21b
commit 05112d1e75
2 changed files with 46 additions and 23 deletions

View File

@ -275,21 +275,34 @@ namespace ANX.Framework.Windows.DX10
public static ColorWriteMaskFlags Translate(ColorWriteChannels colorWriteChannels)
{
switch (colorWriteChannels)
ColorWriteMaskFlags mask = 0;
if ((colorWriteChannels & ColorWriteChannels.All) == ColorWriteChannels.All)
{
case ColorWriteChannels.All:
return ColorWriteMaskFlags.All;
case ColorWriteChannels.Alpha:
return ColorWriteMaskFlags.Alpha;
case ColorWriteChannels.Blue:
return ColorWriteMaskFlags.Blue;
case ColorWriteChannels.Green:
return ColorWriteMaskFlags.Green;
case ColorWriteChannels.Red:
return ColorWriteMaskFlags.Red;
mask |= ColorWriteMaskFlags.All;
}
throw new NotImplementedException();
if ((colorWriteChannels & ColorWriteChannels.Alpha) == ColorWriteChannels.Alpha)
{
mask |= ColorWriteMaskFlags.Alpha;
}
if ((colorWriteChannels & ColorWriteChannels.Blue) == ColorWriteChannels.Blue)
{
mask |= ColorWriteMaskFlags.Blue;
}
if ((colorWriteChannels & ColorWriteChannels.Green) == ColorWriteChannels.Green)
{
mask |= ColorWriteMaskFlags.Green;
}
if ((colorWriteChannels & ColorWriteChannels.Red) == ColorWriteChannels.Red)
{
mask |= ColorWriteMaskFlags.Red;
}
return mask;
}
public static SharpDX.Direct3D10.StencilOperation Translate(ANX.Framework.Graphics.StencilOperation stencilOperation)

View File

@ -15,6 +15,7 @@ namespace StencilBuffer
private Texture2D ground;
private SamplerState SamplerState;
private DepthStencilState RenderGroundStencilState;
private DepthStencilState RenderObjectsStencilState;
private DepthStencilState StencilStateRenderShadows;
@ -75,24 +76,33 @@ namespace StencilBuffer
Filter = TextureFilter.Linear,
};
this.RenderGroundStencilState = new DepthStencilState()
{
DepthBufferEnable = false,
DepthBufferWriteEnable = false,
StencilEnable = true,
ReferenceStencil = 1,
StencilPass = StencilOperation.Replace,
StencilFunction = CompareFunction.Always,
};
this.RenderObjectsStencilState = new DepthStencilState()
{
DepthBufferEnable = true,
DepthBufferWriteEnable = true,
DepthBufferFunction = CompareFunction.Always,
ReferenceStencil = 2,
StencilEnable = true,
StencilPass = StencilOperation.Increment,
ReferenceStencil = 1,
StencilEnable = false,
StencilPass = StencilOperation.Replace,
};
this.StencilStateRenderShadows = new DepthStencilState
{
DepthBufferEnable = true,
DepthBufferWriteEnable = true,
DepthBufferFunction = CompareFunction.LessEqual,
ReferenceStencil = 1,
DepthBufferEnable = false,
StencilEnable = true,
StencilPass = StencilOperation.Keep,
ReferenceStencil = 1,
StencilPass = StencilOperation.Increment,
StencilFunction = CompareFunction.LessEqual,
};
}
@ -107,7 +117,7 @@ namespace StencilBuffer
private void RenderGround()
{
spriteBatch.Begin(SpriteSortMode.Texture, null, SamplerState, RenderObjectsStencilState, null);
spriteBatch.Begin(SpriteSortMode.Texture, null, SamplerState, RenderGroundStencilState, null);
for (int y = 0; y < 2; y++)
{
for (int x = 0; x < 4; x++)
@ -122,13 +132,13 @@ namespace StencilBuffer
{
spriteBatch.Begin(SpriteSortMode.Texture, null, SamplerState, StencilStateRenderShadows, null);
spriteBatch.Draw(crate, new Vector2(125, 125), new Color(0, 0, 0, 0.5f));
spriteBatch.Draw(crate, new Vector2(10, 10), new Color(0, 0, 0, 0.5f));
spriteBatch.Draw(crate, new Vector2(20, 20), new Color(0, 0, 0, 0.5f));
spriteBatch.End();
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.Stencil, Color.CornflowerBlue, 1.0f, 2);
GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.Stencil, Color.CornflowerBlue, 1.0f, 0);
RenderGround();
RenderShadows();