private void Start() { fadeInLeft = fadeInTime; sprite = GetComponentInChildren <SpriteRenderer>(); game = GameObject.FindGameObjectWithTag("GameController"); Room = game.GetComponent <RoomLighting>(); scenes = game.GetComponent <RelodScene>(); if (absorbPrefab == null) { absorbPrefab = Resources.Load <GameObject>("AbsorbBubble.prefab"); } }
public void DrawRoom(Room room, RoomLighting lighting, bool clear) { var size = Blueprint.Width - borderSize; //TODO: set floor shadow map here to stop surrounding light issues LightEffect.floorShadowMap = ObjShadowTarg; LightEffect.TargetRoom = (float)room.RoomID; var bigBounds = new Rectangle(lighting.Bounds.X * resPerTile, lighting.Bounds.Y * resPerTile, lighting.Bounds.Width * resPerTile, lighting.Bounds.Height * resPerTile); bigBounds = Rectangle.Intersect(bigBounds, new Rectangle(0, 0, size * resPerTile, size * resPerTile)); GD.RasterizerState = Scissor; if (clear) { GD.SetRenderTarget(LightMap); DrawRect = bigBounds; DrawRect.Offset(ScissorBase); GD.ScissorRectangle = DrawRect; var effect = LightEffect; effect.CurrentTechnique = effect.Techniques[0]; EffectPassCollection passes = effect.Techniques[0].Passes; effect.LightColor = Vector4.One * (Blueprint.MinOut.A / 255f); GD.BlendState = BlendState.Opaque; passes[2].Apply(); GD.SetVertexBuffer(LightBuf); GD.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); if (LightMapDirection != null) { GD.SetRenderTarget(LightMapDirection); DrawRect = ScaleDirectionScissor(DrawRect); GD.ScissorRectangle = DrawRect; effect.CurrentTechnique = effect.Techniques[1]; passes = effect.Techniques[1].Passes; effect.LightColor = Vector4.Zero; GD.BlendState = BlendState.Opaque; passes[2].Apply(); GD.SetVertexBuffer(LightBuf); GD.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); } } var outFactor = Vector4.One - Blueprint.MinOut.ToVector4(); var factor = 16f / resPerTile; var colorTech = 0; // var dirTech = 1; // if (room.IsOutside || WallComp != null) { var res = (Blueprint.Width - borderSize) * resPerTile; if (!room.IsOutside) { DrawRect = new Rectangle(0, 0, res, res); } else { DrawRect = bigBounds; } if (OutdoorsLight == null) { BuildOutdoorsLight(Blueprint.OutsideTime); } var light = OutdoorsLight; //generate shadows light.Level = (sbyte)(room.Floor); DrawWallShadows(room.WallLines, light); if (room.IsOutside && !WorldConfig.Current.UltraLighting) { DrawObjShadows(lighting.ObjectFootprints, light); } //draw the light onto the lightmap GD.SetRenderTarget(LightMap); DrawRect.Offset(ScissorBase); GD.ScissorRectangle = DrawRect; LightEffect.LightColor = Color.White.ToVector4() * outFactor.W; LightEffect.ShadowPowers = new Vector2(0.75f, 0.6f) * light.ShadowMultiplier; LightEffect.LightHeight = 1f / (float)Blueprint.Width; LightEffect.LightPosition = light.LightPos / (size * 16f); //in position space (0,1) LightEffect.LightDirection = new Vector3(-SunVector.Z, SunVector.Y * -1, SunVector.X); LightEffect.LightSize = float.MaxValue; //in position space (0,1) LightEffect.IsOutdoors = true; var effect = LightEffect; effect.CurrentTechnique = effect.Techniques[colorTech]; EffectPassCollection passes = effect.Techniques[colorTech].Passes; passes[room.IsOutside ? ((WallComp == null) ? 1 : 4) : 3].Apply(); GD.SetVertexBuffer(LightBuf); GD.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); if (LightMapDirection != null) { GD.SetRenderTarget(LightMapDirection); effect.CurrentTechnique = effect.Techniques[dirTech]; passes = effect.Techniques[dirTech].Passes; DrawRect = ScaleDirectionScissor(DrawRect); GD.ScissorRectangle = DrawRect; passes[room.IsOutside ? ((WallComp == null) ? 1 : 4) : 3].Apply(); GD.SetVertexBuffer(LightBuf); GD.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); } LightEffect.shadowMap = ShadowTarg; } var order = lighting.Lights.OrderBy(x => x.OutdoorsColor ? 0 : 1); var hasMulOutside = false; foreach (var light in order) { if (!light.OutdoorsColor && !hasMulOutside) { MultiplyOutdoors(bigBounds); hasMulOutside = true; } if (light.WindowRoom != -1) { var wroom = Blueprint.Light[Blueprint.Rooms[light.WindowRoom].Base]; light.LightIntensity = wroom.AmbientLight / 150f; } if (light.LightIntensity < 0.2f) { continue; } DrawRect = new Rectangle((int)(light.LightBounds.X / factor), (int)(light.LightBounds.Y / factor), (int)(light.LightBounds.Width / factor), (int)(light.LightBounds.Height / factor)); DrawRect = Rectangle.Intersect(DrawRect, bigBounds); //generate shadows DrawWallShadows(room.WallLines, light); DrawObjShadows(lighting.ObjectFootprints, light); //draw the light onto the lightmap GD.SetRenderTarget(LightMap); DrawRect.Offset(ScissorBase); GD.ScissorRectangle = DrawRect; LightEffect.ShadowPowers = new Vector2(1f, 1f); LightEffect.LightPosition = light.LightPos / (size * 16f); //in position space (0,1) LightEffect.LightSize = light.LightSize / (size * 16f); //in position space (0,1) var l = light.LightColor.ToVector4(); l.W = (l.X + l.Y + l.Z) / 3; if (light.OutdoorsColor) { l = Vector4.Multiply(l, outFactor); } else { l *= 0.70f; } LightEffect.LightColor = l; LightEffect.IsOutdoors = light.OutdoorsColor; LightEffect.LightIntensity = light.LightIntensity; var effect = LightEffect; effect.CurrentTechnique = effect.Techniques[colorTech]; EffectPassCollection passes = effect.Techniques[colorTech].Passes; if (WorldConfig.Current.UltraLighting) { LightEffect.BlurMin = (light.OutdoorsColor)?(1 / (Blueprint.Width * 9f)):0; LightEffect.BlurMax = (1 / (Blueprint.Width * 5f)); passes[5].Apply(); } else { passes[0].Apply(); } GD.SetVertexBuffer(LightBuf); GD.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); if (LightMapDirection != null) { GD.SetRenderTarget(LightMapDirection); effect.CurrentTechnique = effect.Techniques[dirTech]; passes = effect.Techniques[dirTech].Passes; DrawRect = ScaleDirectionScissor(DrawRect); passes[0].Apply(); GD.SetVertexBuffer(LightBuf); GD.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); } } if (!hasMulOutside) { MultiplyOutdoors(bigBounds); } }
public void DrawRoom(Room room, RoomLighting lighting, bool clear) { var size = Blueprint.Width - borderSize; LightEffect.Parameters["TargetRoom"].SetValue((float)room.RoomID); var bigBounds = new Rectangle(lighting.Bounds.X * resPerTile, lighting.Bounds.Y * resPerTile, lighting.Bounds.Width * resPerTile, lighting.Bounds.Height * resPerTile); bigBounds = Rectangle.Intersect(bigBounds, new Rectangle(0, 0, size * resPerTile, size * resPerTile)); GD.RasterizerState = new RasterizerState() { ScissorTestEnable = true, CullMode = CullMode.None }; if (clear) { GD.SetRenderTarget(LightMap); DrawRect = bigBounds; DrawRect.Offset(ScissorBase); GD.ScissorRectangle = DrawRect; var effect = LightEffect; effect.CurrentTechnique = effect.Techniques[0]; EffectPassCollection passes = effect.Techniques[0].Passes; effect.Parameters["LightColor"].SetValue(Vector4.One * (Blueprint.MinOut.A / 255f)); GD.BlendState = BlendState.Opaque; passes[2].Apply(); GD.SetVertexBuffer(LightBuf); GD.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); } var outFactor = 1 - (Blueprint.MinOut.A / 255f); var factor = 16f / resPerTile; if (room.IsOutside || WallComp != null) { var res = (Blueprint.Width - borderSize) * resPerTile; if (!room.IsOutside) { DrawRect = new Rectangle(0, 0, res, res); } else { DrawRect = bigBounds; } if (OutdoorsLight == null) { BuildOutdoorsLight(Blueprint.OutsideTime); } var light = OutdoorsLight; //generate shadows light.Level = (sbyte)(room.Floor); DrawWallShadows(room.WallLines, light); if (room.IsOutside && !WorldConfig.Current.UltraLighting) { DrawObjShadows(lighting.ObjectFootprints, light); } //draw the light onto the lightmap GD.SetRenderTarget(LightMap); DrawRect.Offset(ScissorBase); GD.ScissorRectangle = DrawRect; LightEffect.Parameters["LightColor"].SetValue(Color.White.ToVector4() * outFactor); LightEffect.Parameters["ShadowPowers"].SetValue(new Vector2(0.75f, 0.6f) * light.ShadowMultiplier); LightEffect.Parameters["LightPosition"].SetValue(light.LightPos / (size * 16f)); //in position space (0,1) LightEffect.Parameters["LightSize"].SetValue(float.MaxValue); //in position space (0,1) LightEffect.Parameters["IsOutdoors"]?.SetValue(true); var effect = LightEffect; effect.CurrentTechnique = effect.Techniques[0]; EffectPassCollection passes = effect.Techniques[0].Passes; passes[room.IsOutside ? ((WallComp == null) ? 1 : 4) : 3].Apply(); GD.SetVertexBuffer(LightBuf); GD.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); LightEffect.Parameters["shadowMap"].SetValue(ShadowTarg); } var order = lighting.Lights.OrderBy(x => x.OutdoorsColor ? 0 : 1); var hasMulOutside = false; foreach (var light in order) { if (!light.OutdoorsColor && !hasMulOutside) { MultiplyOutdoors(bigBounds); hasMulOutside = true; } if (light.WindowRoom != -1) { var wroom = Blueprint.Light[Blueprint.Rooms[light.WindowRoom].Base]; light.LightIntensity = wroom.AmbientLight / 150f; } if (light.LightIntensity < 0.2f) { continue; } DrawRect = new Rectangle((int)(light.LightBounds.X / factor), (int)(light.LightBounds.Y / factor), (int)(light.LightBounds.Width / factor), (int)(light.LightBounds.Height / factor)); DrawRect = Rectangle.Intersect(DrawRect, bigBounds); //generate shadows DrawWallShadows(room.WallLines, light); DrawObjShadows(lighting.ObjectFootprints, light); //draw the light onto the lightmap GD.SetRenderTarget(LightMap); DrawRect.Offset(ScissorBase); GD.ScissorRectangle = DrawRect; LightEffect.Parameters["ShadowPowers"].SetValue(new Vector2(1f, 1f)); LightEffect.Parameters["LightPosition"].SetValue(light.LightPos / (size * 16f)); //in position space (0,1) LightEffect.Parameters["LightSize"].SetValue(light.LightSize / (size * 16f)); //in position space (0,1) var l = light.LightColor.ToVector4(); l.W = (l.X + l.Y + l.Z) / 3; if (light.OutdoorsColor) { l *= outFactor; } else { l *= 0.70f; } LightEffect.Parameters["LightColor"].SetValue(l); LightEffect.Parameters["IsOutdoors"]?.SetValue(light.OutdoorsColor); LightEffect.Parameters["LightIntensity"]?.SetValue(light.LightIntensity); var effect = LightEffect; effect.CurrentTechnique = effect.Techniques[0]; EffectPassCollection passes = effect.Techniques[0].Passes; if (WorldConfig.Current.UltraLighting) { LightEffect.Parameters["BlurMin"].SetValue((light.OutdoorsColor)?(1 / (75f * 9)):0); LightEffect.Parameters["BlurMax"].SetValue((1 / (75f * 5))); passes[5].Apply(); } else { passes[0].Apply(); } GD.SetVertexBuffer(LightBuf); GD.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); } if (!hasMulOutside) { MultiplyOutdoors(bigBounds); } }
public void DrawRoom(Room room, RoomLighting lighting, bool clear) { var size = Blueprint.Width - 2; LightEffect.Parameters["TargetRoom"].SetValue((float)room.RoomID); var bigBounds = new Rectangle(lighting.Bounds.X * resPerTile, lighting.Bounds.Y * resPerTile, lighting.Bounds.Width * resPerTile, lighting.Bounds.Height * resPerTile); bigBounds = Rectangle.Intersect(bigBounds, new Rectangle(0, 0, size * 8, size * 8)); GD.RasterizerState = new RasterizerState() { ScissorTestEnable = true, CullMode = CullMode.None }; if (clear) { GD.SetRenderTarget(LightMap); DrawRect = bigBounds; DrawRect.Offset(ScissorBase); GD.ScissorRectangle = DrawRect; var effect = LightEffect; effect.CurrentTechnique = effect.Techniques[0]; EffectPassCollection passes = effect.Techniques[0].Passes; passes[2].Apply(); GD.SetVertexBuffer(LightBuf); GD.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); } var factor = 16f / resPerTile; foreach (var light in lighting.Lights) { if (light.WindowRoom != -1) { var wroom = Blueprint.Light[Blueprint.Rooms[light.WindowRoom].Base]; light.LightIntensity = wroom.AmbientLight / 150f; } if (light.LightIntensity < 0.2f) { continue; } DrawRect = new Rectangle((int)(light.LightBounds.X / factor), (int)(light.LightBounds.Y / factor), (int)(light.LightBounds.Width / factor), (int)(light.LightBounds.Height / factor)); DrawRect = Rectangle.Intersect(DrawRect, bigBounds); //generate shadows DrawObjShadows(lighting.ObjectFootprints, light); DrawWallShadows(room.WallLines, light); //draw the light onto the lightmap GD.SetRenderTarget(LightMap); DrawRect.Offset(ScissorBase); GD.ScissorRectangle = DrawRect; LightEffect.Parameters["ShadowPowers"].SetValue(new Vector2(1f, 1f)); LightEffect.Parameters["LightPosition"].SetValue(light.LightPos / (size * 16f)); //in position space (0,1) LightEffect.Parameters["LightSize"].SetValue(light.LightSize / (size * 16f)); //in position space (0,1) LightEffect.Parameters["IsOutdoors"].SetValue(light.OutdoorsColor); LightEffect.Parameters["LightIntensity"].SetValue(light.LightIntensity); var effect = LightEffect; effect.CurrentTechnique = effect.Techniques[0]; EffectPassCollection passes = effect.Techniques[0].Passes; passes[0].Apply(); GD.SetVertexBuffer(LightBuf); GD.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); } if (room.IsOutside) { var res = (Blueprint.Width - 2) * 8; DrawRect = new Rectangle(0, 0, res, res); if (OutdoorsLight == null) { BuildOutdoorsLight(Blueprint.OutsideTime); } var light = OutdoorsLight; //generate shadows DrawObjShadows(lighting.ObjectFootprints, light); DrawWallShadows(room.WallLines, light); //draw the light onto the lightmap GD.SetRenderTarget(LightMap); DrawRect.Offset(ScissorBase); GD.ScissorRectangle = DrawRect; LightEffect.Parameters["ShadowPowers"].SetValue(new Vector2(0.75f, 0.6f) * light.ShadowMultiplier); LightEffect.Parameters["LightPosition"].SetValue(light.LightPos / (size * 16f)); //in position space (0,1) LightEffect.Parameters["LightSize"].SetValue(float.MaxValue); //in position space (0,1) LightEffect.Parameters["IsOutdoors"].SetValue(true); var effect = LightEffect; effect.CurrentTechnique = effect.Techniques[0]; EffectPassCollection passes = effect.Techniques[0].Passes; passes[1].Apply(); GD.SetVertexBuffer(LightBuf); GD.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2); } }