本文整理汇总了C#中Microsoft.Xna.Framework.Graphics.Effect.Begin方法的典型用法代码示例。如果您正苦于以下问题:C# Effect.Begin方法的具体用法?C# Effect.Begin怎么用?C# Effect.Begin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Xna.Framework.Graphics.Effect
的用法示例。
在下文中一共展示了Effect.Begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: drawMe
public void drawMe(GraphicsDevice device, Effect effect)
{
if (mDecl == null)
{
mDecl = new VertexDeclaration(device, VertexPositionColor.VertexElements);
}
// update vert buffer.
for (int i = 0; i < mPointMasses.Count; i++)
{
mVerts[i].Position = JelloPhysics.VectorTools.vec3FromVec2(mPointMasses[i].Position);
float dist = (mPointMasses[i].Position - mGlobalShape[i]).Length() * 2.0f;
if (dist > 1f) { dist = 1f; }
mVerts[i].Color = mColor;
}
device.VertexDeclaration = mDecl;
// draw me!
effect.Begin();
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Begin();
device.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, mVerts, 0, mVerts.Length, mIndices, 0, mIndices.Length / 3);
pass.End();
}
effect.End();
}
示例2: Draw
/// <summary>
/// Draws the quad using the specified effect. Sets no parameters on the effect, nor any render states on
/// the graphics device. Those must be set appropriately before calling Draw.
/// This is a convenience function, calling Begin, End, and DrawGeometry for you.
/// </summary>
/// <param name="effect">The effect to draw with.</param>
public void Draw(Effect effect)
{
effect.Begin();
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Begin();
DrawGeometry();
pass.End();
}
effect.End();
}
示例3: RenderScreenQuad
public void RenderScreenQuad(Effect effect, EffectTechnique technique, Texture2D texture)
{
effect.CurrentTechnique = technique;
sb.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.None);
effect.Begin();
technique.Passes[0].Begin();
sb.Draw(texture, screen, Color.White);
technique.Passes[0].End();
effect.End();
sb.End();
}
示例4: Draw
public void Draw(Effect effect)
{
var device = GraphicsDeviceHolder.Device;
device.VertexDeclaration = vertexDeclaration;
device.Vertices[0].SetSource(vertexBuffer, 0, 3 * sizeof(float));
effect.Parameters["xWorld"].SetValue(Matrix.Identity);
effect.Begin();
foreach (var pass in effect.CurrentTechnique.Passes)
{
pass.Begin();
device.DrawPrimitives(PrimitiveType.LineList, 0, 2);
pass.End();
}
effect.End();
}
示例5: Draw
public void Draw(GameTime gameTime, GraphicsDevice device, Effect effect, Matrix worldViewProjectionMatrix, int resolutionWidth, int resolutionHeight)
{
effect.Parameters["xWorldViewProjection"].SetValue(worldViewProjectionMatrix);
effect.Parameters["xWidth"].SetValue(resolutionWidth);
effect.Parameters["xHeight"].SetValue(resolutionHeight);
effect.Begin();
foreach (SModelMesh mesh in _meshes)
{
effect.Parameters["xTexture"].SetValue(mesh.texture);
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Begin();
device.VertexDeclaration = _vertexDeclaration;
device.Vertices[0].SetSource(mesh.vertexBuffer, 0, _vertexSizeInBytes);
device.DrawPrimitives(PrimitiveType.TriangleList, 0, mesh.numPrimitives);
pass.End();
}
}
effect.End();
}
示例6: DrawFlags
void DrawFlags(Effect effectToUse, String technique)
{
GraphicsDevice device = parentGame.device;
//effectToUse = new BasicEffect(device, new EffectPool());
foreach (EventFlag flag in parentGame.myLevel.FlagsList)
{
currentColor.G -= 1;
VertexPositionColor[] pointList = new VertexPositionColor[5];
int x = 0;
#region Get Corners
foreach (Vector2 Crnr in flag.Corners)
{
Vector3 corner = new Vector3(Crnr.X, 0, Crnr.Y);
Vector3 norm;
parentGame.terrainEngine.GetHeight(corner, out corner.Y, out norm);
corner.Y += 2;
pointList[x] = new VertexPositionColor(corner, Color.Red);
if (x == 0)
{
pointList[4] = new VertexPositionColor(corner, Color.Red);
currentColor = Color.Red;
}
else
currentColor = Color.Chartreuse;
float scale = 0.05f;
if (activeFlag == flag
&& activeCorner == Crnr)
scale *= 1.5f;
parentGame.currentColor = Color.Brown;
parentGame.DrawModel(effectToUse, parentGame.cornerModel, parentGame.tankTextures,
Matrix.CreateScale(scale)
*
Matrix.Identity
*
Matrix.CreateTranslation(corner),
technique, true);
x++;
}
#endregion
short[] lineStripIndices = new short[5] { 0, 1, 2, 3, 4 };
device.RenderState.FillMode = FillMode.WireFrame;
device.RenderState.CullMode = CullMode.None;
effectToUse.Begin();
foreach (EffectPass pass in effectToUse.CurrentTechnique.Passes)
{
pass.Begin();
device.VertexDeclaration = new
VertexDeclaration(device,
VertexPositionColor.VertexElements);
device.DrawUserIndexedPrimitives<VertexPositionColor>(
PrimitiveType.LineStrip,
pointList,
0, // vertex buffer offset to add to each element of the index buffer
5, // number of vertices to draw
lineStripIndices,
0, // first index element to read
4 // number of primitives to draw
);
pass.End();
}
effectToUse.End();
//device.RenderState.FillMode = FillMode.Solid;
device.RenderState.FillMode = FillMode.Solid;
device.RenderState.CullMode = CullMode.CullClockwiseFace;
}
}
示例7: DrawSpawns
void DrawSpawns(Effect effectToUse, String technique)
{
GraphicsDevice device = parentGame.device;
foreach (EventFlag flag in parentGame.myLevel.FlagsList)
{
if (flag == activeFlag)
{
foreach (GameEvent g_event in flag.Events)
{
VertexPositionColor[] pointList = new VertexPositionColor[2];
#region Get Corners
Vector3 corner = g_event.SpawnPoint.Position;
Vector2 center = FindCenter2D(flag.Corners);
Vector3 Center = new Vector3(center.X, 0, center.Y);
Vector3 norm;
if(parentGame.terrainEngine.IsOnHeightmap(Center))
parentGame.terrainEngine.GetHeight(Center, out Center.Y, out norm);
pointList[0] = new VertexPositionColor(corner, Color.Red);
pointList[1] = new VertexPositionColor(Center, Color.Red);
float scale = 0.05f;
if (activeEvent == g_event)
scale *= 1.5f;
parentGame.currentColor = Color.GreenYellow;
parentGame.DrawModel(effectToUse, parentGame.cornerModel, parentGame.tankTextures,
Matrix.CreateScale(scale)
*
Matrix.Identity
*
Matrix.CreateTranslation(corner),
technique, true);
parentGame.currentColor = Color.Brown;
#endregion
#region draw lines
short[] lineStripIndices = new short[2] { 0, 1 };
device.RenderState.FillMode = FillMode.WireFrame;
device.RenderState.CullMode = CullMode.None;
effectToUse.Begin();
foreach (EffectPass pass in effectToUse.CurrentTechnique.Passes)
{
pass.Begin();
device.VertexDeclaration = new
VertexDeclaration(device,
VertexPositionColor.VertexElements);
device.DrawUserIndexedPrimitives<VertexPositionColor>(
PrimitiveType.LineStrip,
pointList,
0, // vertex buffer offset to add to each element of the index buffer
2, // number of vertices to draw
lineStripIndices,
0, // first index element to read
1 // number of primitives to draw
);
pass.End();
}
effectToUse.End();
//device.RenderState.FillMode = FillMode.Solid;
device.RenderState.FillMode = FillMode.Solid;
device.RenderState.CullMode = CullMode.CullClockwiseFace;
#endregion
}
}
}
}
示例8: DrawQuad
private void DrawQuad(Texture2D source, RenderTarget2D target, int x, int y, int width, int height, SpriteBlendMode spriteBlendMode, Effect effect, Color color)
{
graphics.GraphicsDevice.SetRenderTarget(0, target);
if (effect != null)
graphics.GraphicsDevice.Textures[0] = source;
// Draw a fullscreen sprite to apply the postprocessing effect.
spriteBatch.Begin(spriteBlendMode,
SpriteSortMode.Immediate,
SaveStateMode.SaveState);
if (effect != null)
{
effect.Begin();
effect.CurrentTechnique.Passes[0].Begin();
}
spriteBatch.Draw(source, new Rectangle(x, y, width, height), color);
spriteBatch.End();
if (effect != null)
{
effect.CurrentTechnique.Passes[0].End();
effect.End();
}
graphics.GraphicsDevice.SetRenderTarget(0, null);
}
示例9: renderPart
//method shadow effect render part
private void renderPart(GraphicsDevice device, List<SRenderInfoMesh> v_list, Matrix world, Effect shadow_effect)
{
shadow_effect.Begin();
shadow_effect.Parameters["xWorld"].SetValue(world);
for (int i = 0; i < v_list.Count; ++i)
{
VertexPositionNormalTexture[] vertices = v_list[i].vertex_info;
//model_effect.Texture = getTexture(v_list[i].texture_name);
foreach (EffectPass pass in shadow_effect.CurrentTechnique.Passes)
{
pass.Begin();
int count_primitives = vertices.Length / 3;
device.DrawUserPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList, vertices, 0, count_primitives);
pass.End();
}
}
shadow_effect.End();
}
示例10: DrawTerrain
private void DrawTerrain(Effect effect)
{
effect.Begin();
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Begin();
for (int i = 0; i < Patches.Count; ++i)
{
// Test the patch against frustum.
BoundingBox transformedBBox = Transform(Patches[i].BoundingBox, World);
if (Camera.Frustum.Contains(Patches[i].BoundingBox) != ContainmentType.Disjoint)
{
Patches[i].Draw();
++DrawnPatchCount;
}
}
pass.End();
}
effect.End();
}
示例11: DrawFullScreenQuad
public void DrawFullScreenQuad(SpriteBatch spriteBatch, Texture2D texture, Effect effect)
{
spriteBatch.Begin(SpriteBlendMode.None,
SpriteSortMode.Immediate, SaveStateMode.SaveState);
if (effect != null)
{
effect.Begin();
effect.CurrentTechnique.Passes[0].Begin();
}
// only render the viewport part
spriteBatch.Draw(texture, new Rectangle(0, 0,
DrawingManager.ViewPortSize.X, DrawingManager.ViewPortSize.Y),
new Rectangle(0, 0, DrawingManager.ViewPortSize.X, DrawingManager.ViewPortSize.Y),
Color.White);
if (effect != null)
{
effect.CurrentTechnique.Passes[0].End();
effect.End();
}
spriteBatch.End();
}
示例12: Draw
public void Draw(Effect effect,
string colorMapParamName,
string normalMapParamName,
string heightMapParamName,
Texture2D wallColorMap,
Texture2D wallNormalMap,
Texture2D wallHeightMap,
Texture2D floorColorMap,
Texture2D floorNormalMap,
Texture2D floorHeightMap,
Texture2D ceilingColorMap,
Texture2D ceilingNormalMap,
Texture2D ceilingHeightMap,
bool drawingCeiling)
{
graphicsDevice.VertexDeclaration = vertexDeclaration;
graphicsDevice.Vertices[0].SetSource(vertexBuffer, 0, NormalMappedVertex.SizeInBytes);
// Draw the scene geometry.
effect.Begin();
// Draw the walls.
effect.Parameters[colorMapParamName].SetValue(wallColorMap);
effect.Parameters[normalMapParamName].SetValue(wallNormalMap);
effect.Parameters[heightMapParamName].SetValue(wallHeightMap);
effect.CommitChanges();
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Begin();
graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, wallsIndex, 8);
pass.End();
}
if (drawingCeiling)
{
// Draw the ceiling.
effect.Parameters[colorMapParamName].SetValue(ceilingColorMap);
effect.Parameters[normalMapParamName].SetValue(ceilingNormalMap);
effect.Parameters[heightMapParamName].SetValue(ceilingHeightMap);
effect.CommitChanges();
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Begin();
graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, ceilingIndex, 2);
pass.End();
}
}
// Draw the floor.
effect.Parameters[colorMapParamName].SetValue(floorColorMap);
effect.Parameters[normalMapParamName].SetValue(floorNormalMap);
effect.Parameters[heightMapParamName].SetValue(floorHeightMap);
effect.CommitChanges();
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Begin();
graphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, floorIndex, 2);
pass.End();
}
effect.End();
}
示例13: Draw
/// <summary>
/// Отрисовывает объект
/// </summary>
/// <param name="effect">Эффект, который должен испльзоваться для отрисовки. Предполагается, что как минимум матрицы xProjection и xView уже заданы!</param>
public void Draw(Effect effect, Matrix worldMatrix, bool useMaterial)
{
GraphicsDevice device = vertexDeclaration.GraphicsDevice;
device.RenderState.CullMode = CullMode.None;
effect.Parameters["xWorld"].SetValue(worldMatrix);
device.VertexDeclaration = vertexDeclaration;
device.Vertices[0].SetSource(vertexBuffer, 0, vertexSize);
device.Indices = indexBuffer;
foreach (ModelMeshPart3D part in meshParts)
{
if (useMaterial)
{
Material mat = materials[part.MaterialId];
if (mat.Texture != null)
{
effect.CurrentTechnique = effect.Techniques["Textured"];
effect.Parameters["xTexture"].SetValue(mat.Texture);
}
else
{
effect.CurrentTechnique = effect.Techniques["SolidColored"];
effect.Parameters["xSolidColor"].SetValue(mat.Color.ToVector4());
}
}
effect.Begin();
foreach (var pass in effect.CurrentTechnique.Passes)
{
pass.Begin();
device.DrawIndexedPrimitives(triangleStrip ? PrimitiveType.TriangleStrip : PrimitiveType.TriangleList, 0, 0,
verticesCount, part.StartIdx, part.PrimitivesCount);
pass.End();
}
effect.End();
}
}
示例14: Draw
/// <summary>
/// Draws the tree mesh using a given effect.
/// You should set the proper parameters on the effect first, such as World, View, and Projection matrices.
/// </summary>
/// <param name="effect">Effect to draw with.</param>
public void Draw(Effect effect)
{
device.VertexDeclaration = vdeclaration;
device.Vertices[0].SetSource(vbuffer, 0, TreeVertex.SizeInBytes);
device.Indices = ibuffer;
effect.Begin();
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Begin();
device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, numvertices, 0, numtriangles);
pass.End();
}
effect.End();
}
示例15: Generate
//.........这里部分代码省略.........
uniform float4 _vs_c[11] : register(vs, c0);
{4}
technique Shader
{0}
pass
{0}
VertexShader =
asm
{0}
{2}
{1};
PixelShader =
asm
{0}
{3}
{1};
{1}
{1}",
"{", "}", vsAsm, psAsm, constantSetup);
}
else
{
string vsSource = vsConvert.GetSource();
string psSource = psConvert.GetSource();
//setup the technique.
techniqueCode = string.Format(
@"
{2}
{3}
technique Shader
{0}
pass
{0}
VertexShader = compile {4} vsMain();
PixelShader = compile {5} psMain();
{1}
{1}",
"{", "}", vsSource, psSource, vsConvert.GetProfile().ToString().ToLower(), psConvert.GetProfile().ToString().ToLower());
}
TargetPlatform target = TargetPlatform.Unknown;
switch (platform)
{
case Platform.Both:
throw new ArgumentException();
case Platform.Windows:
target = TargetPlatform.Windows;
break;
case Platform.Xbox:
target = TargetPlatform.Xbox360;
break;
}
CompiledEffect effectSource = Effect.CompileEffectFromSource(techniqueCode, null, null, CompilerOptions.None, target);
if (effectSource.Success == false)
Common.ThrowError(effectSource.ErrorsAndWarnings, techniqueCode);
byte[] code = effectSource.GetEffectCode();
Effect effect = new Effect(Graphics.GraphicsDevice, code, CompilerOptions.None, new EffectPool());
Vector4[] valuesV = new Vector4[11];
for (int i = 0; i < valuesV.Length; i++)
{
valuesV[i] = new Vector4(i,0,0,0);
}
//Vector4[] valuesP = new Vector4[24];
//for (int i = 0; i < valuesP.Length; i++)
//{
// valuesP[i] = new Vector4(0, i, 0, 0);
//}
effect.Parameters[0].SetValue(valuesV);
Vector4[] test = effect.Parameters[0].GetValueVector4Array(11);
//effect.Parameters[1].SetValue(valuesP);
//effect.Parameters[2].SetValue(new bool[] { false, false });
GraphicsDevice gd = Graphics.GraphicsDevice;
effect.CurrentTechnique = effect.Techniques[0];
effect.Begin();
effect.Techniques[0].Passes[0].Begin();
Vector4[] outputV = gd.GetVertexShaderVector4ArrayConstant(0, 255);
Vector4[] outputP = gd.GetPixelShaderVector4ArrayConstant(0, 24);
//bool[] outputPB = gd.GetPixelShaderBooleanConstant(0, 2);
effect.Techniques[0].Passes[0].End();
effect.End();
string asm = effect.Disassemble(false);
return code;
}