I've been testing out fragment shaders in SFML, trying to learn how to write and use them and I've run into a recurring problem. Every shader distorts the texture. Top left is the distorted test texture, top right and bot left are there for comparison along the axis.
The texture is 512x512 pixels in size and the sprite has the same dimensions. I've narrowed down the problem to this line.
vec2 texCoord = (gl_FragCoord.xy / sourceSize.xy);
Where sourceSize is the resolution. The value I'm passing in being (512,512). I've tested around with different values, the closest to the correct output is when I pass in the values (512, 1086) giving this.
Top left is the distorted texture. The X axis is correct but the Y axis is stretched enough to hide the numbers and enlarge the border.
Currently the shader does nothing for testing purposes.
uniform sampler2D source;
uniform vec2 sourceSize;
uniform float time;
void main( void )
{
vec2 texCoord = (gl_FragCoord.xy / sourceSize.xy); //Value between 0.0 and 1.0
texCoord = vec2 (texCoord.x,1.0-texCoord.y); //Inverts the y component. GLSL treats bot left corner as the origin, sfml treats top left as it.
vec4 Color = texture2D(source, texCoord);
gl_FragColor = Color;
}
I'm not sure how to fix this. What I'm trying to achieve is a shader that doesn't distort the base texture so I can build on from there. Thanks for any help you can give.
texCoord
in your shader would go from 0 to 0.5. I don't know how you would do it in SFML, but you need to ask for the UV coordinates \$\endgroup\$