本文整理汇总了C#中Microsoft.Xna.Framework.Graphics.DepthStencilState类的典型用法代码示例。如果您正苦于以下问题:C# DepthStencilState类的具体用法?C# DepthStencilState怎么用?C# DepthStencilState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DepthStencilState类属于Microsoft.Xna.Framework.Graphics命名空间,在下文中一共展示了DepthStencilState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
public void Draw(Matrix currentViewMatrix, Matrix currentProjection)
{
dsState = new DepthStencilState();
dsState.DepthBufferWriteEnable = false;
device.DepthStencilState = dsState;
Matrix[] modelTransforms = new Matrix[model.Bones.Count];
model.CopyAbsoluteBoneTransformsTo(modelTransforms);
Matrix wMatrix = Matrix.CreateTranslation(translation) * Matrix.CreateScale(scale); //* Matrix.CreateTranslation(theCamera.CamPos)
foreach (ModelMesh mesh in model.Meshes)
{
foreach (Effect currentEffect in mesh.Effects)
{
Matrix worldMatrix = modelTransforms[mesh.ParentBone.Index] * wMatrix;
currentEffect.CurrentTechnique = currentEffect.Techniques["Textured"];
currentEffect.Parameters["xWorld"].SetValue(worldMatrix);
currentEffect.Parameters["xView"].SetValue(currentViewMatrix);
currentEffect.Parameters["xProjection"].SetValue(currentProjection);
currentEffect.Parameters["xTexture1"].SetValue(texture);
currentEffect.Parameters["xEnableLighting"].SetValue(false);
}
mesh.Draw();
}
dsState = new DepthStencilState();
dsState.DepthBufferWriteEnable = true;
device.DepthStencilState = dsState;
}
示例2: DrawSkybox
private void DrawSkybox()
{
SamplerState ss = new SamplerState();
ss.AddressU = TextureAddressMode.Clamp;
ss.AddressV = TextureAddressMode.Clamp;
Engine.Video.GraphicsDevice.SamplerStates[0] = ss;
DepthStencilState dss = new DepthStencilState();
dss.DepthBufferEnable = false;
Engine.Video.GraphicsDevice.DepthStencilState = dss;
Matrix[] skyboxTransforms = new Matrix[skyboxModel.Bones.Count];
skyboxModel.CopyAbsoluteBoneTransformsTo(skyboxTransforms);
int i = 0;
foreach(ModelMesh mesh in skyboxModel.Meshes) {
foreach(Effect currentEffect in mesh.Effects) {
Matrix worldMatrix = skyboxTransforms[mesh.ParentBone.Index];
currentEffect.CurrentTechnique = currentEffect.Techniques["Textured"];
currentEffect.Parameters["xWorld"].SetValue(worldMatrix);
currentEffect.Parameters["xView"].SetValue(camera.ViewMatrix);
currentEffect.Parameters["xProjection"].SetValue(camera.ProjectionMatrix);
currentEffect.Parameters["xTexture"].SetValue(skyboxTextures[i++]);
}
mesh.Draw();
}
dss = new DepthStencilState();
dss.DepthBufferEnable = true;
Engine.Video.GraphicsDevice.DepthStencilState = dss;
}
示例3: Draw
public override void Draw(GameTime gameTime)
{
DepthStencilState s = new DepthStencilState();
s.DepthBufferWriteEnable = false;
DepthStencilState bak = device.DepthStencilState;
device.DepthStencilState = s;
device.RasterizerState = new RasterizerState() { CullMode = CullMode.None, FillMode = FillMode.Solid };
Matrix wMatrix = Matrix.CreateScale(scale) * Matrix.CreateTranslation(cameraPosition);
effect.CurrentTechnique = effect.Techniques["SkyBox"];
effect.Parameters["xView"].SetValue(viewMatrix);
effect.Parameters["xProjection"].SetValue(projectionMatrix);
effect.Parameters["xWorld"].SetValue(wMatrix);
effect.Parameters["xCamPos"].SetValue(cameraPosition);
effect.Parameters["xSkyBoxTexture"].SetValue(cloudMap);
effect.Parameters["xEnableLighting"].SetValue(false);
effect.Parameters["xClipping"].SetValue(false);
effect.Parameters["xTexture"].SetValue(Tools.Quick.biomeTextures[1]);
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
device.SetVertexBuffer(vertexBuffer);
device.Indices = indexBuffer;
device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, indexBuffer.IndexCount, 0, indexBuffer.IndexCount / 3);
}
device.DepthStencilState = bak;
base.Draw(gameTime);
}
示例4: draw
public void draw(Matrix view, Matrix projection, Vector3 playerPosition)
{
SamplerState samplerState = new SamplerState();
samplerState.AddressU = TextureAddressMode.Clamp;
samplerState.AddressV = TextureAddressMode.Clamp;
Game1.getGraphics().GraphicsDevice.SamplerStates[0] = samplerState;
DepthStencilState dss = new DepthStencilState();
dss.DepthBufferEnable = false;
Game1.getGraphics().GraphicsDevice.DepthStencilState = dss;
Matrix[] skyboxTransforms = new Matrix[skyboxModel.Bones.Count];
skyboxModel.CopyAbsoluteBoneTransformsTo(skyboxTransforms);
foreach (ModelMesh mesh in skyboxModel.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
Matrix worldMatrix = skyboxTransforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(playerPosition);
//effect.CurrentTechnique = effect.Techniques["Textured"];
effect.LightingEnabled = true;
effect.AmbientLightColor = new Vector3(1f, 1f, 1f);
effect.EmissiveColor = new Vector3(0.4f, 0.4f, 0.4f);
effect.TextureEnabled = true;
effect.Texture = skyboxTextures;
effect.World = worldMatrix;
effect.View = view;
effect.Projection = projection;
}
mesh.Draw();
}
dss = new DepthStencilState();
dss.DepthBufferEnable = true;
Game1.getGraphics().GraphicsDevice.DepthStencilState = dss;
}
示例5: Draw
/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
renderer.matrix = Matrix.CreateTranslation(0, 0, 0);
GraphicsDevice.Clear(Color.Black);
Vector3 cameraPosition = new Vector3(0, 0, 2.5f);
cameraPosition.Y -= .01f;
if (target == null)
{
//Uncomment for depth correction; but blurry pictures
//target = new RenderTarget2D(GraphicsDevice, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight,false,SurfaceFormat.Rgba64,DepthFormat.Depth24);
target = new RenderTarget2D(GraphicsDevice, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight);
} RasterizerState tstate = new RasterizerState();
tstate.CullMode = CullMode.None;
DepthStencilState lstate = new DepthStencilState();
GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp;
lstate.DepthBufferEnable = true;
GraphicsDevice.DepthStencilState = lstate;
GraphicsDevice.RasterizerState = tstate;
if (!renderer.NtfyReadyRender(GraphicsDevice))
{
renderer.NtfyReadyRender(GraphicsDevice);
}
base.Draw(gameTime);
}
示例6: RenderManager
internal RenderManager(GraphicsDevice device)
{
Skins = new Dictionary<string, Skin>();
Texts = new Dictionary<string, Text>();
ApplyStencil = new DepthStencilState {
StencilEnable = true,
StencilFunction = CompareFunction.Always,
StencilPass = StencilOperation.Replace,
ReferenceStencil = 1,
DepthBufferEnable = false,
};
SampleStencil = new DepthStencilState {
StencilEnable = true,
StencilFunction = CompareFunction.Equal,
StencilPass = StencilOperation.Keep,
ReferenceStencil = 1,
DepthBufferEnable = false,
};
GraphicsDevice = device;
RasterizerState = new RasterizerState { ScissorTestEnable = true };
SpriteBatch = new SpriteBatch(GraphicsDevice);
}
示例7: Draw
Texture2D[] skyboxTextures; // textures to display around the skybox
#endregion Fields
#region Methods
/// <summary>
/// Draw the skybox to the screen.
/// </summary>
/// <param name="device"></param>
/// <param name="gameCamera">Used to get the view and projection matrices</param>
/// <param name="player">The player's position governs where the skybox is drawn</param>
public void Draw(ref GraphicsDevice device, Camera gameCamera, Player player)
{
device.SamplerStates[0] = clampTextureAddressMode;
DepthStencilState dss = new DepthStencilState();
dss.DepthBufferEnable = false;
device.DepthStencilState = dss;
Matrix[] skyboxTransforms = new Matrix[skyboxModel.Bones.Count];
skyboxModel.CopyAbsoluteBoneTransformsTo(skyboxTransforms);
int i = 0;
foreach (ModelMesh mesh in skyboxModel.Meshes)
{
foreach (Effect currentEffect in mesh.Effects)
{
Matrix worldMatrix = skyboxTransforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(player.Position);
currentEffect.CurrentTechnique = currentEffect.Techniques["Textured"];
currentEffect.Parameters["xWorld"].SetValue(worldMatrix);
currentEffect.Parameters["xView"].SetValue(gameCamera.ViewMatrix);
currentEffect.Parameters["xProjection"].SetValue(gameCamera.ProjectionMatrix);
currentEffect.Parameters["xTexture"].SetValue(skyboxTextures[i++]);
}
mesh.Draw();
}
dss = new DepthStencilState();
dss.DepthBufferEnable = true;
device.DepthStencilState = dss;
}
示例8: EffectState
public EffectState(Effect effect, SamplerState sampler, RasterizerState raster, DepthStencilState stencil, bool texture)
{
Effect = effect;
Sampler = sampler;
Raster = raster;
TextureOverride = texture;
}
示例9: ImperativeRenderer
public ImperativeRenderer(
IBatchContainer container,
DefaultMaterialSet materials,
int layer = 0,
RasterizerState rasterizerState = null,
DepthStencilState depthStencilState = null,
BlendState blendState = null,
SamplerState samplerState = null,
bool worldSpace = true,
bool useZBuffer = false,
bool autoIncrementSortKey = false,
bool autoIncrementLayer = false
)
{
if (container == null)
throw new ArgumentNullException("container");
if (materials == null)
throw new ArgumentNullException("materials");
Container = container;
Materials = materials;
Layer = layer;
RasterizerState = rasterizerState;
DepthStencilState = depthStencilState;
BlendState = blendState;
SamplerState = samplerState;
UseZBuffer = useZBuffer;
WorldSpace = worldSpace;
AutoIncrementSortKey = autoIncrementSortKey;
AutoIncrementLayer = autoIncrementLayer;
NextSortKey = 0;
PreviousBatch = null;
}
示例10: Initialize
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here
input = new Input();
GraphicsDevice.BlendState = BlendState.AlphaBlend;
dpsLockDepthWrite = new DepthStencilState();
dpsLockDepthWrite.DepthBufferWriteEnable = false;
DepthStencilState dpsUnLockDepthWrite = new DepthStencilState();
dpsUnLockDepthWrite.DepthBufferWriteEnable = true;
//graphics.PreferredBackBufferWidth = 1280;
//graphics.PreferredBackBufferHeight = 720;
//b = new Bat(-11f, Vector3.UnitZ, Vector3.Up, 0.9f, 0.9f, 0.9f, Color.Gray, graphics);
myCamera = new CameraComponent(graphics);
//model = new GameModel(this, Content, myCamera, Matrix.Identity, e, "box");
//Components.Add(model);
float width = 2.0f;
float height = 1.2f;
tunnel = new Tunnel(this, graphics, myCamera, Content, 1, 15, Vector3.Zero, Vector3.Backward, Vector3.Up, width, height);
frontBat = new Bat(-2.0f, Vector3.Backward, Vector3.Up, .2f, .2f, Color.Red, myCamera, graphics, width, height);
backBat = new Bat(-15.0f, Vector3.Backward, Vector3.Up, .2f, .2f, Color.Green, myCamera, graphics, width, height);
Components.Add(tunnel);
base.Initialize();
}
示例11: DrawSkybox
public void DrawSkybox(Camera camera, Vector3 shipPosition)
{
//A TextureAddressMode.Clamp state removes the seams between the cube.
SamplerState ss = new SamplerState();
ss.AddressU = TextureAddressMode.Clamp;
ss.AddressV = TextureAddressMode.Clamp;
_device.SamplerStates[0] = ss;
//Removes the ZBuffer so no size can be set for the skybox.
DepthStencilState dss = new DepthStencilState();
dss.DepthBufferEnable = false;
_device.DepthStencilState = dss;
Matrix[] transforms = new Matrix[_skyboxModel.Bones.Count]; //Represents the position of each model bone.
_skyboxModel.CopyAbsoluteBoneTransformsTo(transforms); //Models have a method that populates an array.
foreach (ModelMesh mesh in _skyboxModel.Meshes)
{
//BasicEffect is a simplified version of it's parent class Effect. Effects allow objects to be placed on screen.
foreach (BasicEffect basicEffect in mesh.Effects)
{
basicEffect.Projection = camera.Projection;
basicEffect.View = camera.View;
basicEffect.World = Matrix.CreateScale(80) * mesh.ParentBone.Transform * Matrix.CreateTranslation(shipPosition); //Positions the mesh in the correct place relavent to the world.
}
mesh.Draw();
}
//Reenabling the ZBuffer.
dss = new DepthStencilState();
dss.DepthBufferEnable = true;
_device.DepthStencilState = dss;
}
示例12: EffectApplication
static EffectApplication()
{
sDSStateSky = new DepthStencilState();
sDSStateSky.DepthBufferFunction = CompareFunction.LessEqual;
sRenderStateBlendStateMap = new Dictionary<RenderStatePresets, BlendState>();
sRenderStateBlendStateMap.Add(RenderStatePresets.Default, BlendState.Opaque);
sRenderStateBlendStateMap.Add(RenderStatePresets.AlphaAdd, BlendState.Additive);
sRenderStateBlendStateMap.Add(RenderStatePresets.AlphaBlend, BlendState.AlphaBlend);
sRenderStateBlendStateMap.Add(RenderStatePresets.AlphaBlendNPM, BlendState.NonPremultiplied);
sRenderStateBlendStateMap.Add(RenderStatePresets.Skybox, BlendState.Opaque);
sRenderStateDepthStencilStateMap = new Dictionary<RenderStatePresets, DepthStencilState>();
sRenderStateDepthStencilStateMap.Add(RenderStatePresets.Default, DepthStencilState.Default);
sRenderStateDepthStencilStateMap.Add(RenderStatePresets.AlphaAdd, DepthStencilState.DepthRead);
sRenderStateDepthStencilStateMap.Add(RenderStatePresets.AlphaBlend, DepthStencilState.DepthRead);
sRenderStateDepthStencilStateMap.Add(RenderStatePresets.AlphaBlendNPM, DepthStencilState.DepthRead);
sRenderStateDepthStencilStateMap.Add(RenderStatePresets.Skybox, sDSStateSky);
sRenderStateRasterizerStateMap = new Dictionary<RenderStatePresets, RasterizerState>();
sRenderStateRasterizerStateMap.Add(RenderStatePresets.Default, RasterizerState.CullCounterClockwise);
sRenderStateRasterizerStateMap.Add(RenderStatePresets.AlphaAdd, RasterizerState.CullNone);
sRenderStateRasterizerStateMap.Add(RenderStatePresets.AlphaBlend, RasterizerState.CullCounterClockwise);
sRenderStateRasterizerStateMap.Add(RenderStatePresets.AlphaBlendNPM, RasterizerState.CullCounterClockwise);
sRenderStateRasterizerStateMap.Add(RenderStatePresets.Skybox, RasterizerState.CullNone);
sRenderStateAlphaPassMap = new Dictionary<RenderStatePresets, bool>();
sRenderStateAlphaPassMap.Add(RenderStatePresets.Default, false);
sRenderStateAlphaPassMap.Add(RenderStatePresets.AlphaAdd, true);
sRenderStateAlphaPassMap.Add(RenderStatePresets.AlphaBlend, true);
sRenderStateAlphaPassMap.Add(RenderStatePresets.AlphaBlendNPM, true);
sRenderStateAlphaPassMap.Add(RenderStatePresets.Skybox, false);
}
示例13: CreateInstancedRequest
public IRenderRequest CreateInstancedRequest(IRenderContext renderContext, RasterizerState rasterizerState,
BlendState blendState, DepthStencilState depthStencilState, IEffect effect, IEffectParameterSet effectParameterSet,
VertexBuffer meshVertexBuffer, IndexBuffer meshIndexBuffer, PrimitiveType primitiveType,
Matrix[] instanceWorldTransforms, Action<List<Matrix>, VertexBuffer, IndexBuffer> computeCombinedBuffers)
{
throw new NotImplementedException();
}
示例14: Draw
/// <summary>
/// Does the actual drawing of the skybox with our skybox effect.
/// There is no world matrix, because we're assuming the skybox won't
/// be moved around. The size of the skybox can be changed with the size
/// variable.
/// </summary>
/// <param name="view">The view matrix for the effect</param>
/// <param name="projection">The projection matrix for the effect</param>
/// <param name="cameraPosition">The position of the camera</param>
public override void Draw(GameTime gameTime)
{
GraphicsDevice device = game.GraphicsDevice;
SamplerState ss = new SamplerState();
ss.AddressU = TextureAddressMode.Clamp;
ss.AddressV = TextureAddressMode.Clamp;
device.SamplerStates[0] = ss;
DepthStencilState dss = new DepthStencilState();
dss.DepthBufferEnable = false;
device.DepthStencilState = dss;
Matrix[] skyboxTransforms = new Matrix[skyboxModel.Bones.Count];
skyboxModel.CopyAbsoluteBoneTransformsTo(skyboxTransforms);
int i = 0;
foreach (ModelMesh mesh in skyboxModel.Meshes)
{
foreach (BasicEffect currentEffect in mesh.Effects)
{
Matrix worldMatrix = skyboxTransforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(camera.position);
currentEffect.World = worldMatrix;
currentEffect.View = camera.view;
currentEffect.Projection = camera.projection;
currentEffect.TextureEnabled=true;
currentEffect.Texture = skyboxTextures[i++];
}
mesh.Draw();
}
dss = new DepthStencilState();
dss.DepthBufferEnable = true;
device.DepthStencilState = dss;
}
示例15: Score
public Score(PuzzleBooble3dGame puzzlegame)
: base(puzzlegame)
{
DepthStateEnabled = new DepthStencilState();
DepthStateEnabled.DepthBufferEnable = true; /* Enable the depth buffer */
//depthState.DepthBufferWriteEnable = true; /* When drawing to the screen, write to the depth buffer */
}