public void Setup(DrawDetails dd, Matrix worldOverride) { if (lightAmbient_ != null) lightAmbient_.SetValue(dd.lightAmbient); if (lightDiffuse_ != null) lightDiffuse_.SetValue(dd.lightDiffuse); if (lightDir_ != null) lightDir_.SetValue(dd.lightDir); if (viewInv_ != null) viewInv_.SetValue(dd.viewInv); if (viewProj_ != null) viewProj_.SetValue(dd.viewProj); if (world_ != null) world_.SetValue(worldOverride); if (worldView_ != null) worldView_.SetValue(worldOverride * dd.view); if (view_ != null) view_.SetValue(dd.view); if (projection_ != null) projection_.SetValue(dd.projection); if (worldViewProj_ != null) worldViewProj_.SetValue(worldOverride * dd.viewProj); if (fogDistance_ != null) fogDistance_.SetValue(dd.fogDistance); if (fogColor_ != null) if (fogColor_.ColumnCount == 3) fogColor_.SetValue(new Vector3(dd.fogColor.X, dd.fogColor.Y, dd.fogColor.Z)); else fogColor_.SetValue(dd.fogColor); if (fogHeight_ != null) fogHeight_.SetValue(dd.fogHeight); if (fogDepth_ != null) fogDepth_.SetValue(dd.fogDepth); if (frame_ != null) frame_.SetValue(dd.frame); if (pose_ != null) pose_.SetValue(PoseData); }
public void CopyTo(DrawDetails o) { o.dev = dev; o.world = world; o.worldView = worldView; o.view = view; o.viewProj = viewProj; o.viewInv = viewInv; o.projection = projection; o.lightDir = lightDir; o.lightDiffuse = lightDiffuse; o.lightAmbient = lightAmbient; o.fogDistance = fogDistance; o.fogColor = fogColor; o.fogHeight = fogHeight; o.fogDepth = fogDepth; o.frame = frame; }
public void Setup(DrawDetails dd, Matrix worldOverride) { if (lightAmbient_ != null) { lightAmbient_.SetValue(dd.lightAmbient); } if (lightDiffuse_ != null) { lightDiffuse_.SetValue(dd.lightDiffuse); } if (lightDir_ != null) { lightDir_.SetValue(dd.lightDir); } if (viewInv_ != null) { viewInv_.SetValue(dd.viewInv); } if (viewProj_ != null) { viewProj_.SetValue(dd.viewProj); } if (world_ != null) { world_.SetValue(worldOverride); } if (worldView_ != null) { worldView_.SetValue(worldOverride * dd.view); } if (view_ != null) { view_.SetValue(dd.view); } if (projection_ != null) { projection_.SetValue(dd.projection); } if (worldViewProj_ != null) { worldViewProj_.SetValue(worldOverride * dd.viewProj); } if (fogDistance_ != null) { fogDistance_.SetValue(dd.fogDistance); } if (fogColor_ != null) { if (fogColor_.ColumnCount == 3) { fogColor_.SetValue(new Vector3(dd.fogColor.X, dd.fogColor.Y, dd.fogColor.Z)); } else { fogColor_.SetValue(dd.fogColor); } } if (fogHeight_ != null) { fogHeight_.SetValue(dd.fogHeight); } if (fogDepth_ != null) { fogDepth_.SetValue(dd.fogDepth); } if (frame_ != null) { frame_.SetValue(dd.frame); } if (pose_ != null) { pose_.SetValue(PoseData); } }
public void Setup(DrawDetails dd) { Setup(dd, dd.world); }
public void Setup(DrawDetails dd, Matrix worldOverride) { if (lightAmbient_ != null) { lightAmbient_.SetValue(dd.lightAmbient); } if (lightDiffuse_ != null) { lightDiffuse_.SetValue(dd.lightDiffuse); } if (environmentTexture_ != null) { environmentTexture_.SetValue(dd.environmentTexture); } if (lightDir_ != null) { lightDir_.SetValue(dd.lightDir); } if (viewInv_ != null) { viewInv_.SetValue(dd.viewInv); } if (viewProj_ != null) { viewProj_.SetValue(dd.viewProj); } if (world_ != null) { world_.SetValue(worldOverride); } if (worldView_ != null) { worldView_.SetValue(worldOverride * dd.view); } if (view_ != null) { view_.SetValue(dd.view); } if (projection_ != null) { projection_.SetValue(dd.projection); } if (worldViewProj_ != null) { worldViewProj_.SetValue(worldOverride * dd.viewProj); } if (fogDistance_ != null) { fogDistance_.SetValue(dd.fogDistance); } if (fogColor_ != null) { if (fogColor_.ColumnCount == 3) { fogColor_.SetValue(new Vector3(dd.fogColor.X, dd.fogColor.Y, dd.fogColor.Z)); } else { fogColor_.SetValue(dd.fogColor); } } if (fogHeight_ != null) { fogHeight_.SetValue(dd.fogHeight); } if (fogDepth_ != null) { fogDepth_.SetValue(dd.fogDepth); } if (frame_ != null) { frame_.SetValue(dd.frame); } if (time_ != null) { time_.SetValue(dd.time); } if (pose_ != null) { pose_.SetValue(PoseData); } dd.dev.RenderState.PointSpriteEnable = pointsprites_; }
// do the device and effect magic to render a given chunk of geometry private void DrawChunk(DrawDetails dd, Chunk ch) { // configure the device and actually draw dd.dev.Indices = ch.Mesh.IndexBuffer; dd.dev.VertexDeclaration = ch.Part.VertexDeclaration; dd.dev.Vertices[0].SetSource(ch.Mesh.VertexBuffer, ch.Part.StreamOffset, ch.Part.VertexStride); // note: calculating the world matrix overrides the previous value, hence the use // of the saved copy of the world transform Matrix.Multiply(ref matrices_[ch.Mesh.ParentBone.Index], ref world_, out dd.world); ch.Fx.Setup(dd); ch.Fx.FX.Begin(); // be lazy and save state EffectTechnique et = ch.Fx.FX.CurrentTechnique; // most my effects are single-pass, but at least transparency is multi-pass for (int i = 0, n = et.Passes.Count; i != n; ++i) { EffectPass ep = et.Passes[i]; ep.Begin(); dd.dev.DrawIndexedPrimitives(PrimitiveType.TriangleList, ch.Part.BaseVertex, 0, ch.Part.NumVertices, ch.Part.StartIndex, ch.Part.PrimitiveCount); ep.End(); } ch.Fx.FX.End(); }
// Draw helper that actually issues geometry, or defers for later. internal bool Draw(DrawDetails dd, bool asDeferred) { // keep a copy of world, because I override it in the DrawDetails bool added = false; // each chunk is drawn separately, as it represents a different // shader set-up (world transform, texture, etc). foreach (Chunk ch in chunks_) { if (asDeferred) { // If I'm called back to draw deferred pieces, don't draw if this // piece is not deferred. if (!ch.Deferred) continue; } else if (ch.Deferred) { added = true; continue; } DrawChunk(dd, ch); } return added; }
// callback for transparent drawing public void SceneDrawTransparent(DrawDetails dd) { Draw(dd, true); }
// Only call Draw() once per object instance per frame. Else // transparently sorted pieces won't draw correctly, as there is // only one set of state per ModelDraw. Use multiple ModelDraw // instances for multiple object instances. // Immediately draw the parts that do not require transparency. // put parts that need transparency on a deferred list, to be // drawn later (z sorted) using DrawDeferred(). public bool SceneDraw(DrawDetails dd) { // if animating, then pose it if (instance_ != null) { Matrix temp; Keyframe[] kfs = instance_.CurrentPose; unchecked { int i = 0, n = matrices_.Length; foreach (Keyframe kf in kfs) { if (i == n) break; if (kf != null) { kf.ToMatrix(out temp); // set up the model in parent-relative pose model_.Bones[i].Transform = temp; } ++i; } } } // get the object-relative matrices (object->world is separate) model_.CopyAbsoluteBoneTransformsTo(matrices_); #if DRAW_SKELETON // draw the skeleton, but only in debug mode foreach (ModelBone mb in model_.Bones) { if (mb.Parent != null) { Matrix m = matrices_[mb.Index]; Vector3 c = m.Translation; DebugLines.Global.AddLine( c, matrices_[mb.Parent.Index].Translation, Color.White); DebugLines.Global.AddLine( c, c + m.Right * 0.5f, Color.Red); DebugLines.Global.AddLine( c, c + m.Up * 0.5f, Color.Green); DebugLines.Global.AddLine( c, c + m.Backward * 0.5f, Color.Blue); } } #endif // If I have a 3x4 matrix pose, then generate that for skinning if (pose_ != null) GeneratePose(); // chain to an internal helper return Draw(dd, false); }