Spritebatch, source rectangles and pixel shaders

Started by
1 comment, last by quelluomo 9 years, 9 months ago

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 ^^'

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.

Looks like it was simpler than I thought ph34r.png

Thanks man, cheers biggrin.png

This topic is closed to new replies.

Advertisement