hi.
MyRenderTarget = new RenderTarget2D(graphicsDevice, mapSize, mapSize, true, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.DiscardContents);
NewRenderTarget = new RenderTarget2D(graphicsDevice, mapSize, mapSize, true, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.DiscardContents);
DepthStencilState writeStencil = new DepthStencilState()
{
StencilEnable = true,
DepthBufferEnable = false,
ReferenceStencil = 1,
StencilFunction = CompareFunction.Always,
StencilPass = StencilOperation.Replace,
};
DepthStencilState stencilMask = new DepthStencilState()
{
StencilEnable = true,
DepthBufferEnable = false,
ReferenceStencil = 0,
StencilFunction = CompareFunction.NotEqual,
StencilPass = StencilOperation.Keep,
};
graphicsDevice.SetRenderTarget(MyRenderTarget);
graphicsDevice.Clear(ClearOptions.DepthBuffer | ClearOptions.Stencil | ClearOptions.Target, Microsoft.Xna.Framework.Color.Black, 1.0f, 0);
graphicsDevice.DepthStencilState = writeStencil;
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
graphicsDevice.DrawUserIndexedPrimitives<Position4Texture>(PrimitiveType.TriangleList,
Vertices, 0, 4, Indices, 0, 2);
}
graphicsDevice.DepthStencilState = DepthStencilState.Default;
graphicsDevice.SetRenderTarget(NewRenderTarget);
graphicsDevice.Clear(ClearOptions.DepthBuffer | ClearOptions.Stencil | ClearOptions.Target, Microsoft.Xna.Framework.Color.Black, 1.0f, 0);
graphicsDevice.DepthStencilState = DepthStencilState.Default;
< DRAW TERRAIN TO NewRenderTarget >
graphicsDevice.DepthStencilState = stencilMask;
effect.Parameters["Texture"].SetValue(MyRenderTarget);
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
graphicsDevice.DrawUserIndexedPrimitives<Position4Texture>(PrimitiveType.TriangleList,
Vertices, 0, 4, Indices, 0, 2);
}
graphicsDevice.DepthStencilState = DepthStencilState.Default;
return = tex2D(Texture,input.TexCoord);