public void Render(GraphicsDevice device, IEnumerable <Visual> obstacles) { if (Power > 0) { // Compute the visibility mesh VisibilityComputer visibility = new VisibilityComputer(Position, Radius); foreach (Visual v in obstacles) { float width = v.Pose.Scale.X * v.Texture.Width; visibility.AddSquareOccluder(v.Pose.Position, width, v.Pose.Rotation); } List <Vector2> encounters = visibility.Compute(); // Generate a triangle list from the encounter points VertexPositionTexture[] vertices; short[] indices; TriangleListFromEncounters(encounters, out vertices, out indices); // Project the vertices to the screen ProjectVertices(vertices, device.PresentationParameters.BackBufferWidth, device.PresentationParameters.BackBufferHeight); // Apply the effect lightEffect.Parameters["lightSource"].SetValue(Position); lightEffect.Parameters["lightColor"].SetValue(Color.ToVector3() * Power); lightEffect.Parameters["lightRadius"].SetValue(Radius); lightEffect.Techniques[0].Passes[0].Apply(); // Draw the light on screen, using the triangle fan from the computed // visibility mesh so that the light only influences the area that can be // "seen" from the light's position. device.DrawUserIndexedPrimitives <VertexPositionTexture> ( PrimitiveType.TriangleList, vertices, 0, vertices.Length, indices, 0, indices.Length / 3 ); } }
private void Awake() { _playerStore = FindObjectOfType <PlayerStore>(); _visibilityComputer = new VisibilityComputer(); _visibilityComputer.Radius = 30; }
// Use this for initialization void Start() { mVisibility = new VisibilityComputer(LightObject.transform.position, LightRange); mShadowCasters = new List <ShadowCaster>(); }