I downloaded the newest version that includes the graphics part and have run into some questions. I have an ocean effect shader that I had originally gotten from here that I used before I got this engine. I tried my hand at applying this shader in the graphics engine, but an error was thrown stating that I wasn't supplying the TANGENT0 information needed by the shader.
I'm pretty sure this is happening because I changed the content processor to the Digital Rune Model instead of the XNA Model which had an option for generating tangent frames in the processor options. I very well could just not be applying effects the intended way to a Digital Rune model though, so I wanted to see how you would go about doing this. Here's the code that I have for the ocean (I basically took the Ground class in the DefferedLightingSample and made an Ocean version that loads my model, etc):
001.public class Ocean : GameObject
002. {
003. private DigitalRune.Graphics.SceneGraph.Model _model;
004. private RigidBody _body;
005.
006.
007. // Parameters for Ocean shader
008. EffectParameter projectionOceanParameter;
009. EffectParameter viewOceanParameter;
010. EffectParameter worldOceanParameter;
011. EffectParameter ambientIntensityOceanParameter;
012. EffectParameter ambientColorOceanParameter;
013.
014.
015. EffectParameter diffuseIntensityOceanParameter;
016. EffectParameter diffuseColorOceanParameter;
017. EffectParameter lightDirectionOceanParameter;
018.
019.
020. EffectParameter eyePosOceanParameter;
021. EffectParameter specularColorOceanParameter;
022.
023.
024. EffectParameter colorMapTextureOceanParameter;
025. EffectParameter normalMapTextureOceanParameter;
026. EffectParameter totalTimeOceanParameter;
027.
028.
029. // ocean shader
030. Effect oceanEffect;
031.
032.
033. // ocean textures
034. Texture2D diffuseOceanTexture;
035. Texture2D normalOceanTexture;
036.
037.
038. //variables
039. float totalTime = 0.0f;
040. Vector4 ambientLightColor;
041.
042.
043.
044.
045. protected override void OnLoad()
046. {
047. var contentManager = ServiceLocator.Current.GetInstance<ContentManager>();
048. var graphicsService = ServiceLocator.Current.GetInstance<IGraphicsService>();
049. var screen = ((DeferredLightingScreen)graphicsService.Screens["Default"]);
050.
051.
052. //ocean effect
053. oceanEffect = contentManager.Load<Effect>("OceanShader");
054. SetupOceanShaderParameters();
055. diffuseOceanTexture = contentManager.Load<Texture2D>("water");
056. normalOceanTexture = contentManager.Load<Texture2D>("wavesbump");
057.
058.
059. // Load model and add it to the scene.
060. _model = (DigitalRune.Graphics.SceneGraph.Model)contentManager.Load<DigitalRune.Graphics.SceneGraph.Model>("ocean").Clone();
061. _model.ScaleLocal = new Vector3F(0.5f);
062. screen.Scene.Children.Add(_model);
063.
064.
065. // Disable the CastsShadow flag for ground mesh instances. No need to render
066. // this model into the shadow map. (This also avoids any shadow acne on the
067. // ground model.)
068. foreach (var meshInstance in _model.GetSubtree().OfType<MeshInstance>())
069. meshInstance.CastsShadows = false;
070.
071.
072. // Create rigid body and add it to the simulation.
073. var simulation = ServiceLocator.Current.GetInstance<Simulation>();
074. _body = new RigidBody(new PlaneShape(Vector3F.UnitY, 0))
075. {
076. MotionType = MotionType.Static,
077. };
078. simulation.RigidBodies.Add(_body);
079. }
080.
081.
082.
083.
084. protected override void OnUnload()
085. {
086. // Remove model and body.
087. _model.Parent.Children.Remove(_model);
088. _model.Dispose();
089. _model = null;
090.
091.
092. _body.Simulation.RigidBodies.Remove(_body);
093. _body = null;
094. }
095.
096.
097. public void SetupOceanShaderParameters()
098. {
099. // Bind the parameters with the shader.
100. worldOceanParameter = oceanEffect.Parameters["World"];
101. viewOceanParameter = oceanEffect.Parameters["View"];
102. projectionOceanParameter = oceanEffect.Parameters["Projection"];
103.
104.
105. ambientColorOceanParameter = oceanEffect.Parameters["AmbientColor"];
106. ambientIntensityOceanParameter = oceanEffect.Parameters["AmbientIntensity"];
107.
108.
109. diffuseColorOceanParameter = oceanEffect.Parameters["DiffuseColor"];
110. diffuseIntensityOceanParameter = oceanEffect.Parameters["DiffuseIntensity"];
111. lightDirectionOceanParameter = oceanEffect.Parameters["LightDirection"];
112.
113.
114. eyePosOceanParameter = oceanEffect.Parameters["EyePosition"];
115. specularColorOceanParameter = oceanEffect.Parameters["SpecularColor"];
116.
117.
118. colorMapTextureOceanParameter = oceanEffect.Parameters["ColorMap"];
119. normalMapTextureOceanParameter = oceanEffect.Parameters["NormalMap"];
120. totalTimeOceanParameter = oceanEffect.Parameters["TotalTime"];
121. }
122.
123.
124. public void Update(GameTime gameTime)
125. {
126. ambientLightColor = Color.White.ToVector4();
127. totalTime += gameTime.ElapsedGameTime.Milliseconds / 5000.0f;
128. }
129.
130.
131. public void Draw(GameTime gameTime, Player player)
132. {
133. var graphics = ServiceLocator.Current.GetInstance<IGraphicsService>();
134.
135.
136. MeshInstance meshIn = _model.GetSubtree().OfType<MeshInstance>().First();
137. Submesh meshSub = meshIn.Mesh.Submeshes.First();
138.
139.
140. // Set parameters
141. projectionOceanParameter.SetValue(player.Camera.Camera.Projection.ToXna());
142. viewOceanParameter.SetValue(player.Camera.View.ToXna());
143. worldOceanParameter.SetValue(Matrix.CreateRotationY((float)MathHelper.ToRadians((int)270)) * Matrix.CreateRotationZ((float)MathHelper.ToRadians((int)90)) * Matrix.CreateScale(100.0f) * Matrix.CreateTranslation(0, -60, 0)); //Matrix.CreateScale(50.0f) * Matrix.CreateRotationX(MathHelper.ToRadians(270)) * Matrix.CreateTranslation(0, -60, 0);
144. ambientIntensityOceanParameter.SetValue(0.4f);
145. ambientColorOceanParameter.SetValue(ambientLightColor);
146. diffuseColorOceanParameter.SetValue(Color.White.ToVector4());
147. diffuseIntensityOceanParameter.SetValue(0.2f);
148. specularColorOceanParameter.SetValue(Color.White.ToVector4());
149. eyePosOceanParameter.SetValue(player.Camera.PoseLocal.Position.ToXna());
150. colorMapTextureOceanParameter.SetValue(diffuseOceanTexture);
151. normalMapTextureOceanParameter.SetValue(normalOceanTexture);
152. totalTimeOceanParameter.SetValue(totalTime);
153.
154.
155. Vector3 lightDirection = new Vector3(1.0f, 0.0f, -1.0f);
156.
157.
158. //ensure the light direction is normalized, or
159. //the shader will give some weird results
160. lightDirection.Normalize();
161. lightDirectionOceanParameter.SetValue(lightDirection);
162.
163.
164. //set the vertex source to the mesh's vertex buffer
165. graphics.GraphicsDevice.SetVertexBuffer(meshSub.VertexBuffer, 0);
166.
167.
168. //set the current index buffer to the sample mesh's index buffer
169. graphics.GraphicsDevice.Indices = meshSub.IndexBuffer;
170.
171.
172. graphics.GraphicsDevice.BlendState = BlendState.AlphaBlend;
173. graphics.GraphicsDevice.DepthStencilState = DepthStencilState.DepthRead;
174.
175.
176. oceanEffect.CurrentTechnique = oceanEffect.Techniques["Technique1"];
177.
178.
179. for (int i = 0; i < oceanEffect.CurrentTechnique.Passes.Count; i++)
180. {
181. //EffectPass.Apply will update the device to
182. //begin using the state information defined in the current pass
183. oceanEffect.CurrentTechnique.Passes[i].Apply();
184.
185.
186. //theMesh contains all of the information required to draw
187. //the current mesh
188. graphics.GraphicsDevice.DrawIndexedPrimitives(
189. PrimitiveType.TriangleList, 0, 0,
190. meshSub.VertexCount, meshSub.StartIndex, meshSub.PrimitiveCount);
191. }
192. }
193. }
=========================================================================================================
If you want to look at the OceanShader code, I can attach or paste it in as well. I just didn't want to have an even more gigantic post if it wasn't necessary.