[PR]
×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
プログラミング、3DCGとその他いろいろについて
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
float4x4 World, View, Projection; float Shatter; texture Texture; sampler TextureSampler = sampler_state { Texture = (Texture); }; struct VertexPositionTexture { float4 Position : POSITION; float2 TextureCoordinate : TEXCOORD; }; VertexPositionTexture ShatterVertexShader( float4 position:POSITION, float4 normal:NORMAL, float2 textureCoordinate :TEXCOORD ) { VertexPositionTexture output; position.xyz += normal.xyz * Shatter; float4x4 transform = mul(World, mul(View, Projection)); output.Position = mul(position, transform); output.TextureCoordinate = textureCoordinate; return output; } float4 ShatterPixelShader(float2 textureCoordinate : TEXCOORD) : COLOR { return tex2D(TextureSampler, textureCoordinate); } technique ShatterEffect { pass { VertexShader = compile vs_2_0 ShatterVertexShader(); PixelShader = compile ps_2_0 ShatterPixelShader(); } }
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Content; class MyGame : Game { GraphicsDeviceManager graphics; ContentManager content; //Graphics Device Objects Effect effect; Model model; public MyGame() { graphics = new GraphicsDeviceManager(this); content = new ContentManager(Services); } protected override void LoadGraphicsContent(bool loadAllContent) { if (loadAllContent) { effect = content.Load<Effect>("ShatterEffect"); model = loadModel("Ship", effect); } } Model loadModel(string modelName, Effect effect) { Model result = content.Load<Model>(modelName); foreach (ModelMesh mesh in result.Meshes) { foreach (ModelMeshPart part in mesh.MeshParts) { effect.Parameters["Texture"].SetValue( ((BasicEffect)part.Effect).Texture ); part.Effect = effect.Clone(graphics.GraphicsDevice); } } return result; } protected override void UnloadGraphicsContent(bool unloadAllContent) { if (unloadAllContent) { content.Unload(); } } protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.CornflowerBlue); foreach (ModelMesh mesh in model.Meshes) { foreach (Effect effect in mesh.Effects) { setEffectParameters( effect, gameTime.TotalGameTime.TotalSeconds ); } mesh.Draw(); } } private void setEffectParameters(Effect effect, double totalSeconds) { Matrix world = Matrix.CreateRotationY( (float)totalSeconds * 2 ); Matrix view = Matrix.CreateLookAt( new Vector3(0, 0, 3000), new Vector3(), Vector3.UnitY ); Matrix projection = Matrix.CreatePerspectiveFieldOfView( MathHelper.ToRadians(90), (float)graphics.GraphicsDevice.Viewport.Width / graphics.GraphicsDevice.Viewport.Height, 1, 10000 ); effect.Parameters["Shatter"].SetValue( (float)(1 + System.Math.Sin(totalSeconds)) * 100 ); effect.Parameters["World"].SetValue(world); effect.Parameters["View"].SetValue(view); effect.Parameters["Projection"].SetValue(projection); } }