- Fixed the ModelSample

- Added texture rendering to ModelSample
This commit is contained in:
SND\GinieDp_cp 2012-03-10 22:29:29 +00:00
parent 5659159780
commit 2cd5e8b803
3 changed files with 43 additions and 26 deletions

View File

@ -118,7 +118,18 @@ namespace ANX.Framework.Graphics
#region Clear #region Clear
public void Clear(Color color) 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) public void Clear(ClearOptions options, Color color, float depth, int stencil)

View File

@ -65,12 +65,16 @@ namespace ModelSample
SpriteBatch spriteBatch; SpriteBatch spriteBatch;
Model cubeModel; Model cubeModel;
Effect effect; Effect effect;
Texture2D texture;
bool overrideWithSimpleEffect = true; bool overrideWithSimpleEffect = true;
Matrix world; Matrix world;
Matrix view; Matrix view;
Matrix projection; Matrix projection;
Matrix worldViewProj;
Matrix worldInverseTranspose;
public Game1() public Game1()
{ {
graphics = new GraphicsDeviceManager(this); graphics = new GraphicsDeviceManager(this);
@ -95,6 +99,7 @@ namespace ModelSample
spriteBatch = new SpriteBatch(GraphicsDevice); spriteBatch = new SpriteBatch(GraphicsDevice);
effect = Content.Load<Effect>("Effects/SimpleEffect"); effect = Content.Load<Effect>("Effects/SimpleEffect");
cubeModel = Content.Load<Model>("Models/Cube"); cubeModel = Content.Load<Model>("Models/Cube");
texture = Content.Load<Texture2D>("Textures/Test_100x100");
// Ovrride the basic effect in the model for testing // Ovrride the basic effect in the model for testing
if (overrideWithSimpleEffect) if (overrideWithSimpleEffect)
@ -115,15 +120,14 @@ namespace ModelSample
Keyboard.GetState().IsKeyDown(Keys.Escape)) Keyboard.GetState().IsKeyDown(Keys.Escape))
this.Exit(); this.Exit();
if (Keyboard.GetState().IsKeyDown(Keys.Space)) const float speed = 0.00001f;
{ world = Matrix.Identity *
world = Matrix.Identity; Matrix.CreateRotationX((float)gameTime.TotalGameTime.TotalSeconds * speed) *
} Matrix.CreateRotationY((float)gameTime.TotalGameTime.TotalSeconds * speed) *
else Matrix.CreateRotationZ((float)gameTime.TotalGameTime.TotalSeconds * speed);
{
world = Matrix.Identity * Matrix.CreateRotationX(MathHelper.PiOver4) * Matrix.CreateRotationY(MathHelper.PiOver4); worldViewProj = world * view * projection;
} worldInverseTranspose = Matrix.Transpose(Matrix.Invert(world));
base.Update(gameTime); base.Update(gameTime);
} }
@ -137,7 +141,9 @@ namespace ModelSample
this.effect.Parameters["World"].SetValue(this.world); this.effect.Parameters["World"].SetValue(this.world);
this.effect.Parameters["View"].SetValue(this.view); this.effect.Parameters["View"].SetValue(this.view);
this.effect.Parameters["Projection"].SetValue(this.projection); 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); cubeModel.Draw(world, view, projection);

View File

@ -45,40 +45,40 @@ uniform extern float4x4 World;
uniform extern float4x4 View; uniform extern float4x4 View;
uniform extern float4x4 Projection; uniform extern float4x4 Projection;
uniform extern float4x4 WorldViewProj;
uniform extern float4x4 WorldInverseTranspose;
Texture2D<float4> Texture : register(t0);
sampler TextureSampler : register(s0);
struct VertexShaderInput struct VertexShaderInput
{ {
// SV_POSITION semantic does not work. Results in an exception on draw call float4 Position : POSITION0;
// float4 Position : SV_POSITION; float3 Normal : NORMAL;
float2 TexCoord : TEXCOORD0;
float4 Position : POSITION0;
}; };
struct VertexShaderOutput 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; float4 Position : SV_POSITION;
float3 Normal : NORMAL;
float2 TexCoord : TEXCOORD0;
}; };
VertexShaderOutput VertexShaderFunction(VertexShaderInput input) VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{ {
VertexShaderOutput output; VertexShaderOutput output;
float4 worldPosition = mul(input.Position.xyz, World); output.Position = mul(input.Position, WorldViewProj);
float4 viewPosition = mul(worldPosition, View); output.Normal = normalize(mul(input.Normal.xyz, (float3x3)WorldInverseTranspose));
output.Position = mul(viewPosition, Projection); output.TexCoord = input.TexCoord;
return output; return output;
} }
float4 PixelShaderFunction(VertexShaderOutput input) : SV_TARGET float4 PixelShaderFunction(VertexShaderOutput input) : SV_TARGET
{ {
return float4(1, 0, 0, 1); return Texture.Sample(TextureSampler, input.TexCoord);
} }
technique10 Technique1 technique10 Technique1