Sign in to follow this  
FOOLVER

HLSL and XNA draw calls problem

Recommended Posts

hi, we are writing the shadow system for our isometric tile engine using a full shader system we draw the tiles with a code "like" this
Spritebatch.Begin();

for(y;y<height;y++)
   for(x;x<width;x++)
   {
       /*here we use our shadow shader*/
      if (tile has light)
      // effect.begin etc etc etc
      // draw the tile
      // effect.end etc etc
      else
      // draw the tile

      // draw the items
  
      // draw the characters
   }

SpriteBatch.End();
the problem is this: the shader affected all the draw calls inside spritebatch.begin (every tile in various strange ways!!!!!) .. also items and characters, we tried to use renderterged 2d but is useless because the creation of every rendertarget2d want another spritebatch.begin.. and we simply can't use a begin every tiles someone know ho to solve this problem ? thanks a lot and sorry for my bad english

Share this post


Link to post
Share on other sites
Quote:
Sprite Batching

In normal drawing, the SpriteBatch object does not change any render states or draw any sprites until you call End. This is known as Deferred mode. In Deferred mode, SpriteBatch saves the information from each Draw call until you call End. When you then call End, SpriteBatch changes the graphics device settings and draws each sprite in the batch. End then resets the device settings, if you specified SaveStateMode.SaveState.

If you call Begin, specifying SpriteSortMode.Immediate, it triggers Immediate mode. In Immediate mode, the SpriteBatch immediately changes the graphics device render states to begin drawing sprites. Thereafter, each call to Draw immediately draws the sprite using the current device settings. Calling End resets the device settings, if you specified SaveStateMode.SaveState.

In Immediate mode, once you call Begin on one SpriteBatch instance, do not call it on any other SpriteBatch instance until you call End for the first SpriteBatch.

Deferred mode is slower than Immediate mode, but it allows multiple instances of SpriteBatch to accept Begin and Draw calls without interfering with each other.

MSDN

so as i understand it you have to use different sprite batches if you switch the shader or maybe try using immediate mode.

Share this post


Link to post
Share on other sites
Quote:
use a batch for every tile draw is madness

i dont understand u should use a batch to pack all draw calls of similiar tiles into one batch. these should all have the same shader after u are done with the tile move onto the next with shader req. you dont have to use one batch per tile just per tile type.

Share this post


Link to post
Share on other sites
the shader is yep the same for every tile, but the parameters we inject into the shader to work correctly change every draw, I do not understand the "pack" for similar tiles, i can just "pack" into a batch every layer but the problem is not this .. the problem is that the shader affacted others draw that should not be affected by the shader

[Edited by - FOOLVER on September 11, 2009 11:45:51 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this