- added a SimpleEffect.fx to test the model rendering

- fixed model implementation
- enabled all NotImplementedExceptions on BasicEffect again
- disabled property setting in BasicEffectReader, until BasicEffect is implemented
This commit is contained in:
SND\GinieDp_cp 2012-03-10 11:52:21 +00:00
parent 0bbb2d7b35
commit 5659159780
9 changed files with 205 additions and 62 deletions

View File

@ -251,7 +251,7 @@ namespace ANX.Framework.Content
}
catch (Exception ex)
{
throw new ContentLoadException("failed to open stream for '" + assetName + "'", ex);
throw new ContentLoadException(String.Format("failed to open stream for '{0}'", assetName), ex);
}
}

View File

@ -64,17 +64,18 @@ namespace ANX.Framework.Content
var graphics = input.ResolveGraphicsDevice();
var effect = new BasicEffect(graphics);
Texture2D texture = input.ReadExternalReference<Texture2D>();
if (texture != null)
{
effect.Texture = texture;
effect.TextureEnabled = true;
}
effect.DiffuseColor = input.ReadVector3();
effect.EmissiveColor = input.ReadVector3();
effect.SpecularColor = input.ReadVector3();
effect.SpecularPower = input.ReadSingle();
effect.Alpha = input.ReadSingle();
effect.VertexColorEnabled = input.ReadBoolean();
// TODO: enable parameter setup when basic effect is implemented
//if (texture != null)
//{
// effect.Texture = texture;
// effect.TextureEnabled = true;
//}
/*effect.DiffuseColor = */input.ReadVector3();
/*effect.EmissiveColor = */input.ReadVector3();
/*effect.SpecularColor = */input.ReadVector3();
/*effect.SpecularPower = */input.ReadSingle();
/*effect.Alpha = */input.ReadSingle();
/*effect.VertexColorEnabled = */input.ReadBoolean();
return effect;
}
}

View File

@ -172,9 +172,15 @@ namespace ANX.Framework.Content
object meshPartTag = reader.ReadObject<object>();
ModelMeshPart meshPart = new ModelMeshPart(vertexOffset, numVertices, startIndex, primitiveCount, meshPartTag);
reader.ReadSharedResource<VertexBuffer>((buffer) => { meshPart.VertexBuffer = buffer; });
reader.ReadSharedResource<IndexBuffer>((buffer) => { meshPart.IndexBuffer = buffer; });
reader.ReadSharedResource<Effect>((effect) => { meshPart.Effect = effect; });
reader.ReadSharedResource<VertexBuffer>((buffer) => {
meshPart.VertexBuffer = buffer;
});
reader.ReadSharedResource<IndexBuffer>((buffer) => {
meshPart.IndexBuffer = buffer;
});
reader.ReadSharedResource<Effect>((effect) => {
meshPart.Effect = effect;
});
meshParts[j] = meshPart;
}

View File

