parent
d4d48ee21b
commit
05112d1e75
@ -275,21 +275,34 @@ namespace ANX.Framework.Windows.DX10
|
|||||||
|
|
||||||
public static ColorWriteMaskFlags Translate(ColorWriteChannels colorWriteChannels)
|
public static ColorWriteMaskFlags Translate(ColorWriteChannels colorWriteChannels)
|
||||||
{
|
{
|
||||||
switch (colorWriteChannels)
|
ColorWriteMaskFlags mask = 0;
|
||||||
|
|
||||||
|
if ((colorWriteChannels & ColorWriteChannels.All) == ColorWriteChannels.All)
|
||||||
{
|
{
|
||||||
case ColorWriteChannels.All:
|
mask |= ColorWriteMaskFlags.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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
public static SharpDX.Direct3D10.StencilOperation Translate(ANX.Framework.Graphics.StencilOperation stencilOperation)
|
||||||
|
@ -15,6 +15,7 @@ namespace StencilBuffer
|
|||||||
private Texture2D ground;
|
private Texture2D ground;
|
||||||
|
|
||||||
private SamplerState SamplerState;
|
private SamplerState SamplerState;
|
||||||
|
private DepthStencilState RenderGroundStencilState;
|
||||||
private DepthStencilState RenderObjectsStencilState;
|
private DepthStencilState RenderObjectsStencilState;
|
||||||
private DepthStencilState StencilStateRenderShadows;
|
private DepthStencilState StencilStateRenderShadows;
|
||||||
|
|
||||||
@ -75,24 +76,33 @@ namespace StencilBuffer
|
|||||||
Filter = TextureFilter.Linear,
|
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()
|
this.RenderObjectsStencilState = new DepthStencilState()
|
||||||
{
|
{
|
||||||
DepthBufferEnable = true,
|
DepthBufferEnable = true,
|
||||||
DepthBufferWriteEnable = true,
|
DepthBufferWriteEnable = true,
|
||||||
DepthBufferFunction = CompareFunction.Always,
|
DepthBufferFunction = CompareFunction.Always,
|
||||||
ReferenceStencil = 2,
|
ReferenceStencil = 1,
|
||||||
StencilEnable = true,
|
StencilEnable = false,
|
||||||
StencilPass = StencilOperation.Increment,
|
StencilPass = StencilOperation.Replace,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.StencilStateRenderShadows = new DepthStencilState
|
this.StencilStateRenderShadows = new DepthStencilState
|
||||||
{
|
{
|
||||||
DepthBufferEnable = true,
|
DepthBufferEnable = false,
|
||||||
DepthBufferWriteEnable = true,
|
|
||||||
DepthBufferFunction = CompareFunction.LessEqual,
|
|
||||||
ReferenceStencil = 1,
|
|
||||||
StencilEnable = true,
|
StencilEnable = true,
|
||||||
StencilPass = StencilOperation.Keep,
|
ReferenceStencil = 1,
|
||||||
|
StencilPass = StencilOperation.Increment,
|
||||||
|
StencilFunction = CompareFunction.LessEqual,
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -107,7 +117,7 @@ namespace StencilBuffer
|
|||||||
|
|
||||||
private void RenderGround()
|
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 y = 0; y < 2; y++)
|
||||||
{
|
{
|
||||||
for (int x = 0; x < 4; x++)
|
for (int x = 0; x < 4; x++)
|
||||||
@ -122,13 +132,13 @@ namespace StencilBuffer
|
|||||||
{
|
{
|
||||||
spriteBatch.Begin(SpriteSortMode.Texture, null, SamplerState, StencilStateRenderShadows, null);
|
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(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();
|
spriteBatch.End();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Draw(GameTime gameTime)
|
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();
|
RenderGround();
|
||||||
RenderShadows();
|
RenderShadows();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user