Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What you're trying to to is alpha channel masking.The easiest way is to bake the alpha channel using the content pipeline. But if for some reason you want to do it at runtime here's how (roughly) using a render target (A better and faster solution would be to write a shader)</p> <p>First create a RenderTarget2D to store and intermediate masked texture</p> <pre><code>RenderTarget2D maskRenderTarget = GfxComponent.CreateRenderTarget(GraphicsDevice, 1, SurfaceFormat.Single); </code></pre> <p>Set the renderTarget, and device state</p> <pre><code>GraphicsDevice.SetRenderTarget(0, maskRenderTarget); GraphicsDevice.RenderState.AlphaBlendEnable = true; GraphicsDevice.RenderState.DestinationBlend = Blend.Zero; GraphicsDevice.RenderState.SourceBlend = Blend.One; </code></pre> <p>Set the channels to write to the R, G, B channels and draw the first texture using a sprite batch</p> <pre><code>GraphicsDevice.RenderState.ColorWriteChannels = ColorWriteChannels.Red | ColorWriteChannels.Green | ColorWriteChannels.Blue; spriteBatch.Draw(bg, new Vector2(0, 0), Color.White); </code></pre> <p>Set channels to alpha only, and draw the alpha mask</p> <pre><code>GraphicsDevice.RenderState.ColorWriteChannels = ColorWriteChannels.Alpha; spriteBatch.Draw(circle, new Vector2(0, 0), Color.White); </code></pre> <p>you can now restore the render target to the back buffer and draw your texture using alpha blending.</p> <pre><code>maskedTexture = shadowRenderTarget.GetTexture(); ... </code></pre> <p>Also don't forget to restore the state:</p> <pre><code>GraphicsDevice.RenderState.ColorWriteChannels = ColorWriteChannels.All; ... </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