public RoofComponent(Blueprint bp) { blueprint = bp; RoofRects = new List <RoofRect> [bp.Stories]; Drawgroups = new RoofDrawGroup[bp.Stories]; this.Effect = WorldContent.GrassEffect; }
public TerrainComponent(Rectangle size, Blueprint blueprint) { this.Size = size; this.Effect = WorldContent.GrassEffect; this.Bp = blueprint; GridAsTexture = FSOEnvironment.Enable3D; UpdateLotType(); }
public static void LoadEffects(bool reload) { _2DWorldBatchEffect = new WorldBatchEffect(ContentManager.Load <Effect>("Effects/2DWorldBatch" + EffectSuffix)); Grad2DEffect = new GradEffect(ContentManager.Load <Effect>("Effects/gradpoly2D")); Light2DEffect = new LightMap2DEffect(ContentManager.Load <Effect>("Effects/LightMap2D")); GrassEffect = new GrassEffect(ContentManager.Load <Effect>("Effects/GrassShader" + EffectSuffix)); RCObject = new RCObjectEffect(ContentManager.Load <Effect>("Effects/RCObject" + EffectSuffix)); SSAA = ContentManager.Load <Effect>("Effects/SSAA"); SpriteEffect = new Effects.SpriteEffect(ContentManager.Load <Effect>("Effects/SpriteEffects" + EffectSuffix)); ParticleEffect = new LightMappedEffect(ContentManager.Load <Effect>("Effects/ParticleShader")); AvatarEffect = new LightMappedEffect(ContentManager.Load <Effect>("Effects/Vitaboy" + EffectSuffix)); Files.RC.Utils.DepthTreatment.SpriteEffect = SpriteEffect; LightEffects = new List <LightMappedEffect>() { _2DWorldBatchEffect, GrassEffect, RCObject, ParticleEffect, AvatarEffect }; }
public void DrawFloor(GraphicsDevice gd, GrassEffect e, WorldZoom zoom, WorldRotation rot, List <Texture2D> roommaps, HashSet <sbyte> floors, EffectPass pass, Matrix?lightWorld = null, WorldState state = null, int minFloor = 0, bool screenAlignUV = false) { var parallax = WorldConfig.Current.Complex; var buggedTex = WorldConfig.Current.AdvancedLighting ? 1 : 0; //assumes the effect and all its parameters have been set up already //we just need to get the right texture and offset var flrContent = Content.Content.Get().WorldFloors; e.TexOffset = new Vector2();// TexOffset[zoom]*-1f); var tmat = TexMat[rot]; e.TexMatrix = tmat; e.ScreenAlignUV = screenAlignUV; var baseRS = gd.RasterizerState; var f = 0; foreach (var floor in Floors) { if (!floors.Contains((sbyte)(f++))) { continue; } Matrix worldmat; if (lightWorld == null) { worldmat = Matrix.CreateTranslation(0, 2.95f * (f - 1) * 3 - Bp.BaseAlt * Bp.TerrainFactor * 3, 0); } else { worldmat = Matrix.CreateScale(1, 0, 1) * Matrix.CreateTranslation(0, 1f * (f - (1 + minFloor)), 0) * lightWorld.Value; e.DiffuseColor = new Vector4(1, 1, 1, 1) * (float)(6 - (f - (minFloor))) / 5f; } e.World = worldmat; e.Level = (float)(f - ((lightWorld == null)?0.999f:1f)); if (roommaps != null) { e.RoomMap = roommaps[f - 1]; } foreach (var type in floor.GroupForTileType) { bool water = false; if (type.Value is Modelled3DFloor) { //we generated a special model for this tile type var mdl = type.Value as Modelled3DFloor; e.TexMatrix = new Vector4(1, 0, 0, 1); e.ScreenAlignUV = false; e.GrassShininess = 0.02f; e.Bias = -0.5f; gd.Indices = mdl.GPUData; gd.SetVertexBuffer(mdl.VertGPUData); var tex = mdl.GetTexture(gd); e.BaseTex = tex; if (tex != null) { e.TexSize = new Vector2(tex.Width, tex.Height); } //e.CurrentTechnique.Passes[2].Apply(); pass.Apply(); gd.SamplerStates[0] = CustomWrap; gd.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, mdl.PrimitiveCount); gd.SetVertexBuffer(Bp.Terrain.VertexBuffer); e.TexMatrix = tmat; e.ScreenAlignUV = screenAlignUV; e.Bias = -999; continue; } var dat = type.Value.GPUData; if (dat == null) { continue; } gd.Indices = dat; var id = type.Key; var doubleDraw = false; Texture2D SPR = null; Texture2D pSPR = null; if (id == 0) { e.UseTexture = false; e.IgnoreColor = false; e.GrassShininess = 0.02f;// (float)0.25); } else { e.GrassShininess = (id >= 65503)?0.02f:0f; if (id >= 65503) { if (id == 65503) { water = true; var airTiles = TextureGenerator.GetAirTiles(gd); switch (zoom) { case WorldZoom.Far: SPR = airTiles[2]; break; case WorldZoom.Medium: SPR = airTiles[1]; break; case WorldZoom.Near: SPR = airTiles[0]; break; } } else { e.Water = true; e.ScreenAlignUV = false; var pool = id >= 65520; water = true; if (!pool) { e.UseTexture = false; e.IgnoreColor = false; //quickly draw under the water pass.Apply(); gd.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, type.Value.GeomForOffset.Count * 2); e.UseTexture = true; e.IgnoreColor = true; if (lightWorld == null) { e.World = worldmat * Matrix.CreateTranslation(0, 0.05f, 0); } id -= 65504; } else { id -= 65520; } e.TexMatrix = CounterTexMat[rot]; var roti = (int)rot; roti = (4 - roti) % 4; id = (ushort)(((id << roti) & 15) | (id >> (4 - roti))); //pools & water are drawn with special logic, and may also be drawn slightly above the ground. int baseSPR; int frameNum = 0; if (state != null) { if (PoolReplace != null && pool) { SPR = PoolReplace[id]; if (parallax) { pSPR = PoolReplaceParallax[id]; } } else { switch (zoom) { case WorldZoom.Far: baseSPR = (pool) ? 0x400 : 0x800; frameNum = (pool) ? 0 : 2; SPR = state._2D.GetTexture(flrContent.GetGlobalSPR((ushort)(baseSPR + id)).Frames[frameNum]); break; case WorldZoom.Medium: baseSPR = (pool) ? 0x410 : 0x800; frameNum = (pool) ? 0 : 1; SPR = state._2D.GetTexture(flrContent.GetGlobalSPR((ushort)(baseSPR + id)).Frames[frameNum]); break; default: baseSPR = (pool) ? 0x420 : 0x800; SPR = state._2D.GetTexture(flrContent.GetGlobalSPR((ushort)(baseSPR + id)).Frames[frameNum]); break; } } } } } else { var flr = flrContent.Get(id); if (flr == null) { continue; } if (state != null) { switch (zoom) { case WorldZoom.Far: SPR = state._2D.GetTexture(flr.Far.Frames[0]); break; case WorldZoom.Medium: SPR = state._2D.GetTexture(flr.Medium.Frames[0]); break; default: SPR = state._2D.GetTexture(flr.Near.Frames[0]); break; } } } //e.UseTexture = SPR != null); } e.BaseTex = SPR; if (SPR != null) { e.TexSize = new Vector2(SPR.Width, SPR.Height); } if (SPR != null && SPR.Name == null) { doubleDraw = true; SPR.Name = Alt.ToString(); } if (pSPR != null) { var parallaxPass = e.CurrentTechnique.Passes[4]; e.ParallaxTex = pSPR; e.ParallaxUVTexMat = new Vector4(0.7071f, -0.7071f, 0.7071f, 0.7071f); e.ParallaxHeight = 0.1f; parallaxPass.Apply(); } else { pass.Apply(); } if (Alt && !FSOEnvironment.DirectX) { //opengl bug workaround. For some reason, the texture is set to clamp mode by some outside force on first draw. //Monogame then thinks the texture is wrapping. gd.SamplerStates[buggedTex] = CustomWrap; } gd.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, type.Value.GeomForOffset.Count * 2); if (id == 0) { e.UseTexture = true; e.IgnoreColor = true; } if (water) { e.ScreenAlignUV = screenAlignUV; e.World = worldmat; e.TexMatrix = tmat; e.Water = false; } } } e.Water = false; Alt = !Alt; }