@ -84,12 +84,11 @@ namespace ANX.Framework.Graphics
{
get
{
return false;
//throw new NotImplementedException();
throw new NotImplementedException();
}
set
{
//throw new NotImplementedException();
throw new NotImplementedException();
}
}
@ -138,12 +137,11 @@ namespace ANX.Framework.Graphics
{
get
{
return Vector3.One;
//throw new NotImplementedException();
throw new NotImplementedException();
}
set
{
//throw new NotImplementedException();
throw new NotImplementedException();
}
}
@ -166,12 +164,11 @@ namespace ANX.Framework.Graphics
{
get
{
return false;
//throw new NotImplementedException();
throw new NotImplementedException();
}
set
{
//throw new NotImplementedException();
throw new NotImplementedException();
}
}
@ -179,12 +176,11 @@ namespace ANX.Framework.Graphics
{
get
{
return Vector3.One;
//throw new NotImplementedException();
throw new NotImplementedException();
}
set
{
//throw new NotImplementedException();
throw new NotImplementedException();
}
}
@ -192,12 +188,11 @@ namespace ANX.Framework.Graphics
{
get
{
return false;
//throw new NotImplementedException();
throw new NotImplementedException();
}
set
{
//throw new NotImplementedException();
throw new NotImplementedException();
}
}
@ -205,12 +200,11 @@ namespace ANX.Framework.Graphics
{
get
{
return 0;
//throw new NotImplementedException();
throw new NotImplementedException();
}
set
{
//throw new NotImplementedException();
throw new NotImplementedException();
}
}
@ -218,12 +212,11 @@ namespace ANX.Framework.Graphics
{
get
{
return 0;
//throw new NotImplementedException();
throw new NotImplementedException();
}
set
{
//throw new NotImplementedException();
throw new NotImplementedException();
}
}
@ -231,12 +224,11 @@ namespace ANX.Framework.Graphics
{
get
{
return null;
//throw new NotImplementedException();
throw new NotImplementedException();
}
set
{
//throw new NotImplementedException();
throw new NotImplementedException();
}
}
@ -244,12 +236,11 @@ namespace ANX.Framework.Graphics
{
get
{
return false;
//throw new NotImplementedException();
throw new NotImplementedException();
}
set
{
//throw new NotImplementedException();
throw new NotImplementedException();
}
}
@ -257,12 +248,11 @@ namespace ANX.Framework.Graphics
{
get
{
return Vector3.One;
//throw new NotImplementedException();
throw new NotImplementedException();
}
set
{
//throw new NotImplementedException();
throw new NotImplementedException();
}
}
@ -270,12 +260,11 @@ namespace ANX.Framework.Graphics
{
get
{
return Vector3.One;
//throw new NotImplementedException();
throw new NotImplementedException();
}
set
{
//throw new NotImplementedException();
throw new NotImplementedException();
}
}
@ -283,12 +272,11 @@ namespace ANX.Framework.Graphics
{
get
{
return Vector3.One;
//throw new NotImplementedException();
throw new NotImplementedException();
}
set
{
//throw new NotImplementedException();
throw new NotImplementedException();
}
}
@ -296,12 +284,11 @@ namespace ANX.Framework.Graphics
{
get
{
return 16;
//throw new NotImplementedException();
throw new NotImplementedException();
}
set
{
//throw new NotImplementedException();
throw new NotImplementedException();
}
}
@ -309,12 +296,11 @@ namespace ANX.Framework.Graphics
{
get
{
return 1;
//throw new NotImplementedException();
throw new NotImplementedException();
}
set
{
//throw new NotImplementedException();
throw new NotImplementedException();
}
}
@ -346,8 +332,8 @@ namespace ANX.Framework.Graphics
return;
}
this.CurrentTechnique = Techniques["NormalTex"]; //TODO: this is for ModelSample to be work
//throw new InvalidOperationException("Currently ANX's BasicEffect only supports VertexColor technique");
//this.CurrentTechnique = Techniques["NormalTex"]; //TODO: this is for ModelSample to be work
throw new InvalidOperationException("Currently ANX's BasicEffect only supports VertexColor technique");
}
}
}

View File

@ -147,7 +147,7 @@ namespace ANX.Framework.Graphics
if (newEffect != null && !newEffectIsKnown)
{
effects.Add(oldEffect);
effects.Add(newEffect);
}
}

View File

@ -64,6 +64,12 @@ namespace ModelSample
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Model cubeModel;
Effect effect;
bool overrideWithSimpleEffect = true;
Matrix world;
Matrix view;
Matrix projection;
public Game1()
{
@ -71,10 +77,36 @@ namespace ModelSample
Content.RootDirectory = "SampleContent";
}
protected override void Initialize()
{
const float nearplane = 1;
const float farplane = 100;
float aspect = (float)graphics.PreferredBackBufferWidth / (float)graphics.PreferredBackBufferHeight;
world = Matrix.Identity;
view = Matrix.CreateLookAt(Vector3.Backward * 10, world.Translation, Vector3.Up);
projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, aspect, nearplane, farplane);
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
effect = Content.Load<Effect>("Effects/SimpleEffect");
cubeModel = Content.Load<Model>("Models/Cube");
// Ovrride the basic effect in the model for testing
if (overrideWithSimpleEffect)
{
foreach (var mesh in cubeModel.Meshes)
{
foreach (var part in mesh.MeshParts)
{
part.Effect = effect;
}
}
}
}
protected override void Update(GameTime gameTime)
@ -83,13 +115,32 @@ 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);
}
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
cubeModel.Draw(Matrix.Identity, Matrix.Identity, Matrix.Identity);
if (overrideWithSimpleEffect)
{
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();
}
cubeModel.Draw(world, view, projection);
base.Draw(gameTime);
}
}

