[PR]
×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
プログラミング、3DCGとその他いろいろについて
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
float4x4 View; float4x4 Projection; float Time; texture ExplosionTexture; sampler explosionSampler = sampler_state { Texture = <ExplosionTexture>; }; struct ExplosionVertexShaderOutput { float4 Position : POSITION; float4 Color : COLOR; }; float4 ComputeColor(float normalizedAge) { float4 color = 1; color.a *= normalizedAge * (1 - normalizedAge) * (1 - normalizedAge) * 6.7; return color; } ExplosionVertexShaderOutput ExplosionVertexShader(float4 velocity:COLOR) { ExplosionVertexShaderOutput output; float4 worldPosition = float4(velocity.xyz * Time, 1); output.Position = mul(worldPosition, mul(View, Projection)); output.Color = ComputeColor(Time / 2); return output; } float4 ExplosionPixelShader( float2 textureCoordinate:TEXCOORD, float4 color:COLOR ):COLOR { return tex2D(explosionSampler, textureCoordinate) * color; } technique ExplosionShaderTechnique { pass P0 { VertexShader = compile vs_2_0 ExplosionVertexShader(); PixelShader = compile ps_2_0 ExplosionPixelShader(); } }
using Microsoft.Xna.Framework; public class ExplosionTest : Game { private GraphicsDeviceManager graphics; public ExplosionTest() { graphics = new GraphicsDeviceManager(this); this.Components.Add(new ExplosionRenderer(this)); } }
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Content; public class ExplosionRenderer : Microsoft.Xna.Framework.DrawableGameComponent { private Effect effect; private VertexVelocity[] vertices; private ContentManager content; private static System.Random random = new System.Random(); public ExplosionRenderer(Game game) : base(game) { content = new ContentManager(game.Services); } public override void Initialize() { vertices = new VertexVelocity[30]; for (int i = 0; i < vertices.Length; i++) { vertices[i].Velocity = randomVector3()/10; } base.Initialize(); } Vector3 randomVector3() { return new Vector3( (float)(random.NextDouble() * 2 - 1), (float)(random.NextDouble() * 2 - 1), (float)(random.NextDouble() * 2 - 1) ); } protected override void LoadGraphicsContent(bool loadAllContent) { if (loadAllContent) { effect = content.Load<Effect>("Content/ExplosionShader"); effect.Parameters["ExplosionTexture"].SetValue( content.Load<Texture2D>("Content/explosion") ); effect.Parameters["View"].SetValue( Matrix.CreateLookAt( new Vector3(0, 0, 5), new Vector3(), new Vector3(0, 1, 0) ) ); effect.Parameters["Projection"].SetValue( Matrix.CreatePerspectiveFieldOfView( MathHelper.ToRadians(45), aspectRatio, 0.1f, 1000 ) ); GraphicsDevice.VertexDeclaration = new VertexDeclaration( GraphicsDevice, VertexVelocity.VertexElements ); } } float aspectRatio { get { return (float)GraphicsDevice.Viewport.Width / GraphicsDevice.Viewport.Height; } } protected override void UnloadGraphicsContent(bool unloadAllContent) { if (unloadAllContent) { content.Unload(); } } public override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); GraphicsDevice.RenderState.PointSize = 50; GraphicsDevice.RenderState.PointSpriteEnable = true; GraphicsDevice.RenderState.AlphaBlendEnable = true; GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha; GraphicsDevice.RenderState.DestinationBlend = Blend.One; GraphicsDevice.RenderState.DepthBufferWriteEnable = false; effect.Parameters["Time"].SetValue( (float)gameTime.TotalGameTime.TotalSeconds ); effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); GraphicsDevice.DrawUserPrimitives<VertexVelocity>( PrimitiveType.PointList, vertices, 0, vertices.Length ); pass.End(); } effect.End(); } }
using Microsoft.Xna.Framework; public class ExplosionTest : Game { private GraphicsDeviceManager graphics; public ExplosionTest() { graphics = new GraphicsDeviceManager(this); ExplosionRenderer explosion = new ExplosionRenderer(this); Matrix view = Matrix.CreateLookAt( new Vector3(0, 0, 5), new Vector3(), new Vector3(0, 1, 0) ); Matrix projection = Matrix.CreatePerspectiveFieldOfView( MathHelper.ToRadians(45), (float)Window.ClientBounds.Width/Window.ClientBounds.Height, 0.1f, 1000 ); explosion.SetCamera(view, projection); this.Components.Add(explosion); } }
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Content; public class ExplosionRenderer : Microsoft.Xna.Framework.DrawableGameComponent { private Effect effect; private VertexVelocity[] vertices; private ContentManager content; private static System.Random random = new System.Random(); private Matrix view; private Matrix projection; public ExplosionRenderer(Game game) : base(game) { content = new ContentManager(game.Services); } public override void Initialize() { vertices = new VertexVelocity[30]; for (int i = 0; i < vertices.Length; i++) { vertices[i].Velocity = randomVector3()/10; } base.Initialize(); } Vector3 randomVector3() { return new Vector3( (float)(random.NextDouble() * 2 - 1), (float)(random.NextDouble() * 2 - 1), (float)(random.NextDouble() * 2 - 1) ); } protected override void LoadGraphicsContent(bool loadAllContent) { if (loadAllContent) { effect = content.Load<Effect>("Content/ExplosionShader"); effect.Parameters["ExplosionTexture"].SetValue( content.Load<Texture2D>("Content/explosion") ); GraphicsDevice.VertexDeclaration = new VertexDeclaration( GraphicsDevice, VertexVelocity.VertexElements ); } } protected override void UnloadGraphicsContent(bool unloadAllContent) { if (unloadAllContent) { content.Unload(); } } public override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); GraphicsDevice.RenderState.PointSize = 50; GraphicsDevice.RenderState.PointSpriteEnable = true; GraphicsDevice.RenderState.AlphaBlendEnable = true; GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha; GraphicsDevice.RenderState.DestinationBlend = Blend.One; GraphicsDevice.RenderState.DepthBufferWriteEnable = false; effect.Parameters["Time"].SetValue( (float)gameTime.TotalGameTime.TotalSeconds ); effect.Parameters["View"].SetValue(view); effect.Parameters["Projection"].SetValue(projection); effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); GraphicsDevice.DrawUserPrimitives<VertexVelocity>( PrimitiveType.PointList, vertices, 0, vertices.Length ); pass.End(); } effect.End(); } public void SetCamera(Matrix view, Matrix projection) { this.view = view; this.projection = projection; } }
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Content; public class ExplosionRenderer : Microsoft.Xna.Framework.DrawableGameComponent { private Effect effect; private VertexDeclaration vertexDeclaration; private VertexVelocity[] vertices; private ContentManager content; private static System.Random random = new System.Random(); private Matrix view; private Matrix projection; public ExplosionRenderer(Game game) : base(game) { content = new ContentManager(game.Services); } public override void Initialize() { vertices = new VertexVelocity[30]; for (int i = 0; i < vertices.Length; i++) { vertices[i].Velocity = randomVector3()/10; } base.Initialize(); } Vector3 randomVector3() { return new Vector3( (float)(random.NextDouble() * 2 - 1), (float)(random.NextDouble() * 2 - 1), (float)(random.NextDouble() * 2 - 1) ); } protected override void LoadGraphicsContent(bool loadAllContent) { if (loadAllContent) { effect = content.Load<Effect>("Content/ExplosionShader"); effect.Parameters["ExplosionTexture"].SetValue( content.Load<Texture2D>("Content/explosion") ); vertexDeclaration = new VertexDeclaration( GraphicsDevice, VertexVelocity.VertexElements ); } } protected override void UnloadGraphicsContent(bool unloadAllContent) { if (unloadAllContent) { content.Unload(); } } public override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); GraphicsDevice.RenderState.PointSize = 50; GraphicsDevice.RenderState.PointSpriteEnable = true; GraphicsDevice.RenderState.AlphaBlendEnable = true; GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha; GraphicsDevice.RenderState.DestinationBlend = Blend.One; GraphicsDevice.RenderState.DepthBufferWriteEnable = false; GraphicsDevice.VertexDeclaration = vertexDeclaration; effect.Parameters["Time"].SetValue( (float)gameTime.TotalGameTime.TotalSeconds ); effect.Parameters["View"].SetValue(view); effect.Parameters["Projection"].SetValue(projection); effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); GraphicsDevice.DrawUserPrimitives<VertexVelocity>( PrimitiveType.PointList, vertices, 0, vertices.Length ); pass.End(); } effect.End(); GraphicsDevice.RenderState.AlphaBlendEnable = false; GraphicsDevice.RenderState.DepthBufferWriteEnable = true; } public void SetCamera(Matrix view, Matrix projection) { this.view = view; this.projection = projection; } }
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Content; public class ExplosionTest : Game { private GraphicsDeviceManager graphics; private Effect effect; private VertexVelocity[] vertices; private ContentManager content; private static System.Random random = new System.Random(); public ExplosionTest() { graphics = new GraphicsDeviceManager(this); content = new ContentManager(Services); } protected override void Initialize() { vertices = new VertexVelocity[30]; for (int i = 0; i < vertices.Length; i++) { vertices[i].Velocity = randomVector3()/10; } base.Initialize(); } Vector3 randomVector3() { return new Vector3( (float)(random.NextDouble() * 2 - 1), (float)(random.NextDouble() * 2 - 1), (float)(random.NextDouble() * 2 - 1) ); } protected override void LoadGraphicsContent(bool loadAllContent) { if (loadAllContent) { effect = content.Load<Effect>("Content/ExplosionShader"); effect.Parameters["ExplosionTexture"].SetValue( content.Load<Texture2D>("Content/explosion") ); graphics.GraphicsDevice.VertexDeclaration = new VertexDeclaration( graphics.GraphicsDevice, VertexVelocity.VertexElements ); } } protected override void UnloadGraphicsContent(bool unloadAllContent) { if (unloadAllContent) { content.Unload(); } } protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.CornflowerBlue); graphics.GraphicsDevice.RenderState.PointSize = 50; graphics.GraphicsDevice.RenderState.PointSpriteEnable = true; graphics.GraphicsDevice.RenderState.AlphaBlendEnable = true; graphics.GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha; graphics.GraphicsDevice.RenderState.DestinationBlend = Blend.One; effect.Parameters["Time"].SetValue( (float)gameTime.TotalGameTime.TotalSeconds ); effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); graphics.GraphicsDevice.DrawUserPrimitives<VertexVelocity>( PrimitiveType.PointList, vertices, 0, vertices.Length ); pass.End(); } effect.End(); } }
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Content; public class ExplosionTest : Game { private GraphicsDeviceManager graphics; private Effect effect; private VertexVelocity[] vertices; private ContentManager content; private static System.Random random = new System.Random(); public ExplosionTest() { graphics = new GraphicsDeviceManager(this); content = new ContentManager(Services); } protected override void Initialize() { vertices = new VertexVelocity[30]; for (int i = 0; i < vertices.Length; i++) { vertices[i].Velocity = randomVector3()/10; } base.Initialize(); } Vector3 randomVector3() { return new Vector3( (float)(random.NextDouble() * 2 - 1), (float)(random.NextDouble() * 2 - 1), (float)(random.NextDouble() * 2 - 1) ); } protected override void LoadGraphicsContent(bool loadAllContent) { if (loadAllContent) { effect = content.Load<Effect>("Content/ExplosionShader"); effect.Parameters["ExplosionTexture"].SetValue( content.Load<Texture2D>("Content/explosion") ); graphics.GraphicsDevice.VertexDeclaration = new VertexDeclaration( graphics.GraphicsDevice, VertexVelocity.VertexElements ); } } protected override void UnloadGraphicsContent(bool unloadAllContent) { if (unloadAllContent) { content.Unload(); } } protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.CornflowerBlue); graphics.GraphicsDevice.RenderState.PointSize = 50; graphics.GraphicsDevice.RenderState.PointSpriteEnable = true; graphics.GraphicsDevice.RenderState.AlphaBlendEnable = true; graphics.GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha; graphics.GraphicsDevice.RenderState.DestinationBlend = Blend.One; graphics.GraphicsDevice.RenderState.DepthBufferWriteEnable = false; effect.Parameters["Time"].SetValue( (float)gameTime.TotalGameTime.TotalSeconds ); effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); graphics.GraphicsDevice.DrawUserPrimitives<VertexVelocity>( PrimitiveType.PointList, vertices, 0, vertices.Length ); pass.End(); } effect.End(); } }
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Content; public class ExplosionTest : Game { private GraphicsDeviceManager graphics; private Effect effect; private VertexVelocity[] vertices; private ContentManager content; private static System.Random random = new System.Random(); public ExplosionTest() { graphics = new GraphicsDeviceManager(this); content = new ContentManager(Services); } protected override void Initialize() { vertices = new VertexVelocity[30]; for (int i = 0; i < vertices.Length; i++) { vertices[i].Velocity = randomVector3()/10; } base.Initialize(); } Vector3 randomVector3() { return new Vector3( (float)(random.NextDouble() * 2 - 1), (float)(random.NextDouble() * 2 - 1), (float)(random.NextDouble() * 2 - 1) ); } protected override void LoadGraphicsContent(bool loadAllContent) { if (loadAllContent) { effect = content.Load<Effect>("Content/ExplosionShader"); effect.Parameters["ExplosionTexture"].SetValue( content.Load<Texture2D>("Content/explosion") ); effect.Parameters["View"].SetValue( Matrix.CreateLookAt( new Vector3(0, 0, 5), new Vector3(), new Vector3(0, 1, 0) ) ); effect.Parameters["Projection"].SetValue( Matrix.CreatePerspectiveFieldOfView( MathHelper.ToRadians(45), aspectRatio, 0.1f, 1000 ) ); graphics.GraphicsDevice.VertexDeclaration = new VertexDeclaration( graphics.GraphicsDevice, VertexVelocity.VertexElements ); } } float aspectRatio { get { return (float)graphics.GraphicsDevice.Viewport.Width / graphics.GraphicsDevice.Viewport.Height; } } protected override void UnloadGraphicsContent(bool unloadAllContent) { if (unloadAllContent) { content.Unload(); } } protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.CornflowerBlue); graphics.GraphicsDevice.RenderState.PointSize = 50; graphics.GraphicsDevice.RenderState.PointSpriteEnable = true; graphics.GraphicsDevice.RenderState.AlphaBlendEnable = true; graphics.GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha; graphics.GraphicsDevice.RenderState.DestinationBlend = Blend.One; graphics.GraphicsDevice.RenderState.DepthBufferWriteEnable = false; effect.Parameters["Time"].SetValue( (float)gameTime.TotalGameTime.TotalSeconds ); effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); graphics.GraphicsDevice.DrawUserPrimitives<VertexVelocity>( PrimitiveType.PointList, vertices, 0, vertices.Length ); pass.End(); } effect.End(); } }
float4x4 View; float4x4 Projection; float Time; texture ExplosionTexture; sampler explosionSampler = sampler_state { Texture = <ExplosionTexture>; }; float4 ExplosionVertexShader(float4 velocity:COLOR):POSITION { float4 worldPosition = float4(velocity.xyz * Time, 1); return mul(worldPosition, mul(View, Projection)); } float4 ExplosionPixelShader(float2 textureCoordinate:TEXCOORD):COLOR { return tex2D(explosionSampler, textureCoordinate); } technique ExplosionShaderTechnique { pass P0 { VertexShader = compile vs_2_0 ExplosionVertexShader(); PixelShader = compile ps_2_0 ExplosionPixelShader(); } }
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Content; public class ExplosionTest : Microsoft.Xna.Framework.Game { private GraphicsDeviceManager graphics; private Effect effect; private VertexPositionColor[] vertices = { new VertexPositionColor(new Vector3(0, 0.1f, 0), Color.White), new VertexPositionColor(new Vector3(0.1f, 0, 0), Color.White), new VertexPositionColor(new Vector3(-0.1f, 0, 0), Color.White) }; private ContentManager content; public ExplosionTest() { graphics = new GraphicsDeviceManager(this); content = new ContentManager(Services); } protected override void LoadGraphicsContent(bool loadAllContent) { if (loadAllContent) { effect = content.Load<Effect>("Content/ExplosionShader"); effect.Parameters["ExplosionTexture"].SetValue( content.Load<Texture2D>("Content/explosion") ); graphics.GraphicsDevice.VertexDeclaration = new VertexDeclaration( graphics.GraphicsDevice, VertexPositionColor.VertexElements ); } } protected override void UnloadGraphicsContent(bool unloadAllContent) { if (unloadAllContent) { content.Unload(); } } protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.CornflowerBlue); graphics.GraphicsDevice.RenderState.PointSize = 50; graphics.GraphicsDevice.RenderState.PointSpriteEnable = true; graphics.GraphicsDevice.RenderState.AlphaBlendEnable = true; graphics.GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha; graphics.GraphicsDevice.RenderState.DestinationBlend = Blend.One; effect.Parameters["Time"].SetValue( (float)gameTime.TotalGameTime.TotalSeconds ); effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>( PrimitiveType.PointList, vertices, 0, vertices.Length ); pass.End(); } effect.End(); } }
float Time; texture ExplosionTexture; sampler explosionSampler = sampler_state { Texture = <ExplosionTexture>; }; float4 ExplosionVertexShader(float4 position:POSITION):POSITION { return float4(position.xyz * Time, 1); } float4 ExplosionPixelShader(float2 textureCoordinate:TEXCOORD):COLOR { return tex2D(explosionSampler, textureCoordinate); } technique ExplosionShaderTechnique { pass P0 { VertexShader = compile vs_2_0 ExplosionVertexShader(); PixelShader = compile ps_2_0 ExplosionPixelShader(); } }
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; struct VertexVelocity { public Vector3 Velocity; public VertexVelocity(Vector3 velocity) { this.Velocity = velocity; } public static readonly VertexElement[] VertexElements = { new VertexElement( 0, 0, VertexElementFormat.Vector3, VertexElementMethod.Default, VertexElementUsage.Color, 0) }; }
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Content; public class ExplosionTest : Game { private GraphicsDeviceManager graphics; private Effect effect; private VertexVelocity[] vertices = { new VertexVelocity(new Vector3(0, 0.1f, 0)), new VertexVelocity(new Vector3(0.1f, 0, 0)), new VertexVelocity(new Vector3(-0.1f, 0, 0)) }; private ContentManager content; public ExplosionTest() { graphics = new GraphicsDeviceManager(this); content = new ContentManager(Services); } protected override void LoadGraphicsContent(bool loadAllContent) { if (loadAllContent) { effect = content.Load<Effect>("Content/ExplosionShader"); effect.Parameters["ExplosionTexture"].SetValue( content.Load<Texture2D>("Content/explosion") ); graphics.GraphicsDevice.VertexDeclaration = new VertexDeclaration( graphics.GraphicsDevice, VertexVelocity.VertexElements ); } } protected override void UnloadGraphicsContent(bool unloadAllContent) { if (unloadAllContent) { content.Unload(); } } protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.CornflowerBlue); graphics.GraphicsDevice.RenderState.PointSize = 50; graphics.GraphicsDevice.RenderState.PointSpriteEnable = true; graphics.GraphicsDevice.RenderState.AlphaBlendEnable = true; graphics.GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha; graphics.GraphicsDevice.RenderState.DestinationBlend = Blend.One; effect.Parameters["Time"].SetValue( (float)gameTime.TotalGameTime.TotalSeconds ); effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); graphics.GraphicsDevice.DrawUserPrimitives<VertexVelocity>( PrimitiveType.PointList, vertices, 0, vertices.Length ); pass.End(); } effect.End(); } }
float Time; texture ExplosionTexture; sampler explosionSampler = sampler_state { Texture = <ExplosionTexture>; }; float4 ExplosionVertexShader(float4 velocity:COLOR):POSITION { return float4(velocity.xyz * Time, 1); } float4 ExplosionPixelShader(float2 textureCoordinate:TEXCOORD):COLOR { return tex2D(explosionSampler, textureCoordinate); } technique ExplosionShaderTechnique { pass P0 { VertexShader = compile vs_2_0 ExplosionVertexShader(); PixelShader = compile ps_2_0 ExplosionPixelShader(); } }
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Content; public class ExplosionTest : Microsoft.Xna.Framework.Game { private GraphicsDeviceManager graphics; private Effect effect; private VertexPositionColor[] vertices = { new VertexPositionColor(new Vector3(0, 0.1f, 0), Color.White), new VertexPositionColor(new Vector3(0.1f, 0, 0), Color.White), new VertexPositionColor(new Vector3(-0.1f, 0, 0), Color.White) }; private ContentManager content; public ExplosionTest() { graphics = new GraphicsDeviceManager(this); content = new ContentManager(Services); } protected override void LoadGraphicsContent(bool loadAllContent) { if (loadAllContent) { effect = content.Load<Effect>("Content/ExplosionShader"); graphics.GraphicsDevice.VertexDeclaration = new VertexDeclaration( graphics.GraphicsDevice, VertexPositionColor.VertexElements ); } } protected override void UnloadGraphicsContent(bool unloadAllContent) { if (unloadAllContent) { content.Unload(); } } protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.CornflowerBlue); graphics.GraphicsDevice.RenderState.PointSize = 50; graphics.GraphicsDevice.RenderState.PointSpriteEnable = true; graphics.GraphicsDevice.RenderState.AlphaBlendEnable = true; graphics.GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha; graphics.GraphicsDevice.RenderState.DestinationBlend = Blend.One; effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>( PrimitiveType.PointList, vertices, 0, vertices.Length ); pass.End(); } effect.End(); } }
float4 ExplosionVertexShader(float4 position:POSITION):POSITION { return position; } float4 ExplosionPixelShader():COLOR { return 1; //white } technique ExplosionShaderTechnique { pass P0 { VertexShader = compile vs_2_0 ExplosionVertexShader(); PixelShader = compile ps_2_0 ExplosionPixelShader(); } }
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Content; public class ExplosionTest : Microsoft.Xna.Framework.Game { private GraphicsDeviceManager graphics; private Effect effect; private VertexPositionColor[] vertices = { new VertexPositionColor(new Vector3(0, 0.1f, 0), Color.White), new VertexPositionColor(new Vector3(0.1f, 0, 0), Color.White), new VertexPositionColor(new Vector3(-0.1f, 0, 0), Color.White) }; private ContentManager content; public ExplosionTest() { graphics = new GraphicsDeviceManager(this); content = new ContentManager(Services); } protected override void LoadGraphicsContent(bool loadAllContent) { if (loadAllContent) { effect = content.Load<Effect>("Content/ExplosionShader"); effect.Parameters["ExplosionTexture"].SetValue( content.Load<Texture2D>("Content/explosion") ); graphics.GraphicsDevice.VertexDeclaration = new VertexDeclaration( graphics.GraphicsDevice, VertexPositionColor.VertexElements ); } } protected override void UnloadGraphicsContent(bool unloadAllContent) { if (unloadAllContent) { content.Unload(); } } protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.CornflowerBlue); graphics.GraphicsDevice.RenderState.PointSize = 50; graphics.GraphicsDevice.RenderState.PointSpriteEnable = true; graphics.GraphicsDevice.RenderState.AlphaBlendEnable = true; graphics.GraphicsDevice.RenderState.SourceBlend = Blend.SourceAlpha; graphics.GraphicsDevice.RenderState.DestinationBlend = Blend.One; effect.Begin(); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>( PrimitiveType.PointList, vertices, 0, vertices.Length ); pass.End(); } effect.End(); } }
texture ExplosionTexture; sampler explosionSampler = sampler_state { Texture = <ExplosionTexture>; }; float4 ExplosionVertexShader(float4 position:POSITION):POSITION { return position; } float4 ExplosionPixelShader(float2 textureCoordinate:TEXCOORD):COLOR { return tex2D(explosionSampler, textureCoordinate); } technique ExplosionShaderTechnique { pass P0 { VertexShader = compile vs_2_0 ExplosionVertexShader(); PixelShader = compile ps_2_0 ExplosionPixelShader(); } }