From 2cd5e8b803c9973307e9668d15d543f38c8f69c8 Mon Sep 17 00:00:00 2001 From: "SND\\GinieDp_cp" Date: Sat, 10 Mar 2012 22:29:29 +0000 Subject: [PATCH] - Fixed the ModelSample - Added texture rendering to ModelSample --- ANX.Framework/Graphics/GraphicsDevice.cs | 13 +++++++- Samples/ModelSample/ModelSample/Game1.cs | 26 +++++++++------- Samples/SampleContent/Effects/SimpleEffect.fx | 30 +++++++++---------- 3 files changed, 43 insertions(+), 26 deletions(-) diff --git a/ANX.Framework/Graphics/GraphicsDevice.cs b/ANX.Framework/Graphics/GraphicsDevice.cs index 6b3e719d..b2468522 100644 --- a/ANX.Framework/Graphics/GraphicsDevice.cs +++ b/ANX.Framework/Graphics/GraphicsDevice.cs @@ -118,7 +118,18 @@ namespace ANX.Framework.Graphics #region Clear public void Clear(Color color) { - nativeDevice.Clear(ref color); + ClearOptions options = ClearOptions.Target; + if (this.currentPresentationParameters.DepthStencilFormat != DepthFormat.None) + { + options |= ClearOptions.DepthBuffer; + } + if (this.currentPresentationParameters.DepthStencilFormat == DepthFormat.Depth24Stencil8) + { + options |= ClearOptions.Stencil; + } + + Clear(options, color, 1, 0); + // nativeDevice.Clear(ref color); } public void Clear(ClearOptions options, Color color, float depth, int stencil) diff --git a/Samples/ModelSample/ModelSample/Game1.cs b/Samples/ModelSample/ModelSample/Game1.cs index 24e9295b..310bea1c 100644 --- a/Samples/ModelSample/ModelSample/Game1.cs +++ b/Samples/ModelSample/ModelSample/Game1.cs @@ -65,12 +65,16 @@ namespace ModelSample SpriteBatch spriteBatch; Model cubeModel; Effect effect; + Texture2D texture; bool overrideWithSimpleEffect = true; Matrix world; Matrix view; Matrix projection; + Matrix worldViewProj; + Matrix worldInverseTranspose; + public Game1() { graphics = new GraphicsDeviceManager(this); @@ -95,6 +99,7 @@ namespace ModelSample spriteBatch = new SpriteBatch(GraphicsDevice); effect = Content.Load("Effects/SimpleEffect"); cubeModel = Content.Load("Models/Cube"); + texture = Content.Load("Textures/Test_100x100"); // Ovrride the basic effect in the model for testing if (overrideWithSimpleEffect) @@ -115,15 +120,14 @@ namespace ModelSample Keyboard.GetState().IsKeyDown(Keys.Escape)) this.Exit(); - if (Keyboard.GetState().IsKeyDown(Keys.Space)) - { - world = Matrix.Identity; - } - else - { - world = Matrix.Identity * Matrix.CreateRotationX(MathHelper.PiOver4) * Matrix.CreateRotationY(MathHelper.PiOver4); - } - + const float speed = 0.00001f; + world = Matrix.Identity * + Matrix.CreateRotationX((float)gameTime.TotalGameTime.TotalSeconds * speed) * + Matrix.CreateRotationY((float)gameTime.TotalGameTime.TotalSeconds * speed) * + Matrix.CreateRotationZ((float)gameTime.TotalGameTime.TotalSeconds * speed); + + worldViewProj = world * view * projection; + worldInverseTranspose = Matrix.Transpose(Matrix.Invert(world)); base.Update(gameTime); } @@ -137,7 +141,9 @@ namespace ModelSample this.effect.Parameters["World"].SetValue(this.world); this.effect.Parameters["View"].SetValue(this.view); this.effect.Parameters["Projection"].SetValue(this.projection); - this.effect.CurrentTechnique.Passes[0].Apply(); + this.effect.Parameters["WorldViewProj"].SetValue(this.worldViewProj); + this.effect.Parameters["WorldInverseTranspose"].SetValue(this.worldInverseTranspose); + this.effect.Parameters["Texture"].SetValue(this.texture); } cubeModel.Draw(world, view, projection); diff --git a/Samples/SampleContent/Effects/SimpleEffect.fx b/Samples/SampleContent/Effects/SimpleEffect.fx index 98c1e086..532f2004 100644 --- a/Samples/SampleContent/Effects/SimpleEffect.fx +++ b/Samples/SampleContent/Effects/SimpleEffect.fx @@ -45,40 +45,40 @@ uniform extern float4x4 World; uniform extern float4x4 View; uniform extern float4x4 Projection; +uniform extern float4x4 WorldViewProj; +uniform extern float4x4 WorldInverseTranspose; + +Texture2D Texture : register(t0); + sampler TextureSampler : register(s0); + struct VertexShaderInput { - // SV_POSITION semantic does not work. Results in an exception on draw call - // float4 Position : SV_POSITION; - - float4 Position : POSITION0; + float4 Position : POSITION0; + float3 Normal : NORMAL; + float2 TexCoord : TEXCOORD0; }; struct VertexShaderOutput { - // POSITION semantic does not work -> blank screen - // float4 Position : POSITION; - - // POSITION semantic does not work -> blank screen - // float4 Position : POSITION0; - - // SV_POSITION semantic does work float4 Position : SV_POSITION; + float3 Normal : NORMAL; + float2 TexCoord : TEXCOORD0; }; VertexShaderOutput VertexShaderFunction(VertexShaderInput input) { VertexShaderOutput output; - float4 worldPosition = mul(input.Position.xyz, World); - float4 viewPosition = mul(worldPosition, View); - output.Position = mul(viewPosition, Projection); + output.Position = mul(input.Position, WorldViewProj); + output.Normal = normalize(mul(input.Normal.xyz, (float3x3)WorldInverseTranspose)); + output.TexCoord = input.TexCoord; return output; } float4 PixelShaderFunction(VertexShaderOutput input) : SV_TARGET { - return float4(1, 0, 0, 1); + return Texture.Sample(TextureSampler, input.TexCoord); } technique10 Technique1