private void BuildRenderItems() { AddRenderItem(RenderLayer.Sky, 0, "sky", "shapeGeo", "sphere", world: Matrix.Scaling(5000.0f)); _skullRitem = AddRenderItem(RenderLayer.Opaque, 1, "skullMat", "skullGeo", "skull"); AddRenderItem(RenderLayer.Opaque, 2, "bricks0", "shapeGeo", "box", world: Matrix.Scaling(2.0f, 1.0f, 2.0f) * Matrix.Translation(0.0f, 0.5f, 0.0f), texTransform: Matrix.Scaling(1.0f, 0.5f, 1.0f)); AddRenderItem(RenderLayer.OpaqueDynamicReflectors, 3, "mirror0", "shapeGeo", "sphere", world: Matrix.Scaling(2.0f) * Matrix.Translation(0.0f, 2.0f, 0.0f)); AddRenderItem(RenderLayer.Opaque, 4, "tile0", "shapeGeo", "grid", texTransform: Matrix.Scaling(8.0f, 8.0f, 1.0f)); Matrix brickTexTransform = Matrix.Scaling(1.5f, 2.0f, 1.0f); int objCBIndex = 5; for (int i = 0; i < 5; ++i) { AddRenderItem(RenderLayer.Opaque, objCBIndex++, "bricks0", "shapeGeo", "cylinder", world: Matrix.Translation(-5.0f, 1.5f, -10.0f + i * 5.0f), texTransform: brickTexTransform); AddRenderItem(RenderLayer.Opaque, objCBIndex++, "bricks0", "shapeGeo", "cylinder", world: Matrix.Translation(+5.0f, 1.5f, -10.0f + i * 5.0f), texTransform: brickTexTransform); AddRenderItem(RenderLayer.Opaque, objCBIndex++, "mirror0", "shapeGeo", "sphere", world: Matrix.Translation(-5.0f, 3.5f, -10.0f + i * 5.0f)); AddRenderItem(RenderLayer.Opaque, objCBIndex++, "mirror0", "shapeGeo", "sphere", world: Matrix.Translation(+5.0f, 3.5f, -10.0f + i * 5.0f)); } }
private void BuildRenderItems() { _skullRitem = AddRenderItem(RenderLayer.Opaque, 0, "skullMat", "skullGeo", "skull", world: Matrix.Scaling(0.5f) * Matrix.Translation(0.0f, 1.0f, 0.0f)); AddRenderItem(RenderLayer.Opaque, 1, "stone0", "shapeGeo", "box", world: Matrix.Scaling(3.0f, 1.0f, 3.0f) * Matrix.Translation(0.0f, 0.5f, 0.0f)); AddRenderItem(RenderLayer.Opaque, 2, "tile0", "shapeGeo", "grid", texTransform: Matrix.Scaling(8.0f, 8.0f, 1.0f)); Matrix brickTexTransform = Matrix.Scaling(1.5f, 2.0f, 1.0f); int objCBIndex = 3; for (int i = 0; i < 5; ++i) { AddRenderItem(RenderLayer.Opaque, objCBIndex++, "bricks0", "shapeGeo", "cylinder", world: Matrix.Translation(-5.0f, 1.5f, -10.0f + i * 5.0f), texTransform: brickTexTransform); AddRenderItem(RenderLayer.Opaque, objCBIndex++, "bricks0", "shapeGeo", "cylinder", world: Matrix.Translation(+5.0f, 1.5f, -10.0f + i * 5.0f), texTransform: brickTexTransform); AddRenderItem(RenderLayer.Opaque, objCBIndex++, "stone0", "shapeGeo", "sphere", world: Matrix.Translation(-5.0f, 3.5f, -10.0f + i * 5.0f)); AddRenderItem(RenderLayer.Opaque, objCBIndex++, "stone0", "shapeGeo", "sphere", world: Matrix.Translation(+5.0f, 3.5f, -10.0f + i * 5.0f)); } }
private void BuildRenderItems() { MeshGeometry geo = _geometries["carGeo"]; SubmeshGeometry submesh = geo.DrawArgs["car"]; var carRitem = new RenderItem { World = Matrix.Translation(0.0f, 1.0f, 0.0f), ObjCBIndex = 0, Mat = _materials["gray0"], Geo = geo, IndexCount = submesh.IndexCount, StartIndexLocation = submesh.StartIndexLocation, BaseVertexLocation = submesh.BaseVertexLocation, Bounds = submesh.Bounds }; _ritemLayer[RenderLayer.Opaque].Add(carRitem); _allRitems.Add(carRitem); _pickedRitem = new RenderItem { ObjCBIndex = 1, Mat = _materials["highlight0"], Geo = geo, // Picked triangle is not visible until one is picked. Visible = false, // DrawCall parameters are filled out when a triangle is picked. IndexCount = 0, StartIndexLocation = 0, BaseVertexLocation = 0 }; _ritemLayer[RenderLayer.Highlight].Add(_pickedRitem); _allRitems.Add(_pickedRitem); }
private void BuildRenderItems() { _wavesRitem = AddRenderItem(RenderLayer.Transparent, 0, "water", "waterGeo", "grid", texTransform: Matrix.Scaling(5.0f, 5.0f, 1.0f)); AddRenderItem(RenderLayer.Opaque, 1, "grass", "landGeo", "grid", texTransform: Matrix.Scaling(5.0f, 5.0f, 1.0f)); AddRenderItem(RenderLayer.AlphaTested, 2, "wirefence", "boxGeo", "box", world: Matrix.Translation(3.0f, 2.0f, -9.0f)); }
private void BuildRenderItems() { MeshGeometry geo = _geometries["skullGeo"]; SubmeshGeometry submesh = geo.DrawArgs["skull"]; var skullRitem = new RenderItem { ObjCBIndex = 0, Mat = _materials["tile0"], Geo = _geometries["skullGeo"], IndexCount = submesh.IndexCount, StartIndexLocation = submesh.StartIndexLocation, BaseVertexLocation = submesh.BaseVertexLocation, Bounds = submesh.Bounds }; // Instance count for the render item is set during update based on frustum culling. // Generate instance data. const int n = 5; skullRitem.Instances = new InstanceData[n * n * n]; const float width = 200.0f; const float height = 200.0f; const float depth = 200.0f; const float x = -0.5f * width; const float y = -0.5f * height; const float z = -0.5f * depth; const float dx = width / (n - 1); const float dy = height / (n - 1); const float dz = depth / (n - 1); for (int k = 0; k < n; k++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { int index = k * n * n + i * n + j; // Position instanced along a 3D grid. skullRitem.Instances[index].World = new Matrix( 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, x + j * dx, y + i * dy, z + k * dz, 1.0f); skullRitem.Instances[index].TexTransform = Matrix.Scaling(2.0f, 2.0f, 1.0f); skullRitem.Instances[index].MaterialIndex = index % _materials.Count; } } } _allRitems.Add(skullRitem); // All the render items are opaque. _ritemLayers[RenderLayer.Opaque].AddRange(_allRitems); }
private void BuildRenderItems() { _wavesRitem = AddRenderItem(RenderLayer.Transparent, 0, "water", "waterGeo", "grid", texTransform: Matrix.Scaling(5.0f, 5.0f, 1.0f)); AddRenderItem(RenderLayer.Opaque, 1, "grass", "landGeo", "grid", texTransform: Matrix.Scaling(5.0f, 5.0f, 1.0f)); AddRenderItem(RenderLayer.AlphaTested, 2, "wirefence", "boxGeo", "box", world: Matrix.Translation(3.0f, 2.0f, -9.0f)); AddRenderItem(RenderLayer.AlphaTestedTreeSprites, 3, "treeSprites", "treeSpritesGeo", "points", topology: PrimitiveTopology.PointList); }
private void BuildRenderItems() { AddRenderItem(RenderLayer.Opaque, 0, "checkertile", "roomGeo", "floor"); AddRenderItem(RenderLayer.Opaque, 1, "bricks", "roomGeo", "wall"); _skullRitem = AddRenderItem(RenderLayer.Opaque, 2, "skullMat", "skullGeo", "skull"); // Reflected skull will have different world matrix, so it needs to be its own render item. _reflectedSkullRitem = AddRenderItem(RenderLayer.Reflected, 3, "skullMat", "skullGeo", "skull"); // Shadowed skull will have different world matrix, so it needs to be its own render item. _shadowedSkullRitem = AddRenderItem(RenderLayer.Shadow, 4, "shadowMat", "skullGeo", "skull"); AddRenderItem(RenderLayer.Mirrors, 5, "icemirror", "roomGeo", "mirror"); AddRenderItem(RenderLayer.Transparent, 6, "icemirror", "roomGeo", "mirror"); }
private void AddRenderItem(RenderLayer layer, int objCBIndex, string geoName, string submeshName, Matrix?world = null) { MeshGeometry geo = _geometries[geoName]; SubmeshGeometry submesh = geo.DrawArgs[submeshName]; var renderItem = new RenderItem { ObjCBIndex = objCBIndex, Geo = geo, IndexCount = submesh.IndexCount, StartIndexLocation = submesh.StartIndexLocation, BaseVertexLocation = submesh.BaseVertexLocation, World = world ?? Matrix.Identity }; _ritemLayers[layer].Add(renderItem); _allRitems.Add(renderItem); }
private RenderItem AddRenderItem(RenderLayer layer, int objCBIndex, string geoName, string submeshName) { MeshGeometry geo = _geometries[geoName]; SubmeshGeometry submesh = geo.DrawArgs[submeshName]; var renderItem = new RenderItem { ObjCBIndex = objCBIndex, Geo = geo, IndexCount = submesh.IndexCount, StartIndexLocation = submesh.StartIndexLocation, BaseVertexLocation = submesh.BaseVertexLocation }; _ritemLayers[layer].Add(renderItem); _allRitems.Add(renderItem); return(renderItem); }
private void BuildRenderItems() { MeshGeometry geo = _geometries["boxGeo"]; SubmeshGeometry submesh = geo.DrawArgs["box"]; var boxRitem = new RenderItem { ObjCBIndex = 0, Mat = _materials["woodCrate"], Geo = geo, PrimitiveType = PrimitiveTopology.TriangleList, IndexCount = submesh.IndexCount, StartIndexLocation = submesh.StartIndexLocation, BaseVertexLocation = submesh.BaseVertexLocation }; _allRitems.Add(boxRitem); // All the render items are opaque. _ritemLayers[RenderLayer.Opaque].AddRange(_allRitems); }
private void BuildRenderItems() { MeshGeometry geo = _geometries["quadpatchGeo"]; SubmeshGeometry submesh = geo.DrawArgs["quadpatch"]; var quadPatchRitem = new RenderItem { World = Matrix.Identity, TexTransform = Matrix.Identity, ObjCBIndex = 0, Mat = _materials["whiteMat"], Geo = geo, PrimitiveType = PrimitiveTopology.PatchListWith16ControlPoints, IndexCount = submesh.IndexCount, StartIndexLocation = submesh.StartIndexLocation, BaseVertexLocation = submesh.BaseVertexLocation }; _ritemLayers[RenderLayer.Opaque].Add(quadPatchRitem); _allRitems.Add(quadPatchRitem); }
private RenderItem AddRenderItem(RenderLayer layer, int objCBIndex, string matName, string geoName, string submeshName, Matrix?world = null, Matrix?texTransform = null, PrimitiveTopology topology = PrimitiveTopology.TriangleList) { MeshGeometry geo = _geometries[geoName]; SubmeshGeometry submesh = geo.DrawArgs[submeshName]; var renderItem = new RenderItem { ObjCBIndex = objCBIndex, Mat = _materials[matName], Geo = geo, IndexCount = submesh.IndexCount, StartIndexLocation = submesh.StartIndexLocation, BaseVertexLocation = submesh.BaseVertexLocation, World = world ?? Matrix.Identity, TexTransform = texTransform ?? Matrix.Identity, PrimitiveType = topology }; _ritemLayers[layer].Add(renderItem); _allRitems.Add(renderItem); return(renderItem); }
private void AddRenderItem(RenderLayer layer, int objCBIndex, string matName, string geoName, string submeshName, Matrix?world = null, Matrix?texTransform = null, Vector2?dmTexelSize = null, float?gridSpatialStep = null) { MeshGeometry geo = _geometries[geoName]; SubmeshGeometry submesh = geo.DrawArgs[submeshName]; var renderItem = new RenderItem { ObjCBIndex = objCBIndex, Mat = _materials[matName], Geo = geo, IndexCount = submesh.IndexCount, StartIndexLocation = submesh.StartIndexLocation, BaseVertexLocation = submesh.BaseVertexLocation }; if (world.HasValue) { renderItem.World = world.Value; } if (texTransform.HasValue) { renderItem.TexTransform = texTransform.Value; } if (dmTexelSize.HasValue) { renderItem.DisplacementMapTexelSize = dmTexelSize.Value; } if (gridSpatialStep.HasValue) { renderItem.GridSpatialStep = gridSpatialStep.Value; } _ritemLayers[layer].Add(renderItem); _allRitems.Add(renderItem); }
private void BuildRenderItems() { _wavesRitem = AddRenderItem(RenderLayer.Opaque, 0, "waterGeo", "grid"); AddRenderItem(RenderLayer.Opaque, 1, "landGeo", "grid"); }