[PR]
×
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
プログラミング、3DCGとその他いろいろについて
[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。
//グローバル変数(C#側からセット) float4x4 World; float4x4 View; float4x4 Projection; texture Texture; //頂点シェーダ struct VertexPositionTexture { float4 Position : POSITION; float4 TextureCoordinate : TEXCOORD; }; VertexPositionTexture VertexShader(VertexPositionTexture input) { VertexPositionTexture output; output.Position = mul(input.Position, mul(World, mul(View, Projection))); output.TextureCoordinate = input.TextureCoordinate; return output; } //ピクセルシェーダ sampler DiffuseSampler = sampler_state{ Texture = (Texture); }; float4 PixelShader(float2 textureCoordinate : TEXCOORD) : COLOR { return tex2D(DiffuseSampler, textureCoordinate); } technique SimpleEffect { pass { VertexShader = compile vs_1_1 VertexShader(); PixelShader = compile ps_2_0 PixelShader(); } }
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Content; public class MyGame : Game { GraphicsDeviceManager graphics; ContentManager content; Model model; public MyGame() { graphics = new GraphicsDeviceManager(this); content = new ContentManager(Services); } protected override void LoadGraphicsContent(bool loadAllContent) { if (loadAllContent) { model = content.Load<Model>("Ship"); ChangeEffectUsedByModel( content.Load<Effect>("SimpleEffect") ); } } void ChangeEffectUsedByModel(Effect replacementEffect) { Texture2D texture = content.Load<Texture2D>("ShipDiffuse"); foreach (ModelMesh mesh in model.Meshes) { foreach (ModelMeshPart part in mesh.MeshParts) { Effect newEffect = replacementEffect.Clone( graphics.GraphicsDevice ); newEffect.Parameters["Texture"].SetValue( texture ); part.Effect = newEffect; } } } protected override void UnloadGraphicsContent(bool unloadAllContent) { if (unloadAllContent) content.Unload(); } protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.CornflowerBlue); Matrix world = Matrix.CreateRotationY( MathHelper.ToRadians(-40) ); Matrix view = Matrix.CreateLookAt( new Vector3(3000, 1500, 0), Vector3.Zero, Vector3.Up ); Matrix projection = Matrix.CreatePerspectiveFieldOfView( MathHelper.ToRadians(45), (float)graphics.GraphicsDevice.Viewport.Width / graphics.GraphicsDevice.Viewport.Height, 1000, 10000 ); DrawModel(world, view, projection); } void DrawModel(Matrix world, Matrix view, Matrix projection) { Matrix[] transforms = new Matrix[model.Bones.Count]; model.CopyAbsoluteBoneTransformsTo(transforms); foreach (ModelMesh mesh in model.Meshes) { foreach (Effect effect in mesh.Effects) { Matrix localWorld = transforms[mesh.ParentBone.Index] * world; effect.Parameters["World"].SetValue(localWorld); effect.Parameters["View"].SetValue(view); effect.Parameters["Projection"].SetValue(projection); } mesh.Draw(); } } }
void ChangeEffectUsedByModel(Effect replacementEffect) { foreach (ModelMesh mesh in model.Meshes) { foreach (ModelMeshPart part in mesh.MeshParts) { Effect newEffect = replacementEffect.Clone( graphics.GraphicsDevice ); newEffect.Parameters["Texture"].SetValue( ((BasicEffect)part.Effect).Texture ); part.Effect = newEffect; } } }
上手く表示されるテクスチャ | 上手く表示されないテクスチャ | |
Width | 256 | 256 |
Height | 256 | 256 |
ResourceManagementMode | Automatic | Automatic |
ResourceUsage | None | None |
Format | Dxt5 | Color |
LevelCount | 9 | 1 |
LevelOfDetail | 0 | 0 |
IsDisposed | False | False |
Tag | ||
Name | ||
ResourceType | Texture2D | Texture2D |
Priority | 0 | 0 |