Problems with Blending Images XNA 3.1

Started by
11 comments, last by Nokame 12 years ago
I figured i'd give you the whole draw method as well... The following code is called during the draw function. The lightmap rendertarget is created (as discussed) and the map is all drawn onto a rendertarget then drawn to the screen... THEN the lightmap is drawn over the map.


this.DrawLightMapToRenderTarget(); // This is the function i first posted.

this.GraphicsDevice.SetRenderTarget(0, this.region.regionSurface);
this.GraphicsDevice.Clear(Color.Black);

this.spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.FrontToBack, SaveStateMode.None);

#region Draw Player, Character, and Map (The Map's Colored image)
//////////////////////////////////////////////////////////

// Draw MAP
this.DrawRegionTEST(this.region, this.player, this.region.characterList, gameTime);

// Draw Region's Characters
this.DrawCharacters(this.player, this.region.characterList, gameTime);

// Draw Player
this.DrawPlayer(this.player, gameTime);

//////////////////////////////////////////////////////////
#endregion

this.spriteBatch.End();

this.GraphicsDevice.SetRenderTarget(0, null);
this.GraphicsDevice.Clear(Color.Black);

// Draw the region and characters.
this.spriteBatch.Begin();
this.spriteBatch.Draw(this.region.regionSurface.GetTexture(), new Vector2(), Color.White);
this.spriteBatch.End();

// Draw lightmap over all the textures
this.spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.SaveState);

this.spriteBatch.GraphicsDevice.RenderState.SourceBlend = this.region.sourceBlendType;
this.spriteBatch.GraphicsDevice.RenderState.DestinationBlend = this.region.destBlendType;
this.spriteBatch.GraphicsDevice.RenderState.BlendFunction = this.region.blendFunction;

this.spriteBatch.Draw(this.region.lightMap.GetTexture(), Vector2.Zero, Color.White);

this.spriteBatch.End();
Advertisement
You are welcome!

Be careful, the last parameter in the RenderTarget2D constructor is the usage, not multisampling. If the application runs in the XBOX or in some PC GPUs then preserve contents could be a problem.

Edit: Sorry, my mistake. Your value is ok.

[size=1]Project page: [size=1]<

[size=1] XNA FINAL Engine[size=1] [size=1]>
Ok. I’m dry. Sorry :(

At this point I can only recommend that you calculate the illumination but don’t do the drawing. Then comment another part of the code and so on until you find the answer.

Good luck!!

[size=1]Project page: [size=1]<

[size=1] XNA FINAL Engine[size=1] [size=1]>
I agree. It's time to go through it thoroughly. I've been thinking that since this code seems to be done correctly, it's increase in processing power is shedding light on another problem... which i'm excited about.... *sigh*. Anyways, thank you very much for helping me up to this point. Having another voice on the matter has put things into perspective. *closes post*

This topic is closed to new replies.

Advertisement