• Advertisement
Sign in to follow this  

Spritebatch, source rectangles and pixel shaders

This topic is 1278 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi everyone,

I'm trying to write a depth mapping shader for a 2D game, inspired from this famous video.

Following the author's explanation on his blog, I was able to reproduce the desired effect in a test application.

Now I'm trying to include it in my actual game, which uses spritesheets and tilesets. What I really don't understand is: what happens inside the shader when you draw with SpriteBatch using a source rectangle? Will the TexCoord be relative to the whole spritesheet? Or just to the actual source rectangle?

Since I also need to pass other textures to the same shader (normal / height maps), and they're all spritesheets of the same size, do I need to scale/adjust the texture coordinates to the source rectangle, or will SpriteBatch take care of everything?

 

Sorry if I'm not clear or if there's a mistake somewhere, English is not my language ^^'

Share this post


Link to post
Share on other sites
Advertisement

When using sprite sheets with SpriteBatch, the coordinates are pixel locations.

 

So if you have a 16 by 16 sprite at x=0,y=0  you create a source Rectangle new Rectangle(0,0,16,16) and pass that to spritebatch

 

Internally that will be converted to floating point values, you don't have to worry.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement