Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [Bug?] sf::Shader, CurrentImage and SetSubRect  (Read 2306 times)

0 Members and 1 Guest are viewing this topic.

Xorlium

  • Jr. Member
  • **
  • Posts: 84
    • View Profile
[Bug?] sf::Shader, CurrentImage and SetSubRect
« on: November 03, 2010, 07:47:18 am »
Hi,

I'm sorry, my problem is a bit complicated to explain, let me try.

In SFML 2, I'm having the following problem:

I have two images, say Big and Small. Say Big is 200x200 and Small is 100x100.

Then I have a sprite Sprite. I set the image of Sprite to Big, but tell it to only use SubRect of size 100x100 (with sf::Sprite::SetSubRect). Then, I have a shader, which accepts two "variables" of type uniform sampler2D. The two variables are "current" and "other".

I set the "current" to be sf::Shader::CurentImage(). I set "other" to be 'Small'.

Then I do App.Draw(Sprite, Shader).

What you'd expect is that since both images are of size 100x100 (because I chose a subrect of Big of size 100x100), the shader would match them. But the shader actually resizes Small and takes only a quarter of Small, enlarges it, and matches it with Big.

Let me know if any of this makes sense, and if this is indeed the wanted behaviour.

Xorlium

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[Bug?] sf::Shader, CurrentImage and SetSubRect
« Reply #1 on: November 03, 2010, 08:11:43 am »
In your shader, you use the texture coordinates from the current pixel to do texture lookup, right? But as the sprite uses a subrect of its image, the texture coordinates do not cover the entire image, only a quarter of it. So if you use the same coordinates for the other texture, you will get the same quarter of it (not in size, but in ratio -- texture coordinates are defined as factors in range [0, 1], not in pixels).

So you need to use different texture coordinates for the other texture. Maybe you can pass a factor to your shader, that always maps the current texture coordinate to the range [0, 1]?
Laurent Gomila - SFML developer

Xorlium

  • Jr. Member
  • **
  • Posts: 84
    • View Profile
[Bug?] sf::Shader, CurrentImage and SetSubRect
« Reply #2 on: November 03, 2010, 08:46:32 am »
Oh, I see. Heh, the problem is I don't really understand shaders or how they work.

Thanks Laurent!

 

anything