Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you were to multiply your light texture with the scene, you will <em>darken</em> the area, not brighten it.</p> <p>You could try rendering with additive blending; this won't quite look right, but is easy and may be acceptable. You will have to draw your light with a fairly low alpha for the light texture to not just over saturate that part of the image. </p> <p>Another, more complicated, way of doing lighting is to draw all of your light textures (for all the lights in the scene) additively onto a second render target, and then multiply this texture with your scene. This should give much more realistic lighting, but has a larger performance overhead and is more complex.</p> <p>Initialisation:</p> <pre><code>RenderTarget2D lightBuffer = new RenderTarget2D(graphicsDevice, screenWidth, screenHeight, 1, SurfaceFormat.Color); Color ambientLight = new Color(0.3f, 0.3f, 0.3f, 1.0f); </code></pre> <p>Draw:</p> <pre><code>// set the render target and clear it to the ambient lighting graphicsDevice.SetRenderTarget(0, lightBuffer); graphicsDevice.Clear(ambientLight) // additively draw all of the lights onto this texture. The lights can be coloured etc. spriteBatch.Begin(SpriteBlendMode.Additive); foreach (light in lights) spriteBatch.Draw(lightFadeOffTexture, light.Area, light.Color); spriteBatch.End(); // change render target back to the back buffer, so we are back to drawing onto the screen graphicsDevice.SetRenderTarget(0, null); // draw the old, non-lit, scene DrawScene(); // multiply the light buffer texture with the scene spriteBatch.Begin(SpriteBlendMode.Additive, SpriteSortMode.Immediate, SaveStateMode.None); graphicsDevice.RenderState.SourceBlend = Blend.Zero; graphicsDevice.RenderState.DestinationBlend = Blend.SourceColor; spriteBatch.Draw(lightBuffer.GetTexture(), new Rectangle(0, 0, screenWidth, screenHeight), Color.White); spriteBatch.End(); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload