public void QueryForRenderChunks(ref RenderPassDesc desc) { boundingBoxDrawnThisFrame = true; if (!desc.RenderCamera.ViewFrustum.Intersects(boundingBox)) { return; } // Draw bounding boxes GeometryChunk boxChunk = this.parent.Game.Graphics.AllocateGeometryChunk(); boxChunk.Indices = boundingBoxIndexBuffer; boxChunk.VertexStreams.Add(this.boundingBoxVertBuffer); boxChunk.WorldTransform = Matrix.Identity; boxChunk.VertexCount = this.boundingBoxMesh.Length; boxChunk.StartIndex = 0; boxChunk.VertexStreamOffset = 0; boxChunk.PrimitiveCount = 12; // Number of trianges that are required to render a cube. boxChunk.Material = boundingBoxMaterial; boxChunk.RenderTechniqueName = boundingBoxMaterial.CurrentTechnique; boxChunk.Type = PrimitiveType.TriangleList; }
public void QueryForRenderChunks(BoundingFrustum bFrustum, ref Plane clippingPlane, LOD DetailLevel, ref RenderPassDesc desc) { // If a clipping plane exists, check which side the box is on if (null != clippingPlane) { PlaneIntersectionType intersection = clippingPlane.Intersects(this.boundingBox); // If all geometry is on the back side of the plane, then no need to render it if (intersection == PlaneIntersectionType.Back) { return; } } // Check if QuadTree bounding box intersection the current view frustum if (!bFrustum.Intersects(this.boundingBox)) { return; } // Only draw leaves on the tree, never the main tree branches themselves. if (isLeaf) { GeometryChunk chunk = this.Game.Graphics.AllocateGeometryChunk(); chunk.Indices = this.leafPatch.indexBuffers[(int)DetailLevel]; chunk.VertexStreams.Add(terrain.VertexBuffer); chunk.WorldTransform = Matrix.Identity; chunk.VertexCount = this.width * this.width; chunk.StartIndex = 0; chunk.VertexStreamOffset = this.vertexBufferOffset; chunk.PrimitiveCount = this.leafPatch.numTris[(int)DetailLevel]; chunk.Material = this.terrain.Material; if (this.Game.Settings.GraphicsLevel > GraphicsLevel.Low && DetailLevel == LOD.High) { float distanceToBoundingBox = GetDistanceBetweenCameraNearPlaneAndBoundingBox(bFrustum, this.boundingBox); // If the entire terrain patch is far enough from the camera then we lower the shader quality. if (distanceToBoundingBox < QSConstants.MinQuadTreeCubeCenterDistance / 2) { chunk.RenderTechniqueName = "MultiTexturedNormaled"; } else { chunk.RenderTechniqueName = "MultiTextured"; } } else { chunk.RenderTechniqueName = "MultiTextured"; } chunk.CanCreateShadows = false; // Terrain does not cast shadows, it would be very expensive chunk.CanReceiveShadows = true; chunk.Type = PrimitiveType.TriangleList; if (this.terrain.DisplayBoundingBoxes) { // Draw bounding boxes GeometryChunk boxChunk = this.Game.Graphics.AllocateGeometryChunk(); boxChunk.Indices = boundingBoxIndexBuffer; boxChunk.VertexStreams.Add(this.boundingBoxVertBuffer); boxChunk.WorldTransform = Matrix.Identity; boxChunk.VertexCount = this.BoundingBoxMesh.Length; boxChunk.StartIndex = 0; boxChunk.VertexStreamOffset = 0; boxChunk.PrimitiveCount = 12; // Number of trianges that are required to render a cube. boxChunk.Material = boundingBoxMaterial; boxChunk.RenderTechniqueName = boundingBoxMaterial.CurrentTechnique; boxChunk.CanCreateShadows = false; boxChunk.CanReceiveShadows = true; boxChunk.Type = PrimitiveType.TriangleList; } } // If there are branches on this node, move down through them recursively else if (childQuadTrees.Length > 0) { for (int i = 0; i < childQuadTrees.Length; ++i) { childQuadTrees[i].QueryForRenderChunks(bFrustum, ref clippingPlane, DetailLevel, ref desc); } } }