/// <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; }
/// <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(); }
/// <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); }
private void PopulateEffect(Camera camera, string drawMode) { BasicEffect basicEffect = XiHelper.Cast<BasicEffect>(Effect); basicEffect.TrySetCurrentTechnique("BasicEffect"); PopulateEffectTransform(camera, basicEffect); PopulateEffectFogging(basicEffect); PopulateEffectLighting(basicEffect); }
private static bool IsShadowing(Camera shadowCamera, Surface surface) { return surface.HasDrawProperties(DrawProperties.Shadowing) && ( surface.Boundless || shadowCamera.Contains(surface.BoundingBox) != ContainmentType.Disjoint ); }
/// <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; }
private void PopulateEffectTransform(Camera camera, LightReceiverEffect lrEffect) { Matrix worldTransform; Actor.GetBoneAbsoluteWorld(Mesh.ParentBone.Index, out worldTransform); lrEffect.PopulateTransform(camera, ref worldTransform); }
/// <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); }
private void DrawSurfaces(GameTime gameTime, Camera camera, string drawMode) { game.SurfaceDrawer3D.DrawSurfaces(gameTime, camera, drawMode, cachedSurfaces); }
private void PreDrawSurfaces(GameTime gameTime, Camera camera) { game.SurfaceDrawer3D.PreDrawSurfaces(gameTime, camera, cachedSurfaces); }
/// <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); }
/// <summary> /// Handle predrawing the surface. /// </summary> protected abstract void DrawHook(GameTime gameTime, Camera camera, string drawMode);
/// <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); }
/// <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; }
/// <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); }
private void PopulateEffect(GameTime gameTime, Camera camera, string drawMode) { Effect.TrySetCurrentTechnique(drawMode); PopulateEffectHook(gameTime, camera, drawMode); }
private void ConfigureShadowCamera(Camera camera) { ConfigureShadowCameraView(camera); }
private Vector3 CalculateShadowCameraPosition(Camera camera) { if (!shadowCameraRelativeToViewCamera) return shadowCameraPosition; Vector3 cameraPosition = camera.Position - direction * shadowCameraOffset; return shadowCameraSnap != 0 ? cameraPosition.GetSnap(shadowCameraSnap) : cameraPosition; }
private void ConfigureShadowCameraView(Camera camera) { Vector3 position = CalculateShadowCameraPosition(camera), right, up; direction.GetComplimentaryOrientationVectors(out up, out right); shadow.Camera.SetTransformByLookForward(position, up, direction); }
/// <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; }
/// <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); } }
/// <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); }
/// <inheritdoc /> protected override void PreDrawHook(GameTime gameTime, Camera camera) { }
/// <summary> /// Handle predrawing the surface. /// </summary> protected abstract void PreDrawHook(GameTime gameTime, Camera camera);
private void DrawShadows(GameTime gameTime, Camera camera) { foreach (DirectionalLight directionalLight in CachedDirectionalLights) if (directionalLight.Enabled && directionalLight.ShadowEnabled) directionalLight.DrawShadow(gameTime, camera); }
/// <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(); }
private void PopulateEffectTransform(Camera camera, BasicEffect basicEffect) { Matrix worldTransform; Actor.GetBoneAbsoluteWorld(Mesh.ParentBone.Index, out worldTransform); basicEffect.PopulateTransform(camera, ref worldTransform); }