Hello Guest

Author Topic: Shader Issues [Solved]  (Read 132448 times)

0 Members and 1 Guest are viewing this topic.

BretHudson

  • Member
  • Posts: 15
  • indie(Function); CEO
    • View Profile
    • BretHudson.com
Shader Issues [Solved]
« on: November 15, 2013, 03:08:39 AM »
SOLUTION:
If you're here for finding out a solution to your shader issues/problems, and it looks like the following, we have your answer.



Kyle and I tried figuring it out over the course of a couple weeks in the posts below. However, the solution is as simple as making sure the file is saved correctly. You need to make sure that you save the file with UTC-8 encoding. If you don't, weird shit happens and the shader compiler will try to murder you.



Save your thanks for Kyle.


ORIGINAL POST:
I don't know if you replied on the old forum, since it was deleted.

I'm having issues getting Shaders to load. Here's my project: https://www.dropbox.com/s/n2pa0u6jhc8x9jm/ottertest.zip

I'm just using the typical
Code: [Select]
game.Surface.AddShader(new Shader("Assets/pixelate.frag", ShaderType.Fragment));
Also tried
Code: [Select]
game.Surface.AddShader(new Shader(ShaderType.Fragment, @"C:\Users\Bret\Documents\Visual Studio 2012\Projects\ottertest\ottertest\Assets\pixelate.frag"));

The shader is
Code: [Select]
uniform sampler2D texture;
 
uniform sampler2D anothertexture;
 
void main() {
     
    vec2 coord = gl_TexCoord[0].xy;
    vec4 other_color = texture2D(anothertexture, coord);
 
    vec4 pixel_color = texture2D(texture, coord + other_color.rg - 0.5);
    vec4 final_color = pixel_color;
 
    final_color.rgb += other_color.rgb;
    final_color.rgb /= 2;
 
    gl_FragColor = pixel_color;
 
}
« Last Edit: November 22, 2013, 06:00:21 PM by BretHudson »

Kyle

  • Administrator
  • Member
  • Posts: 258
    • View Profile
Re: Shader Issues
« Reply #1 on: November 15, 2013, 01:13:19 PM »
Planning on looking into this tomorrow, it's on my to-do list!

BretHudson

  • Member
  • Posts: 15
  • indie(Function); CEO
    • View Profile
    • BretHudson.com
Re: Shader Issues
« Reply #2 on: November 15, 2013, 01:52:07 PM »
Planning on looking into this tomorrow, it's on my to-do list!
Thank you so much! I really want to port the game I'm working on from AS3 to C# for this jam so I can use some sick shader effects. My C++ engine's currently in an unstable state and can't fix it, so if I'd be able to use Otter, it'd be fantastic. :D

Kyle

  • Administrator
  • Member
  • Posts: 258
    • View Profile
Re: Shader Issues
« Reply #3 on: November 15, 2013, 03:40:00 PM »
Just a quick note, that shader you're trying requires a second texture to be passed in as the "anothertexture" parameter, and I'm not sure what will happen if you're not passing one in.

BretHudson

  • Member
  • Posts: 15
  • indie(Function); CEO
    • View Profile
    • BretHudson.com
Re: Shader Issues
« Reply #4 on: November 16, 2013, 10:22:07 PM »
Just a quick note, that shader you're trying requires a second texture to be passed in as the "anothertexture" parameter, and I'm not sure what will happen if you're not passing one in.
Didn't have any effect in C++/SFML. Tried removing that portion of the shader, didn't change the bug in Otter. Any luck yet?

Kyle

  • Administrator
  • Member
  • Posts: 258
    • View Profile
Re: Shader Issues
« Reply #5 on: November 17, 2013, 04:28:54 AM »
So I downloaded your example project, set it up, and did this in program.cs:

Code: [Select]
            Shader shader = new Shader("Assets/edge.frag");
            game.Surface.AddShader(shader);

            game.FirstScene = new TestScene();
           
            game.Start(); //starts the game loop

And got this:


(the screencap is dark due to a monitor dimming program haha)

Sooo I'm not sure why it's working for you.  Are you certain that you have your shaders set to Copy if Newer in your Assets folder in the project?  Some the errors you talked about on the old forums looked related to missing files, and I noticed in your project that the shaders aren't set to copy.

BretHudson

  • Member
  • Posts: 15
  • indie(Function); CEO
    • View Profile
    • BretHudson.com
