SFML community forums

Help => Graphics => Topic started by: Raptor2277 on August 26, 2015, 06:01:05 pm

Title: SFML.Net, Failed to compile Fragement Shader error(#60)
Post by: Raptor2277 on August 26, 2015, 06:01:05 pm
It runs fine on my computer and some of my friends' computers. But when I try it on others, I get this error.

Failed to compile fragment shader:
Fragment shader failed to compile with the following erros:
ERROR: error(#60) Unknown char: ""
ERROR: error(#273) 1 compilation erros. No code generated

Thnks in advance.
Title: Re: SFML.Net, Failed to compile Fragement Shader error(#60)
Post by: Raptor2277 on August 26, 2015, 06:36:35 pm
Here is the shader.

uniform vec2 lightPos;
uniform vec3 lightColor;
uniform float screenHeight;

uniform sampler2D texture;

void main()
{   
   lightPos.y = screenHeight - lightPos.y;
   float length = length(lightPos - gl_FragCoord.xy);
   float attenuation = 1.0 / (length/10) + .2;

   vec4 color2 = vec4(lightColor, 1) * attenuation;
   
   vec4 color = texture2D(texture,gl_TexCoord[0].st);

   if(color == vec4(0,0,0,1))
      gl_FragColor = color;
   else
      gl_FragColor = color2;

}
Title: Re: SFML.Net, Failed to compile Fragement Shader error(#60)
Post by: Jesper Juhl on August 26, 2015, 07:15:41 pm
Are you sure that shaders are available in the computers that have a problem?
What does
sf::Shader::isAvailable()
return?

You should always test for shader support with sf::Shader::isAvailable() before trying to use shaders and then either tell the user that shader support is required and exit or fall back to running without shaders.
Title: Re: SFML.Net, Failed to compile Fragement Shader error(#60)
Post by: Raptor2277 on August 26, 2015, 10:47:39 pm
It is.
Title: Re: SFML.Net, Failed to compile Fragement Shader error(#60)
Post by: Hapax on August 26, 2015, 10:57:05 pm
It is.
Which question does this answer?
Title: Re: SFML.Net, Failed to compile Fragement Shader error(#60)
Post by: Ztormi on August 26, 2015, 11:25:29 pm
Reminds me of a situation at work some time ago. I had copypasted a piece of Javascript from some website and ran into a syntax error on an empty line  :o

Turned out there was a nonprintable character which Visual Studio and web debugger didn't recognize and I just wasted an hour or two wondering what the heck can be wrong with an empty line of code...
Title: Re: SFML.Net, Failed to compile Fragement Shader error(#60)
Post by: Raptor2277 on August 27, 2015, 04:17:35 am
The computer supports shaders because I've had in not compile once because one didn't support shaders. It gave an error before it even began compiling.

I've also tried some debugging like reading the file and outputting it to cmd before trying to create the shader class. It reads fine and prints the contents of the txt file fine.
Title: Re: SFML.Net, Failed to compile Fragement Shader error(#60)
Post by: Raptor2277 on August 28, 2015, 05:21:48 pm
I have made it work.

It turns out that it might be an encoding problem. What I did is create a new text document on the computer that I'm trying to make it work on and copy the contents of the shader there. Then I "save as" replacing the original shader. It loads fine with no errors.

The problem is I don't know anything about encoding. If someone could point me in the right direction how to write and safe shaders in a way that it will work on all platforms.

Thank you all for your help.