- 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
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)

View File

@ -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<Effect>("Effects/SimpleEffect");
cubeModel = Content.Load<Model>("Models/Cube");
texture = Content.Load<Texture2D>("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);

View File

@ -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<float4> 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