View File

@ -0,0 +1,91 @@
//
// This file is part of the ANX.Framework created by the "ANX.Framework developer group".
//
// This file is released under the Ms-PL license.
//
//
//
// Microsoft Public License (Ms-PL)
//
// This license governs use of the accompanying software. If you use the software, you accept this license.
// If you do not accept the license, do not use the software.
//
// 1.Definitions
// The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning
// here as under U.S. copyright law.
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2.Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations
// in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to
// reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution
// or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in
// section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed
// patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution
// in the software or derivative works of the contribution in the software.
//
// 3.Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your
// patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or
// object code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees,
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the
// extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a
// particular purpose and non-infringement.
uniform extern float4x4 World;
uniform extern float4x4 View;
uniform extern float4x4 Projection;
struct VertexShaderInput
{
// SV_POSITION semantic does not work. Results in an exception on draw call
// float4 Position : SV_POSITION;
float4 Position : POSITION0;
};
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;
};
VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
VertexShaderOutput output;
float4 worldPosition = mul(input.Position.xyz, World);
float4 viewPosition = mul(worldPosition, View);
output.Position = mul(viewPosition, Projection);
return output;
}
float4 PixelShaderFunction(VertexShaderOutput input) : SV_TARGET
{
return float4(1, 0, 0, 1);
}
technique10 Technique1
{
pass Pass1
{
VertexShader = compile vs_4_0 VertexShaderFunction();
PixelShader = compile ps_4_0 PixelShaderFunction();
}
}

View File

@ -119,6 +119,14 @@
<ProcessorParameters_OutputFormat>DX10_HLSL</ProcessorParameters_OutputFormat>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="Effects\SimpleEffect.fx">
<Name>SimpleEffect</Name>
<Importer>EffectImporter</Importer>
<Processor>AnxEffectProcessor</Processor>
<ProcessorParameters_OutputFormat>DX10_HLSL</ProcessorParameters_OutputFormat>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\$(XnaFrameworkVersion)\Microsoft.Xna.GameStudio.ContentPipeline.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View File

@ -111,7 +111,7 @@ namespace TextRendering
spriteBatch.DrawString(this.debugFont, "This screen is powered by the ANX.Framework!\r\nsecond line", new Vector2(100, 100 + this.debugFont.LineSpacing), Color.Black, 0.0f, new Vector2(1, -1), Vector2.One, SpriteEffects.None, 0.0f);
spriteBatch.DrawString(this.debugFont, "This screen is powered by the ANX.Framework!\r\nsecond line", new Vector2(100, 100 + this.debugFont.LineSpacing), Color.Red, 0.0f, Vector2.Zero, Vector2.One, SpriteEffects.None, 1.0f);
spriteBatch.DrawString(this.debugFont, "Mouse X: " + Mouse.GetState().X, new Vector2(100, 100 + this.debugFont.LineSpacing * 3), Color.DarkOrange);
spriteBatch.DrawString(this.debugFont, "Mouse Y:" + Mouse.GetState().Y, new Vector2(100, 100 + this.debugFont.LineSpacing * 4), Color.DarkOrange);
spriteBatch.DrawString(this.debugFont, "Mouse Y: " + Mouse.GetState().Y, new Vector2(100, 100 + this.debugFont.LineSpacing * 4), Color.DarkOrange);
spriteBatch.DrawString(this.debugFont, "rotated Text", new Vector2(100, 150), Color.Green, MathHelper.ToRadians(90), Vector2.Zero, 1.0f, SpriteEffects.None, 1.0f);
GamePadState state = GamePad.GetState(PlayerIndex.One);