Hi!
I want to use this shader (https://github.com/libretro/glsl-shaders/blob/master/xbr/shaders/xbr-mlv4-multipass/xbr-mlv4-pass1.glsl) but all i get is a black image. I know the texture is loaded correctly because i can render it without the shader.
This is how i load and use the shader, which is probably not correct.
void init() {
shader.loadFromFile("glsl-shaders-master/xbr/shaders/xbr-mlv4-multipass/xbr-mlv4-pass1.glsl", sf::Shader::Vertex);
shader.loadFromFile("glsl-shaders-master/xbr/shaders/xbr-mlv4-multipass/xbr-mlv4-pass1.glsl", sf::Shader::Fragment);
shader.setUniform("MVPmatrix", sf::Glsl::Mat4(bg_sprite.getTransform()));
shader.setUniform("FrameDirection", 1);
shader.setUniform("FrameCount", 100);
shader.setUniform("OutputSize", sf::Vector2f(500, 500));
shader.setUniform("TextureSize", sf::Vector2f(500, 500));
shader.setUniform("InputSize", sf::Vector2f(500, 500));
shader.setUniform("Texture", sf::Shader::CurrentTexture);
//more code
}
void draw() {
window.draw(bg_sprite, &shader);
//more code
}
This are the errors i get:
Uniform "MVPmatrix" not found in shader
Uniform "FrameDirection" not found in shader
Uniform "FrameCount" not found in shader
Uniform "OutputSize" not found in shader
Uniform "TextureSize" not found in shader
Uniform "InputSize" not found in shader
Uniform "Texture" not found in shader
I'm a complete ignorant in shaders, but have you tried anothe one, just for testing? I get this error:
Failed to compile vertex shader:
0:368(1): error: syntax error, unexpected end of file
I could use this simple shader which is not useful to me, it only paints some colors on top of everything. But other shaders that i downloaded do not seem to work.
uniform vec2 u_resolution;
void main() {
vec2 st = gl_FragCoord.st/u_resolution;
gl_FragColor = vec4(st.x, st.y, 0.0, 1);
}
shader.loadFromFile("rainbow.glsl", sf::Shader::Fragment);
shader.setUniform("u_resolution", sf::Glsl::Vec2{ 100, 100 });*/
I finally got it working! I had to separate the shader in two different files, one for the vertex shader and one for the fragment shader.
I also had to feed OutputSize, TextureSize, and InputSize uniform variables to the verex shader. Then in the main() function of the vertex shader i added these lines and delete their previous declarations.
mat4 MVPMatrix = gl_ModelViewProjectionMatrix;
vec4 VertexCoord = gl_Vertex;
vec4 TexCoord = gl_TextureMatrix[0] * gl_MultiTexCoord0;