HLSL and XNA draw calls problem

Started by
6 comments, last by flery 14 years, 7 months ago
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
-----I am working on: xna isometric online rpg
Advertisement
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.
I already use immediate mode, use a batch for every tile draw is madness :(, I hope that will be another workaround
-----I am working on: xna isometric online rpg
Unless you pass SaveStateMode.SaveState when calling Effect.Begin, all of the shaders/render states/textures set by that Effect will remain set on the device after you call Effect.End.
we already pass the savestatemode in the begin, I tried none and savestate but sprite and items are already affected by the shader (and this is the main problem) :(
-----I am working on: xna isometric online rpg
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.
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]
-----I am working on: xna isometric online rpg
maybe more code would help. with pack i ment somesort of instancing to minimize drawcalls

This topic is closed to new replies.

Advertisement