public Terrain() { Transformation.SetScale(Vector3.One * TerrainSize); Transformation.SetPosition(Vector3.Up * TerrainSize * 0.45f); GenerateFloatingIslands(256); terrainMaterial = ResourceManager.Inst.GetMaterial("TerrainMaterial"); }
void DrawElement(Material key) { while (Elements[key].Count > 0) { RenderElement currElem = Elements[key].Dequeue(); if (currElem.VertexDec != GFX.Device.VertexDeclaration) GFX.Device.VertexDeclaration = currElem.VertexDec; GFX.Device.Indices = currElem.IndexBuffer; GFX.Device.Vertices[0].SetSource(currElem.VertexBuffer, 0, currElem.VertexStride); for (int j = 0; j < currElem.Transform.Length; j += GFXShaderConstants.NUM_INSTANCES) { int binLength = currElem.Transform.Length - j; if (binLength > GFXShaderConstants.NUM_INSTANCES) binLength = GFXShaderConstants.NUM_INSTANCES; if (currElem.Transform.Length > 1) { // Upload transform matrices as shader constants. Array.Copy(currElem.Transform, j, tempTransforms, 0, binLength); GFX.Device.SetVertexShaderConstant(GFXShaderConstants.VC_WORLD, tempTransforms); } else { GFX.Device.SetVertexShaderConstant(GFXShaderConstants.VC_WORLD, currElem.Transform); } GFX.Device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, currElem.StartVertex, currElem.VertexCount * binLength, 0, currElem.PrimitiveCount * binLength); } } }
public override void OnAdd(Scene scene) { this.Transformation.SetScale(30*Vector3.One); this.Transformation.SetPosition(Vector3.Transform(Vector3.Up * 0.45f, scene.MainTerrain.Transformation.GetTransform())); gateMaterial = ResourceManager.Inst.GetMaterial("GateMaterial"); GenerateGeometry(); base.OnAdd(scene); }
public TerrainVoxel() { Transformation.SetScale(Vector3.One * TerrainSize); Transformation.SetPosition(Vector3.Up * TerrainSize * 0.25f); GenerateFloatingIslands(128); terrainMaterial = ResourceManager.Inst.GetMaterial("TerrainMaterial"); climate = ResourceManager.Inst.GetTerrainClimate("TestTerrain"); PrepareTriangles(); }
public TerrainVoxel(string filename) { Transformation.SetScale(new Vector3(1, 0.25f, 1) * TerrainSize); Transformation.SetPosition(Vector3.Up * TerrainSize * 0.0725f); terrainMaterial = ResourceManager.Inst.GetMaterial("TerrainMaterial"); climate = ResourceManager.Inst.GetTerrainClimate("TestTerrain"); GenerateTerrainFromFile(filename); }
public override void AddElement(Material material, RenderElement element) { if (material.IsFoliage) { FoliageElementManager mgr = (FoliageElementManager)ElementManagers[RenderPass.Foliage]; mgr.AddElement(material, element); } SceneElementManager sceneMgr = (SceneElementManager)ElementManagers[RenderPass.Scene]; sceneMgr.AddElement(material, element); }
public TerrainVoxel() { Transformation.SetScale(new Vector3(1, 0.25f, 1) * TerrainSize); Transformation.SetPosition(Vector3.Up * TerrainSize * 0.22f); //GenerateFloatingIslands(128); GenerateTerrainProcedurally(); terrainMaterial = ResourceManager.Inst.GetMaterial("TerrainMaterial"); climate = ResourceManager.Inst.GetTerrainClimate("TestTerrain"); PrepareTriangles(); TransformLandmarks(); }
public override void OnAdd(Scene scene) { grassMaterial = ResourceManager.Inst.GetMaterial("3DGrassMaterial"); int grassCount = 15; grassGeometries = new GrassGeometry[grassCount]; grassHighDetail = new RenderElement[grassCount]; for (int i = 0; i < grassGeometries.Length; i++) { grassGeometries[i] = new GrassGeometry(); grassHighDetail[i] = grassGeometries[i].GetHighDetail(); } base.OnAdd(scene); }
public Projectile(Actor sender, string tracerEffectName, string explosionEffectName) { this.sender = sender; renderElement = new RenderElement(); renderElement.IndexBuffer = GFXPrimitives.SphereGeometry.Geometry.renderElement.IndexBuffer; renderElement.VertexBuffer = GFXPrimitives.SphereGeometry.Geometry.renderElement.VertexBuffer; renderElement.VertexCount = GFXPrimitives.SphereGeometry.Geometry.renderElement.VertexCount; renderElement.VertexDec = GFXPrimitives.SphereGeometry.Geometry.renderElement.VertexDec; renderElement.VertexStride = GFXPrimitives.SphereGeometry.Geometry.renderElement.VertexStride; renderElement.StartVertex = GFXPrimitives.SphereGeometry.Geometry.renderElement.StartVertex; renderElement.PrimitiveCount = GFXPrimitives.SphereGeometry.Geometry.renderElement.PrimitiveCount; projectileMaterial = ResourceManager.Inst.GetMaterial("GateMaterial"); //tracerEffect = ResourceManager.Inst.GetParticleEffect(tracerEffectName); explosionEffect = ResourceManager.Inst.GetParticleEffect(explosionEffectName); }
public override void OnAdd(Scene scene) { gemMaterial = ResourceManager.Inst.GetMaterial("GemMaterial"); Vector3 randPosition = Vector3.Zero; Vector3 randNormal = Vector3.Zero; randomHelper.NextDouble(); randomHelper.NextDouble(); scene.MainTerrain.GenerateRandomTransform(randomHelper, out randPosition, out randNormal); while (randPosition.Y < 2.0f || Vector3.Dot(randNormal, Vector3.Up) < 0.3f) { scene.MainTerrain.GenerateRandomTransform(randomHelper, out randPosition, out randNormal); } base.OnAdd(scene); generateGem(randPosition); scene.Entities.Add(emitterLight); }
public override void AddElement(Material material, RenderElement element) { if (material.IsTranslucent) { PostProcessElementManager ppMgr = (PostProcessElementManager)ElementManagers[RenderPass.PostProcess]; ppMgr.AddElement(material, element); /* SceneElementManager gbufferTrans = (SceneElementManager)ElementManagers[RenderPass.TransparentGBuffer]; SceneElementManager colorTrans = (SceneElementManager)ElementManagers[RenderPass.TransparentColor]; gbufferTrans.AddElement(material, element); colorTrans.AddElement(material, element); */ } else { if (material.IsDoubleSided) { SceneElementManager doubleMgr = (SceneElementManager)ElementManagers[RenderPass.SceneNoCull]; doubleMgr.AddElement(material, element); } /* if (material.IsFoliage) { FoliageElementManager mgr = (FoliageElementManager)ElementManagers[RenderPass.Foliage]; mgr.AddElement(material, element); }*/ if (material.IsEmissive) { Material mat = ResourceManager.Inst.GetMaterial(material.EmissiveMaterial); if (mat == null) mat = material; SceneElementManager glowMgr = (SceneElementManager)ElementManagers[RenderPass.Emissive]; glowMgr.AddElement(mat, element); } else { SceneElementManager sceneMgr = (SceneElementManager)ElementManagers[RenderPass.Scene]; sceneMgr.AddElement(material, element); } } }
public override void AddElement(Material material, RenderElement element) { if (material.IsTranslucent) { //TransparentElementManager transMgr = (TransparentElementManager)ElementManagers[RenderPass.Translucent]; //transMgr.AddElement(material, element); } else { if (material.IsEmissive) { //We don't render glowy materials in reflections... } else { SceneElementManager sceneMgr = (SceneElementManager)ElementManagers[RenderPass.Scene]; sceneMgr.AddElement(material, element); } } }
void IResource.LoadFromXML(XmlNode node) { foreach (XmlAttribute attrib in node.Attributes) { switch (attrib.Name.ToLower()) { case "size": size = float.Parse(attrib.Value); break; case "sizevariance": sizeVariance = float.Parse(attrib.Value); break; case "density": densityRatio = float.Parse(attrib.Value); break; case "initialdirection": initialDirection = ParseUtils.ParseVector3(attrib.Value); break; case "initialspeed": initialSpeed = float.Parse(attrib.Value); break; case "initialspeedvariance": initialSpeedVariance = float.Parse(attrib.Value); break; case "fadeinpercent": fadeInPercent = float.Parse(attrib.Value); fadeInCoeff = 1.0f / fadeInPercent; break; case "fadeoutpercent": fadeOutPercent = float.Parse(attrib.Value); fadeOutCoeff = 1.0f / (1.0f - fadeOutPercent); break; case "randominitspeed": randomInitSpeed = float.Parse(attrib.Value); break; case "lifetime": lifetime = float.Parse(attrib.Value); break; case "lifetimevariance": lifetimeVariance = float.Parse(attrib.Value); break; case "mass" : mass = float.Parse(attrib.Value); break; case "massvariance": massVariance = float.Parse(attrib.Value); break; case "material": material = ResourceManager.Inst.GetMaterial(attrib.Value); break; case "randomoffset": offsetParameters = new Vector4(ParseUtils.ParseVector3(attrib.Value), offsetParameters.W); break; case "offsetmagnitude": offsetParameters.W = float.Parse(attrib.Value); break; case "name": name = attrib.Value; break; case "color": color = ParseUtils.ParseVector3(attrib.Value); break; } } }
public void AddDecalElement(Material material, Matrix transform) { DecalElementManager decal = (DecalElementManager)ElementManagers[RenderPass.Decal]; decal.AddElement(material, transform); }
public Imposter(Mesh mesh) { Element = new RenderElement(); Element.IndexBuffer = GFXPrimitives.ImposterGeometry.GetInstanceIndexBuffer(); Element.IsAnimated = false; Element.PrimitiveCount = 8; Element.StartVertex = 0; Element.VertexBuffer = GFXPrimitives.ImposterGeometry.GetInstanceVertexBuffer(); Element.VertexCount = 16; Element.VertexDec = GFXVertexDeclarations.PTIDec; Element.VertexStride = VertexPTI.SizeInBytes; //GFXPrimitives.CreateBillboardElement(); ImposterMaterial = new Material(); Vector3 scale = (mesh.GetBounds().Max - mesh.GetBounds().Min); Scale = Matrix.CreateScale(scale); }
public void SetMaterial(string materialName) { material = ResourceManager.Inst.GetMaterial(materialName); }
public ModelPart(string materialName, VertexBuffer vb, IndexBuffer ib, BoundingBox bb) { this.material = ResourceManager.Inst.GetMaterial(materialName); this.vertexBuffer = vb; this.indexBuffer = ib; this.bounds = bb; }
public void AddElement(Material material, ParticleEmitter element) { if (!Elements.ContainsKey(material)) Elements.Add(material, new CustomList<ParticleEmitter>()); Elements[material].Add(element); }
void BuildTerrain() { terrainMaterial = ResourceManager.Inst.GetMaterial("NULL"); Texture2D[] blendTextures = new Texture2D[blendMaps.Length]; for(int i = 0; i < blendTextures.Length; i++) blendTextures[i] = blendMaps[i].GetTexture(); clips = new Clipmap[L]; for (int i = 0; i < L; i++) clips[i] = new Clipmap(i, this); terrainElement = new TerrainRenderElement(); terrainElement.clips = clips; terrainElement.N = this.N; terrainElement.BlendMaps = blendTextures; terrainElement.NormalMap = normalTexture; }
void InitializeVoxels() { terrainMaterial = ResourceManager.Inst.GetMaterial("TerrainMaterial"); int voxelCount = WorldFieldSize / VoxelGridSize; float blockScale = WorldFieldSize * TerrainSize / VoxelGridSize; GenerateNoiseTextures(); DensityFieldSize = VoxelGridSize + 1; srcTarget = new RenderTarget2D(GFX.Device, DensityFieldSize, DensityFieldSize, 1, GFX.Inst.ByteSurfaceFormat); DensityField = new byte[DensityFieldSize * DensityFieldSize * DensityFieldSize]; Vector3 halfShift = Vector3.One*voxelCount*0.5f; for (int z = 0; z < voxelCount; z++) { int zOff = voxelCount * voxelCount * z; for (int y = 0; y < voxelCount; y++) { int yOff = voxelCount * y; for (int x = 0; x < voxelCount; x++) { int idx = x + yOff + zOff; BoundingBox bounds = new BoundingBox(Vector3.One*-1, Vector3.One); Vector3 pos = new Vector3(x,y,z)-halfShift; Matrix worldMat = Matrix.CreateScale(blockScale); worldMat.Translation = pos * blockScale; bounds.Min = Vector3.Transform(bounds.Min, worldMat); bounds.Max = Vector3.Transform(bounds.Max, worldMat); VoxelBounds.Add(idx, bounds); EvaluateDensityFunction(Matrix.CreateTranslation(pos / halfShift)); Voxels.Add(idx, new VoxelGeometry()); Voxels[idx].renderElement.Transform = new Matrix[1] { worldMat }; Voxels[idx].GenerateGeometry(ref DensityField, IsoValue, DensityFieldSize, DensityFieldSize, DensityFieldSize, VoxelGridSize, VoxelGridSize, VoxelGridSize, 0, 0, 0, 2.0f); } } } }
void InitializeVoxels() { int voxelCountX = (DensityFieldWidth - 1) / VoxelGridSize; int voxelCountY = (DensityFieldHeight - 1) / VoxelGridSize; int voxelCountZ = (DensityFieldDepth - 1) / VoxelGridSize; Voxels = new VoxelGeometry[voxelCountX * voxelCountY * voxelCountZ]; VoxelBounds = new BoundingBox[Voxels.Length]; voxelKDTree = new KDTree<VoxelElement>(VoxelCompareFunction, VoxelBoundsFunction, false, true); Vector3 ratio = Vector3.One * 2.0f * (float)VoxelGridSize / new Vector3(DensityFieldWidth-1,DensityFieldHeight-1,DensityFieldDepth-1); for (int z = 0; z < voxelCountZ; z++) { int zOff = voxelCountX * voxelCountY * z; for (int y = 0; y < voxelCountY; y++) { int yOff = voxelCountX * y; for (int x = 0; x < voxelCountX; x++) { int idx = x + yOff + zOff; /* VoxelBounds[idx] = new BoundingBox(new Vector3(x, y, z) * ratio - Vector3.One, new Vector3(x + 1, y + 1, z + 1) * ratio - Vector3.One); VoxelBounds[idx].Min = Vector3.Transform(VoxelBounds[idx].Min, Transformation.GetTransform()); VoxelBounds[idx].Max = Vector3.Transform(VoxelBounds[idx].Max, Transformation.GetTransform()); */ Voxels[idx] = new VoxelGeometry((ushort)idx); Voxels[idx].renderElement.Transform = new Matrix[1] { Transformation.GetTransform() }; Vector3 geometryRatio = 2.0f*Vector3.One / new Vector3(DensityFieldWidth-1,DensityFieldHeight-1,DensityFieldDepth-1); Voxels[idx].GenerateGeometry(ref DensityField, IsoValue, DensityFieldWidth, DensityFieldHeight, DensityFieldDepth, VoxelGridSize, VoxelGridSize, VoxelGridSize, x * VoxelGridSize, y * VoxelGridSize, z * VoxelGridSize, geometryRatio, this.Transformation.GetTransform()); VoxelBounds[idx] = MathUtils.TransformBounds(Voxels[idx].GetBounds(), Transformation.GetTransform()); if(Voxels[idx].CanRender) voxelKDTree.AddElement(new VoxelElement(Voxels[idx], VoxelBounds[idx]), false); } } } voxelKDTree.BuildTree(); RecursivelyBuildBounds(voxelKDTree.GetRoot()); terrainQuadMaterial = ResourceManager.Inst.GetMaterial("TerrainQuadMaterial"); giantQuadElement = GFXPrimitives.Decal.GetRenderElement(); Matrix quadMatrix = Matrix.CreateScale(1.5f) * Matrix.CreateRotationX(MathHelper.Pi) * this.Transformation.GetTransform(); quadMatrix.Translation = Vector3.Up * this.Transformation.GetBounds().Min.Y; giantQuadElement.Transform = new Matrix[1] { quadMatrix }; }
public override void AddElement(Material material, RenderElement element) { ShadowElementManager sceneMgr = (ShadowElementManager)((material.IsFoliage) ? ElementManagers[RenderPass.Foliage] : ElementManagers[RenderPass.Shadows]); sceneMgr.AddElement(material, element); }
public virtual void AddElement(Material material, RenderElement element) { }
public override void AddElement(Material material, RenderElement element) { ShadowElementManager sceneMgr = (ShadowElementManager)ElementManagers[RenderPass.Shadows]; sceneMgr.AddElement(material, element); }
public void AddElement(Material material, ParticleEmitter element) { if (!Elements.ContainsKey(material)) Elements.Add(material, new Queue<ParticleEmitter>()); Elements[material].Enqueue(element); }
public virtual void AddElement(Material material, RenderElement element) { if (!Elements.ContainsKey(material)) Elements.Add(material, new CustomList<RenderElement>()); Elements[material].Add(element); }
public void AddMaterial(Material material) { materials.Add(material); }
public void AddElement(Material material, RenderElement element) { if (!Elements.ContainsKey(material)) Elements.Add(material, new Queue<RenderElement>()); Elements[material].Enqueue(element); }
public void AddElement(Material material, Matrix transform) { if (!Elements.ContainsKey(material)) Elements.Add(material, new List<Matrix>()); Elements[material].Add(transform); }