SFML community forums
Help => Graphics => Topic started by: heishe 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?
-
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?
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?
-
You have to send the texture size to the shader, so that it can compute the proper offset (which is 1/size).
-
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:
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:
texture background
effect
{
_out=background(_in);
}
draws the picture upside down (but x-values remain the same). Is that intended?