diff --git a/ANX.Framework/Content/ContentManager.cs b/ANX.Framework/Content/ContentManager.cs index 6c3fdcc8..76bce181 100644 --- a/ANX.Framework/Content/ContentManager.cs +++ b/ANX.Framework/Content/ContentManager.cs @@ -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); } } diff --git a/ANX.Framework/Content/GraphicTypeReaders/BasicEffectReader.cs b/ANX.Framework/Content/GraphicTypeReaders/BasicEffectReader.cs index 15e24b7c..6abae073 100644 --- a/ANX.Framework/Content/GraphicTypeReaders/BasicEffectReader.cs +++ b/ANX.Framework/Content/GraphicTypeReaders/BasicEffectReader.cs @@ -64,17 +64,18 @@ namespace ANX.Framework.Content var graphics = input.ResolveGraphicsDevice(); var effect = new BasicEffect(graphics); Texture2D texture = input.ReadExternalReference(); - 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; } } diff --git a/ANX.Framework/Content/GraphicTypeReaders/ModelReader.cs b/ANX.Framework/Content/GraphicTypeReaders/ModelReader.cs index 24e94839..53db6855 100644 --- a/ANX.Framework/Content/GraphicTypeReaders/ModelReader.cs +++ b/ANX.Framework/Content/GraphicTypeReaders/ModelReader.cs @@ -172,9 +172,15 @@ namespace ANX.Framework.Content object meshPartTag = reader.ReadObject(); ModelMeshPart meshPart = new ModelMeshPart(vertexOffset, numVertices, startIndex, primitiveCount, meshPartTag); - reader.ReadSharedResource((buffer) => { meshPart.VertexBuffer = buffer; }); - reader.ReadSharedResource((buffer) => { meshPart.IndexBuffer = buffer; }); - reader.ReadSharedResource((effect) => { meshPart.Effect = effect; }); + reader.ReadSharedResource((buffer) => { + meshPart.VertexBuffer = buffer; + }); + reader.ReadSharedResource((buffer) => { + meshPart.IndexBuffer = buffer; + }); + reader.ReadSharedResource((effect) => { + meshPart.Effect = effect; + }); meshParts[j] = meshPart; } diff --git a/ANX.Framework/Graphics/BasicEffect.cs b/ANX.Framework/Graphics/BasicEffect.cs index 451fcf39..a6427a6d 100644 --- a/ANX.Framework/Graphics/BasicEffect.cs +++ b/ANX.Framework/Graphics/BasicEffect.cs @@ -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"); } } } diff --git a/ANX.Framework/Graphics/ModelMesh.cs b/ANX.Framework/Graphics/ModelMesh.cs index c6fe03b0..de1c6f6c 100644 --- a/ANX.Framework/Graphics/ModelMesh.cs +++ b/ANX.Framework/Graphics/ModelMesh.cs @@ -147,7 +147,7 @@ namespace ANX.Framework.Graphics if (newEffect != null && !newEffectIsKnown) { - effects.Add(oldEffect); + effects.Add(newEffect); } } diff --git a/Samples/ModelSample/ModelSample/Game1.cs b/Samples/ModelSample/ModelSample/Game1.cs index 6363b272..24e9295b 100644 --- a/Samples/ModelSample/ModelSample/Game1.cs +++ b/Samples/ModelSample/ModelSample/Game1.cs @@ -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("Effects/SimpleEffect"); cubeModel = Content.Load("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); } } diff --git a/Samples/SampleContent/Effects/SimpleEffect.fx b/Samples/SampleContent/Effects/SimpleEffect.fx new file mode 100644 index 00000000..98c1e086 --- /dev/null +++ b/Samples/SampleContent/Effects/SimpleEffect.fx @@ -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(); + } +} diff --git a/Samples/SampleContent/SampleContent.contentproj b/Samples/SampleContent/SampleContent.contentproj index 329b7afa..30be9fcd 100644 --- a/Samples/SampleContent/SampleContent.contentproj +++ b/Samples/SampleContent/SampleContent.contentproj @@ -119,6 +119,14 @@ DX10_HLSL + + + SimpleEffect + EffectImporter + AnxEffectProcessor + DX10_HLSL + +