Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Shader not working on "newer" machines  (Read 4484 times)

0 Members and 3 Guests are viewing this topic.

heishe

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Shader not working on "newer" machines
« on: June 26, 2011, 09:37:57 pm »
Hey, I have this shader in my program:

Code: [Select]


uniform sampler2D texture;
uniform vec2 target_size;
uniform float scale;

vec4 bloom(vec4 original)
{
   return original*scale;
}

void main()
{
   vec4 color = texture2D(texture,gl_TexCoord[0].xy);
   vec2 step = scale/target_size;
   //right and left
   color *= texture2D(texture,gl_TexCoord[0].xy + vec2(step.x,0.0));
   color *= texture2D(texture,gl_TexCoord[0].xy + vec2(-step.x,0.0));
   //up and down
   color *= texture2D(texture,gl_TexCoord[0].xy + vec2(0.0,step.y));
   color *= texture2D(texture,gl_TexCoord[0].xy + vec2(0.0,-step.y));
   gl_FragColor = bloom(color);
}


It's a simple blur+bloom shader (I think it's gaussian blur, although I'm not sure about the terminology), which blurs the image according to a factor (bigger factor = bigger blur) and blooms it, also depending on the factor.

This shader runs on my really crappy old laptop, with Intel Integrated Graphics set (which uses software 2D rendering), but not on the PCs of two other people who tested the application. Both have ATI graphics cards (one of them has got a HD 5770, the other one a pretty new mobile graphics card).

A more simple shader, like this:

Code: [Select]

void main()
{
     gl_FragColor = vec4(0.0,1.0,0.0,1.0);
}


however, works perfectly fine with them and simply draws a green rectangle to every sprite that it is applied to.

What could this be? Could it be that "newer" graphics cards( HD 5770 isn't exactly new though, afaik OpenGL 3.0 ? ) don't support gl_TexCoord etc. anymore?

Cuban-Pete

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
Shader not working on "newer" machines
« Reply #1 on: June 26, 2011, 09:52:05 pm »
I'm no expert, but I think you need to define the version you are using.

Put this "#version 120" above the shader code.

I got it from here: http://en.wikipedia.org/wiki/GLSL

heishe

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Shader not working on "newer" machines
« Reply #2 on: June 28, 2011, 12:42:37 pm »
If I put that at the top of the shader it fails to compile the shader, telling me that this version is not supported by GL2.

Putting "#version 110" compiles, but it doesn't fix the problem on the other machines (shader still doesn't show anything).

Lo-X

  • Hero Member
  • *****
  • Posts: 618
    • View Profile
    • My personal website, with CV, portfolio and projects
Shader not working on "newer" machines
« Reply #3 on: June 28, 2011, 01:23:49 pm »
The code don't work.
Do you send the variable to the GLSL code ?
Because some aren't initialized if you use this code like this

heishe

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Shader not working on "newer" machines
« Reply #4 on: June 28, 2011, 01:34:45 pm »
of course I do. Otherwise it wouldn't work no my laptop, either. Target size is simply the size of the sprite (width/height), scale is just a factor that I send to the shader every frame, and the texture is the image of the sprite itself.

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Re: Shader not working on "newer" machines
« Reply #5 on: June 29, 2011, 03:49:51 am »
Quote from: "heishe"
This shader runs on my really crappy old laptop, with Intel Integrated Graphics set (which uses software 2D rendering), but not on the PCs of two other people who tested the application. Both have ATI graphics cards (one of them has got a HD 5770, the other one a pretty new mobile graphics card).
This is just a hunch, but what version of SFML are you using?
I use the latest build of SFML2

heishe

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Shader not working on "newer" machines
« Reply #6 on: June 29, 2011, 02:14:15 pm »
The 2.0 version as of about a week ago. I already thought about the ATI bug, but that (to my knowledge) has been fixed a long time ago.

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Shader not working on "newer" machines
« Reply #7 on: June 29, 2011, 06:44:24 pm »
Quote from: "heishe"
The 2.0 version as of about a week ago. I already thought about the ATI bug, but that (to my knowledge) has been fixed a long time ago.
It was fixed, so hrm. Maybe have them make sure their drivers are updated?
I use the latest build of SFML2

heishe

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Shader not working on "newer" machines
« Reply #8 on: June 29, 2011, 08:37:27 pm »
They certainly are. I also doubt that this is a driver problem.

Has anyone here tried the shader? It's not that hard to test. Just draw a sprite using this shader, and set the values of the variable to whatever you want them to be.

Lo-X

  • Hero Member
  • *****
  • Posts: 618
    • View Profile
    • My personal website, with CV, portfolio and projects
Shader not working on "newer" machines
« Reply #9 on: June 29, 2011, 09:57:15 pm »
Quote from: "heishe"
They certainly are. I also doubt that this is a driver problem.

Has anyone here tried the shader? It's not that hard to test. Just draw a sprite using this shader, and set the values of the variable to whatever you want them to be.


give us the C++ code, the GLSL code can't work like this.

heishe

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Shader not working on "newer" machines
« Reply #10 on: July 03, 2011, 12:12:33 pm »
Alright, here's a basic example of how to use the shader code:

Code: [Select]

#include <sfml/graphics.hpp>
#include <sfml/window.hpp>

int main()
{
    sf::RenderWindow window;
    window.Create(sf::VideoMode(800,600,32),"test");

    sf::Image i; i.LoadFromFile("load your favourite bitmap here");
    sf::Sprite spr(i,sf::Vector2f(300,300));
    sf::Shader bloomblur;
    bloomblur.LoadFromFile("put the shader in a text file and put it here");
    bloomblur.SetTexture("texture", *spr.GetImage());
    bloomblur.SetParameter("target_size",spr.GetSize());
    bloomblur.SetParameter("scale", 3.0f);

    bool running = true;
    while(running)
    {
       sf::Event e;
       while(sf::PollEvent(e)
       {
            if(e.Type == sf::Event::KeyPressed)
                 running =false;
       }

       window.Clear(sf::Color::Green);
       window.Draw(spr,bloomblur);
       window.Display();
    }
    return 0;
}


I've hacked this into the browser, so it may not work initially, however, since all of you know how to set up a basic application you should be able to fix it quickly.

It should work though.

 

anything