Ejemplo n.º 1
0
 /// <inheritdoc />
 protected override void PopulateEffectHook(GameTime gameTime, Camera camera, string drawMode)
 {
     base.PopulateEffectHook(gameTime, camera, drawMode);
     NormalMappedEffect nmEffect = XiHelper.Cast<NormalMappedEffect>(Effect);
     nmEffect.NormalMap = NormalMap;
     nmEffect.NormalMapEnabled = normalMapEnabled;
 }
Ejemplo n.º 2
0
 /// <inheritdoc />
 protected override void DrawHook(GameTime gameTime, Camera camera, string drawMode)
 {
     if (drawMode != "Normal") return;
     PopulateEffect(camera, drawMode);
     // OPTIMIZATION: cache these properties
     GraphicsDevice device = Game.GraphicsDevice;
     ModelMesh mesh = Mesh;
     ModelMeshPart part = Part;
     Effect effect = Effect;
     BeginRenderState();
     effect.Begin();
     foreach (EffectPass pass in effect.CurrentTechnique.Passes)
     {
         pass.Begin();
         device.Vertices[0].SetSource(mesh.VertexBuffer, part.StreamOffset, part.VertexStride);
         device.Indices = mesh.IndexBuffer;
         device.VertexDeclaration = part.VertexDeclaration;
         device.DrawIndexedPrimitives(
             PrimitiveType.TriangleList,
             part.BaseVertex,
             0,
             part.NumVertices,
             part.StartIndex,
             part.PrimitiveCount);
         pass.End();
     }
     effect.End();
     EndRenderState();
 }
Ejemplo n.º 3
0
 /// <inheritdoc />
 protected override void PopulateEffectHook(GameTime gameTime, Camera camera, string drawMode)
 {
     base.PopulateEffectHook(gameTime, camera, drawMode);
     ShadowReceiverEffect srEffect = XiHelper.Cast<ShadowReceiverEffect>(Effect);
     Matrix worldTransform;
     Actor.GetBoneAbsoluteWorld(Mesh.ParentBone.Index, out worldTransform);
     srEffect.PopulateShadowing(this, ref worldTransform, Game.Scene.CachedDirectionalLights);
 }
Ejemplo n.º 4
0
 private void PopulateEffect(Camera camera, string drawMode)
 {
     BasicEffect basicEffect = XiHelper.Cast<BasicEffect>(Effect);
     basicEffect.TrySetCurrentTechnique("BasicEffect");
     PopulateEffectTransform(camera, basicEffect);
     PopulateEffectFogging(basicEffect);
     PopulateEffectLighting(basicEffect);
 }