Re: Shader Issues
« Reply #6 on: November 17, 2013, 04:43:57 PM »
So I downloaded your example project, set it up, and did this in program.cs:

Code: [Select]
            Shader shader = new Shader("Assets/edge.frag");
            game.Surface.AddShader(shader);

            game.FirstScene = new TestScene();
           
            game.Start(); //starts the game loop

And got this:


(the screencap is dark due to a monitor dimming program haha)

Sooo I'm not sure why it's working for you.  Are you certain that you have your shaders set to Copy if Newer in your Assets folder in the project?  Some the errors you talked about on the old forums looked related to missing files, and I noticed in your project that the shaders aren't set to copy.
My shaders were not set to copy if newer. However, changeing that results in the same error. Are there any other special properties that I should add to the shader file? A special Build Action? Otherwise I'm completely stumped.

Also, could you upload your edited version to see if it compiles right on my machine?

Kyle

  • Administrator
  • Member
  • Posts: 258
    • View Profile
Re: Shader Issues
« Reply #7 on: November 17, 2013, 08:09:32 PM »

BretHudson

  • Member
  • Posts: 15
  • indie(Function); CEO
    • View Profile
    • BretHudson.com
Re: Shader Issues
« Reply #8 on: November 17, 2013, 09:51:32 PM »
Here's the project:

https://dl.dropboxusercontent.com/u/3194991/TestShaderStuff.zip

It doesn't work! [insert going insane smile here]

I'm using Visual Studio 2012 Ultimate. Perhaps you're using a different version? Maybe there's some settings you've changed?

Kyle

  • Administrator
  • Member
  • Posts: 258
    • View Profile
Re: Shader Issues
« Reply #9 on: November 18, 2013, 12:40:13 AM »
Using Visual C# 2010 express, but I can't imagine there being much of a difference between the two.  I have VS 2012 on my one laptop and I can try it on there when I get a chance.  What is the error you're getting?  Can you not even get the bare bones SFML shader example to work? (Sorry if you said this before in the old forums, I forget :I)

I'm assuming that your laptop or whatever you're developing on has the capability to use shaders as well, right?

BretHudson

  • Member
  • Posts: 15
  • indie(Function); CEO
    • View Profile
    • BretHudson.com
Re: Shader Issues
« Reply #10 on: November 18, 2013, 07:14:35 AM »
Using Visual C# 2010 express, but I can't imagine there being much of a difference between the two.  I have VS 2012 on my one laptop and I can try it on there when I get a chance.  What is the error you're getting?  Can you not even get the bare bones SFML shader example to work? (Sorry if you said this before in the old forums, I forget :I)

I'm assuming that your laptop or whatever you're developing on has the capability to use shaders as well, right?


I'll download VS 2010 express on my other laptop later today and see if I can get it working with that. I believe I tried doing the bare bones SFML shader, with no luck. However, they compile flawlessly in C++, meaning the computer definitely supports them.

EDIT: If you want, we could use TeamViewer. Just Tweet me (@BretHudson) if you want to go that route, since it seems to be an issue on my PC/version of VS rather than with SFML/Otter itself.
« Last Edit: November 18, 2013, 07:57:35 PM by BretHudson »

BretHudson

  • Member
  • Posts: 15
  • indie(Function); CEO
    • View Profile
    • BretHudson.com
Re: Shader Issues
« Reply #11 on: November 19, 2013, 01:56:26 AM »
Downloaded and tested with Visual Studio C# 2010 on both of my laptops. No luck. :(

I'm starting to believe you're the only one who can get shaders to work properly, haha.
« Last Edit: November 19, 2013, 02:29:00 AM by BretHudson »

Kyle

  • Administrator
  • Member
  • Posts: 258
    • View Profile
Re: Shader Issues
« Reply #12 on: November 19, 2013, 12:37:21 PM »
I don't think that's the case since I've seen other people using Otter tweet pictures of them using Shaders, and if you can't even get SFML shaders to compile then there's something else going on.

BretHudson

  • Member
  • Posts: 15
  • indie(Function); CEO
    • View Profile
    • BretHudson.com
Re: Shader Issues
« Reply #13 on: November 19, 2013, 05:43:13 PM »
I don't think that's the case since I've seen other people using Otter tweet pictures of them using Shaders, and if you can't even get SFML shaders to compile then there's something else going on.
Bit strange I can't get it working on either of my PC's, though. What do you suggest I do? I can't seem to find anything on Google to help me out.