public override void Draw(SpriteBatch spriteBatch) { Bounds.Location = Transform.Position.ToPoint(); Bounds.Size = Size * Transform.Scale.ToPoint(); HitBoxDebuger.DrawRectangle(Bounds, Color, 0, Texture, gameObject.Layer, Origin); }
public void Draw(Texture2D texture) { if (!Expired) { Rectangle HandyRectangle = Rectangle.Empty; HandyRectangle.X = (int)Position.X; HandyRectangle.Y = (int)Position.Y; HandyRectangle.Width = (int)Size.X; HandyRectangle.Height = (int)Size.Y; HitBoxDebuger.DrawRectangle(HandyRectangle, Color, Rotation, texture, Layer, Vector2.Zero); } }
public void Draw() { if (!Expired) { Rectangle HandyRectangle = Rectangle.Empty; HandyRectangle.X = (int)Position.X; HandyRectangle.Y = (int)Position.Y; HandyRectangle.Width = (int)Size.X; HandyRectangle.Height = (int)Size.Y; HitBoxDebuger.DrawRectangle(HandyRectangle, Color, Rotation, Layer); } }
public void Draw() { HitBoxDebuger.DrawRectangle(Position, Color); }
public static void ApplyLighting() { //You probably need to add they XY coordinates of BiasScene in editor mode too (below two lines) //Ignore this for now Rectangle BiasScene = new Rectangle((int)(Setup.Camera.Position.X - Setup.graphics.PreferredBackBufferWidth * 0.5f), (int)(Setup.Camera.Position.Y - Setup.graphics.PreferredBackBufferHeight * 0.5f), Setup.graphics.PreferredBackBufferWidth, Setup.graphics.PreferredBackBufferHeight); if (FN_Editor.EditorScene.IsThisTheEditor) { BiasScene = new Rectangle((int)(0 + -Setup.graphics.PreferredBackBufferWidth * 0.5f + Setup.Camera.Position.X), (int)(0 - Setup.graphics.PreferredBackBufferHeight * 0.5f + Setup.Camera.Position.Y), (int)FN_Editor.GizmosVisualizer.SceneWindow.Z, (int)FN_Editor.GizmosVisualizer.SceneWindow.W); } Light[] LIGHTS = SceneManager.ActiveScene.FindGameObjectComponents <Light>(); if (LIGHTS == null || LIGHTS.Length == 0) { //Setup.GraphicsDevice.SetRenderTarget(null); //Setup.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone, null, Setup.Camera.GetViewTransformationMatrix()); //Setup.spriteBatch.Draw(RenderTarget2D, BiasScene.Location.ToVector2(), new Rectangle(Point.Zero, BiasScene.Size), Color.White); //Setup.spriteBatch.End(); return; } int LightCount = LIGHTS.Length; if (LightCount == 0) { return; } int CappedLightCount = LightCount > MAX_LIGHT_COUNT ? MAX_LIGHT_COUNT : LightCount; Vector3[] COLOR = new Vector3[CappedLightCount]; float[] InnerRadius = new float[CappedLightCount]; float[] Radius = new float[CappedLightCount]; float[] Attenuation = new float[CappedLightCount]; float[] X_Bias = new float[CappedLightCount]; float[] Y_Bias = new float[CappedLightCount]; float[] AngularRadius = new float[CappedLightCount]; float[] InnerIntensity = new float[CappedLightCount]; float[] ShadowIntensity = new float[CappedLightCount]; float[] CastShadow = new float[CappedLightCount]; HandyList.Clear(); Points.Clear(); //1- Needs some optimization, like if light is out of bounds of screen, it shouldn't be updated or sent to the light shader if (CastShadows_Global) { //Rendering ShadowMap Here Setup.GraphicsDevice.SetRenderTarget(ShadowMap); ShadowCaster[] Occluders = SceneManager.ActiveScene.FindGameObjectComponents <ShadowCaster>(); Ray ray = new Ray(); Vector2 Bias = -new Vector2(Setup.graphics.PreferredBackBufferWidth * 0.5f - Setup.Camera.Position.X, Setup.graphics.PreferredBackBufferHeight * 0.5f - Setup.Camera.Position.Y); if (Occluders != null) { Points.Add(Bias); Points.Add(Bias + Vector2.UnitX * Setup.graphics.PreferredBackBufferWidth); Points.Add(Bias + Vector2.UnitX * Setup.graphics.PreferredBackBufferWidth + Vector2.UnitY * Setup.graphics.PreferredBackBufferHeight); Points.Add(Bias + Vector2.UnitY * Setup.graphics.PreferredBackBufferHeight); BorderOccluders[0].SetOccluder(Bias, Vector2.UnitX * Setup.graphics.PreferredBackBufferWidth + Bias); BorderOccluders[1].SetOccluder(Bias + Vector2.UnitX * Setup.graphics.PreferredBackBufferWidth, new Vector2(Setup.graphics.PreferredBackBufferWidth, Setup.graphics.PreferredBackBufferHeight) + Bias); BorderOccluders[2].SetOccluder(Bias + Vector2.Zero, new Vector2(0, Setup.graphics.PreferredBackBufferHeight) + Bias); BorderOccluders[3].SetOccluder(Bias + new Vector2(0, Setup.graphics.PreferredBackBufferHeight), new Vector2(Setup.graphics.PreferredBackBufferWidth, Setup.graphics.PreferredBackBufferHeight) + Bias); HandyList.Add(BorderOccluders[0]); HandyList.Add(BorderOccluders[1]); HandyList.Add(BorderOccluders[2]); HandyList.Add(BorderOccluders[3]); Setup.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone, null, Setup.Camera.GetViewTransformationMatrix()); // -> Mandatory foreach (ShadowCaster SC in Occluders) { if (!SC.Enabled) { continue; } HitBoxDebuger.DrawRectangle(SC.gameObject.GetComponent <SpriteRenderer>().Sprite.DynamicScaledRect()); //HitBoxDebuger.DrawRectangle_Effect(SC.gameObject.GetComponent<SpriteRenderer>().Sprite.DynamicScaledRect()); LineOccluder[] LOCS = SC.ConvertToLineOccluders(); for (int i = 0; i < 4; i++) { Vector2 OccluderDirection = Vector2.Normalize(LOCS[i].EndPoint - LOCS[i].StartPoint); Points.Add(LOCS[i].StartPoint); Points.Add(LOCS[i].StartPoint - OccluderDirection * 0.5f); //Casting rays from the side of an object HandyList.Add(LOCS[i]); } } Setup.spriteBatch.End(); } if (HandyList.Count != 0) { for (int k = 0; k < LIGHTS.Length; k++) { PointsTriangle.Clear(); if (!LIGHTS[k].gameObject.IsActive() || !LIGHTS[k].Enabled) { continue; } foreach (Vector2 P in Points) { float ClosestIntersection = 100000000; //Dummy Number Vector2 FoundClosestPoint = Vector2.Zero; float Distance = -1; ray.Origin = LIGHTS[k].gameObject.Transform.Position; ray.Direction = P - ray.Origin; //Don't Normalize! foreach (LineOccluder LOC in HandyList) //Needs Optimization { Distance = ray.GetRayToLineSegmentIntersection(LOC); if (Distance != -1 && Distance < ClosestIntersection) { ClosestIntersection = Distance; FoundClosestPoint = ray.GetAPointAlongRay(Distance); } } if (ClosestIntersection != 100000000) //INTERSECTION { PointsTriangle.Add(FoundClosestPoint); } } PointsTriangle.Sort((x, y) => MathCompanion.GetAngle(x, LIGHTS[k].gameObject.Transform.Position).CompareTo(MathCompanion.GetAngle(y, LIGHTS[k].gameObject.Transform.Position))); Bias = -Bias; //DrawTriangles for (int i = 0; i < PointsTriangle.Count - 1; i++) { HitBoxDebuger.DrawTriangle(Bias + PointsTriangle[i], Bias + PointsTriangle[i + 1], Bias + LIGHTS[k].gameObject.Transform.Position); //White Color } HitBoxDebuger.DrawTriangle(Bias + PointsTriangle[PointsTriangle.Count - 1], Bias + PointsTriangle[0], Bias + LIGHTS[k].gameObject.Transform.Position); } } ShadowMap_param.SetValue(ShadowMap); Setup.GraphicsDevice.SetRenderTarget(RenderTarget2D); } for (int i = 0; i < CappedLightCount; i++) { if (LIGHTS[i].Enabled == false || LIGHTS[i].gameObject.IsActive() == false) { continue; } LIGHTS[i].gameObject.Transform.AdjustTransformation(); COLOR[i] = LIGHTS[i].color.ToVector3(); InnerRadius[i] = MathHelper.Clamp(LIGHTS[i].InnerRadius, 0, LIGHTS[i].OuterRadius) * Setup.Camera.Zoom; Radius[i] = MathHelper.Clamp(LIGHTS[i].OuterRadius, 0, 1) * Setup.Camera.Zoom; Attenuation[i] = MathHelper.Clamp(LIGHTS[i].Attenuation, 0, float.MaxValue); X_Bias[i] = (LIGHTS[i].gameObject.Transform.Position.X - Setup.Camera.Position.X) / Setup.graphics.PreferredBackBufferWidth; Y_Bias[i] = (LIGHTS[i].gameObject.Transform.Position.Y - Setup.Camera.Position.Y) / Setup.graphics.PreferredBackBufferHeight; AngularRadius[i] = MathHelper.Clamp(LIGHTS[i].AngularRadius, 0, 360); InnerIntensity[i] = MathHelper.Clamp(LIGHTS[i].InnerInensity, 1, float.MaxValue); ShadowIntensity[i] = MathHelper.Clamp(1 - LIGHTS[i].ShadowIntensity, 0, 1); CastShadow[i] = LIGHTS[i].CastShadow ? 1 : 0; if (LIGHTS[i].Type == LightTypes.Directional) //Bug here where directional intensity is set forever { DirectionalIntensity_param.SetValue(MathHelper.Clamp(LIGHTS[i].DirectionalIntensity, 0, 1)); InnerRadius[i] = 0; Radius[i] = 0; } } LightCount_param.SetValue(CappedLightCount); //CameraPosNorm_param.SetValue(new Vector2(Setup.Camera.Position.X / Setup.resolutionIndependentRenderer.VirtualWidth, Setup.Camera.Position.Y / Setup.resolutionIndependentRenderer.VirtualHeight)); AngularRadius_param.SetValue(AngularRadius); AngularRadius_param.SetValue(AngularRadius); X_Bias_param.SetValue(X_Bias); Y_Bias_param.SetValue(Y_Bias); YOverX_param.SetValue(YOVERX); Color_param.SetValue(COLOR); Radius_param.SetValue(Radius); InnerRadius_param.SetValue(InnerRadius); InnerIntensity_param.SetValue(InnerIntensity); Attenuation_param.SetValue(Attenuation); CastShadows_param.SetValue(CastShadows_Global); CastShadow_param.SetValue(CastShadow); ShadowConstant_param.SetValue(ShadowIntensity); //Setup.GraphicsDevice.SetRenderTarget(null); //Setup.GraphicsDevice.SetRenderTarget(RenderTarget2D); Setup.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone, LightEffect, Setup.Camera.GetViewTransformationMatrix()); Setup.spriteBatch.Draw(RenderTarget2D, BiasScene.Location.ToVector2(), Color.White); Setup.spriteBatch.End(); }