Ejemplo n.º 5
0
 private static bool IsShadowing(Camera shadowCamera, Surface surface)
 {
     return
         surface.HasDrawProperties(DrawProperties.Shadowing) &&
         (
             surface.Boundless ||
             shadowCamera.Contains(surface.BoundingBox) != ContainmentType.Disjoint
         );
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Populate the transform parameters of a BasicEffect.
 /// </summary>
 /// <param name="camera">The camera from which to extract the view and projection.</param>
 /// <param name="world">The world transform.</param>
 /// <param name="effect">The effect to populate.</param>
 public static void PopulateTransform(this BasicEffect effect, Camera camera, ref Matrix world)
 {
     XiHelper.ArgumentNullCheck(camera);
     Matrix view;
     Matrix projection;
     camera.GetView(out view);
     camera.GetProjection(out projection);
     effect.World = world;
     effect.View = view;
     effect.Projection = projection;
 }
Ejemplo n.º 7
0
 private void PopulateEffectTransform(Camera camera, LightReceiverEffect lrEffect)
 {
     Matrix worldTransform;
     Actor.GetBoneAbsoluteWorld(Mesh.ParentBone.Index, out worldTransform);
     lrEffect.PopulateTransform(camera, ref worldTransform);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// PreDraw the items in the DrawBounds. Must be called once before Draw.
 /// </summary>
 /// <param name="gameTime">The current game time.</param>
 /// <param name="camera">The camera from which the scene is viewed.</param>
 /// <remarks>
 /// Pre-drawing is done in a different phase than normal drawing. This is because of the
 /// following performance constraint -
 /// 
 /// Intermixing scene drawing with pre-drawing involves switching render targets while
 /// persisting their data. Persisting render target data during render target changes
 /// involves copying the render target buffer to temporary texture buffers on the Xbox 360,
 /// then copying it back. This is just too slow so long as the Xbox 360 or a device with
 /// the same constraint is a deployment target.
 /// 
 /// For more info, please read -
 /// http://blogs.msdn.com/shawnhar/archive/2007/11/21/rendertarget-changes-in-xna-game-studio-2-0.aspx
 /// 
 /// At some point it might make sense to have a PreDrawOrder property so that items can be
 /// consistently pre-drawn in a certain order rather than the random order in which they
 /// are found in the scene.
 /// </remarks>        
 public void PreDraw(GameTime gameTime, Camera camera)
 {
     XiHelper.ArgumentNullCheck(gameTime, camera);
     CacheActors();
     CacheLights();
     CacheSurfaces();
     DrawShadows(gameTime, camera);
     PreDrawSurfaces(gameTime, camera);
 }
Ejemplo n.º 9
0
 private void DrawSurfaces(GameTime gameTime, Camera camera, string drawMode)
 {
     game.SurfaceDrawer3D.DrawSurfaces(gameTime, camera, drawMode, cachedSurfaces);
 }
Ejemplo n.º 10
0
 private void PreDrawSurfaces(GameTime gameTime, Camera camera)
 {
     game.SurfaceDrawer3D.PreDrawSurfaces(gameTime, camera, cachedSurfaces);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Draw the shadow map.
 /// </summary>
 /// <param name="gameTime">The current game time.</param>
 /// <param name="camera">The camera from which the scene is viewed.</param>
 public void DrawShadow(GameTime gameTime, Camera camera)
 {
     XiHelper.ArgumentNullCheck(gameTime, camera);
     ConfigureShadowCamera(camera);
     shadow.Draw(gameTime);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Handle predrawing the surface.
 /// </summary>
 protected abstract void DrawHook(GameTime gameTime, Camera camera, string drawMode);
Ejemplo n.º 13
0
 /// <summary>
 /// Draw the surface in a scene using the specified drawing mode.
 /// </summary>
 /// <param name="gameTime">The current game time.</param>
 /// <param name="camera">The camera from which the surface is viewed.</param>
 /// <param name="drawMode">The manner in which to draw the surface.</param>
 public void Draw(GameTime gameTime, Camera camera, string drawMode)
 {
     DrawHook(gameTime, camera, drawMode);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Populate the View, Projection, ViewProjection, and CameraPosition parameters.
 /// </summary>
 public void PopulateTransformWorld(Camera camera)
 {
     XiHelper.ArgumentNullCheck(camera);
     View = camera.View;
     Projection = camera.Projection;
     ViewProjection = camera.ViewProjection;
     CameraPosition = camera.Position;
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Populate the local and world transforms of a BaseEffect.
 /// </summary>
 public void PopulateTransform(Camera camera, ref Matrix world)
 {
     XiHelper.ArgumentNullCheck(camera);
     PopulateTransformLocal(camera, ref world);
     PopulateTransformWorld(camera);
 }
Ejemplo n.º 16
0
 private void PopulateEffect(GameTime gameTime, Camera camera, string drawMode)
 {
     Effect.TrySetCurrentTechnique(drawMode);
     PopulateEffectHook(gameTime, camera, drawMode);
 }
Ejemplo n.º 17
0
 private void ConfigureShadowCamera(Camera camera)
 {
     ConfigureShadowCameraView(camera);
 }
Ejemplo n.º 18
0
 private Vector3 CalculateShadowCameraPosition(Camera camera)
 {
     if (!shadowCameraRelativeToViewCamera) return shadowCameraPosition;
     Vector3 cameraPosition = camera.Position - direction * shadowCameraOffset;
     return shadowCameraSnap != 0 ? cameraPosition.GetSnap(shadowCameraSnap) : cameraPosition;
 }
Ejemplo n.º 19
0
 private void ConfigureShadowCameraView(Camera camera)
 {
     Vector3 position = CalculateShadowCameraPosition(camera), right, up;
     direction.GetComplimentaryOrientationVectors(out up, out right);
     shadow.Camera.SetTransformByLookForward(position, up, direction);
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Populate the World, WorldInverse, and WorldViewProjection parameters.
 /// </summary>
 public void PopulateTransformLocal(Camera camera, ref Matrix world)
 {
     XiHelper.ArgumentNullCheck(camera);
     World = world;
     WorldInverse = world.Determinant() != 0 ? Matrix.Invert(world) : Matrix.Identity;
     WorldViewProjection = world * camera.ViewProjection;
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Handle populating the effect's parameters.
 /// </summary>
 protected virtual void PopulateEffectHook(GameTime gameTime, Camera camera, string drawMode)
 {
     LightReceiverEffect lrEffect = XiHelper.Cast<LightReceiverEffect>(Effect);
     PopulateEffectTransform(camera, lrEffect);
     if (drawMode == "Normal")
     {
         PopulateEffectDiffuseMap(lrEffect);
         PopulateEffectFogging(lrEffect);
         PopulateEffectLighting(lrEffect);
     }
 }
Ejemplo n.º 22
0
 /// <summary>
 /// PreDraw the surface in a scene. See notes on PreDraw in
 /// <see cref="Scene"/>.
 /// </summary>
 /// <param name="gameTime">The current game time.</param>
 /// <param name="camera">The camera from which the surface is viewed.</param>
 public void PreDraw(GameTime gameTime, Camera camera)
 {
     PreDrawHook(gameTime, camera);
 }
Ejemplo n.º 23
0
 /// <inheritdoc />
 protected override void PreDrawHook(GameTime gameTime, Camera camera) { }
Ejemplo n.º 24
0
 /// <summary>
 /// Handle predrawing the surface.
 /// </summary>
 protected abstract void PreDrawHook(GameTime gameTime, Camera camera);
Ejemplo n.º 25
0
 private void DrawShadows(GameTime gameTime, Camera camera)
 {
     foreach (DirectionalLight directionalLight in CachedDirectionalLights)
         if (directionalLight.Enabled && directionalLight.ShadowEnabled)
             directionalLight.DrawShadow(gameTime, camera);
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Draw the items in the DrawingBounds.
 /// </summary>
 /// <param name="gameTime">The current game time.</param>
 /// <param name="camera">The camera from which the scene is viewed.</param>
 /// <param name="drawMode">The manned in which to draw the scene.</param>
 public void Draw(GameTime gameTime, Camera camera, string drawMode)
 {
     DrawSurfaces(gameTime, camera, drawMode);
     ClearSurfaces();
     ClearLights();
     ClearActors();
 }
Ejemplo n.º 27
0
 private void PopulateEffectTransform(Camera camera, BasicEffect basicEffect)
 {
     Matrix worldTransform;
     Actor.GetBoneAbsoluteWorld(Mesh.ParentBone.Index, out worldTransform);
     basicEffect.PopulateTransform(camera, ref worldTransform);
 }