Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Spritebatch, source rectangles and pixel shaders


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 quelluomo   Members   -  Reputation: 120

Like
0Likes
Like

Posted 22 July 2014 - 03:31 AM

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



Sponsor:

#2 Stainless   Members   -  Reputation: 1014

Like
0Likes
Like

Posted 22 July 2014 - 06:00 AM

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.



#3 quelluomo   Members   -  Reputation: 120

Like
0Likes
Like

Posted 22 July 2014 - 07:05 AM

Looks like it was simpler than I thought ph34r.png

Thanks man, cheers biggrin.png






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS