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

Author Topic: Shaders: Accessing pixels around _in  (Read 1955 times)

0 Members and 1 Guest are viewing this topic.

heishe

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Shaders: Accessing pixels around _in
« on: March 14, 2010, 05:33:04 am »
Hi.

I've got an 2-dimensional (float) array that I need to pass on to my shader.

More specifically: The 2D-Array is a heightmap that I need for calculations inside the shader. Each point (x,y) contains the height of that location.

I know that 2D-Arrays are only supported by geometry shaders, so how would I do that? I guess the best way would be to create a heightmap-texture using my heightmap-array, but how can I do that using sf::Image?

heishe

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Shaders: Accessing pixels around _in
« Reply #1 on: March 14, 2010, 10:19:38 am »
OK, using sf::Image I created the appropriate heightmap. This way I can pass the Image on to my shader program.

Now something else:
Within my algorithm, I check the "neighbours" of every pixel. But in the PostFx Tutorial here on sfml-dev.org it states that the coordinates of _in are in the range from 0 to 1. How do I (for example) access the pixel to the left of the current pixel?

Quote

float red = texture(vec2(_in.x-1.0,_in.y)).r;


obviously wont work.

by the way: why does sf::PostFX::SetTexture pass on images upside down?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Shaders: Accessing pixels around _in
« Reply #2 on: March 14, 2010, 11:39:39 am »
You have to send the texture size to the shader, so that it can compute the proper offset (which is 1/size).
Laurent Gomila - SFML developer

heishe

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Shaders: Accessing pixels around _in
« Reply #3 on: March 14, 2010, 12:16:37 pm »
Quote from: "Laurent"
You have to send the texture size to the shader, so that it can compute the proper offset (which is 1/size).


Thanks! :)

edit: Still, why is my image upside down when I pass it to the shader using PostFX::SetTexture? Code is pretty much straightforward:

Code: [Select]

sf::Image someimage; someimage.LoadFromFile("foo.bmp");
sf::PostFX what; what.LoadFromFile("whaat.okay");
what.SetTexture("background",&someimage);

//....
mywindow.Draw(what);


Using this simple shader:

Code: [Select]

texture background

effect
{
    _out=background(_in);
}


draws the picture upside down (but x-values remain the same). Is that intended?