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

Author Topic: Drawing with shader = only quarter of the screen  (Read 2992 times)

0 Members and 1 Guest are viewing this topic.

Vovosunt

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Drawing with shader = only quarter of the screen
« on: April 06, 2012, 08:13:18 pm »
I've been using the following sample vertex and frag shaders (comments are not mine):
VERTEX:
varying vec2 vTexCoord;
 
// remember that you should draw a screen aligned quad
void main(void)
{
   //gl_Position = ftransform();
 
   // Clean up inaccuracies
   vec2 Pos;
   Pos = sign(gl_Vertex.xy);
 
   gl_Position = vec4(Pos, 0.0, 1.0);
   // Image-space
   vTexCoord = Pos * 0.5 + 0.5;
}
FRAGMENT:
uniform sampler2D RTBlurH; // this should hold the texture rendered by the horizontal blur pass
varying vec2 vTexCoord;
 
const float blurSize = 1.0/512.0;
 
void main(void)
{
   vec4 sum = vec4(0.0);
 
   // blur in y (vertical)
   // take nine samples, with the distance blurSize between them
   sum += texture2D(RTBlurH, vec2(vTexCoord.x, vTexCoord.y - 4.0*blurSize)) * 0.05;
   sum += texture2D(RTBlurH, vec2(vTexCoord.x, vTexCoord.y - 3.0*blurSize)) * 0.09;
   sum += texture2D(RTBlurH, vec2(vTexCoord.x, vTexCoord.y - 2.0*blurSize)) * 0.12;
   sum += texture2D(RTBlurH, vec2(vTexCoord.x, vTexCoord.y - blurSize)) * 0.15;
   sum += texture2D(RTBlurH, vec2(vTexCoord.x, vTexCoord.y)) * 0.16;
   sum += texture2D(RTBlurH, vec2(vTexCoord.x, vTexCoord.y + blurSize)) * 0.15;
   sum += texture2D(RTBlurH, vec2(vTexCoord.x, vTexCoord.y + 2.0*blurSize)) * 0.12;
   sum += texture2D(RTBlurH, vec2(vTexCoord.x, vTexCoord.y + 3.0*blurSize)) * 0.09;
   sum += texture2D(RTBlurH, vec2(vTexCoord.x, vTexCoord.y + 4.0*blurSize)) * 0.05;
 
   gl_FragColor = sum;
}

The shader works, but when I draw a full-screen sprite with it, only the top-right quarter of the sprite gets drawn:


Any ideas?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Drawing with shader = only quarter of the screen
« Reply #1 on: April 06, 2012, 08:16:41 pm »
Normalized screen coordinates range from -1 to 1, not from 0 to 1.
Laurent Gomila - SFML developer

Vovosunt

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Drawing with shader = only quarter of the screen
« Reply #2 on: April 06, 2012, 09:48:56 pm »
Normalized screen coordinates range from -1 to 1, not from 0 to 1.
Oh. Ok, I get it. But I've still got no idea how to fix it.
Making vTexCoord = Pos makes it show continuously shrinking version of the sprite.
Looks cool, but is useless  :-\

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Drawing with shader = only quarter of the screen
« Reply #3 on: April 06, 2012, 09:57:33 pm »
How do you render your fullscreen sprite? If it's a SFML sprite you need to uncomment this line:
//gl_Position = ftransform();
Laurent Gomila - SFML developer

Vovosunt

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Drawing with shader = only quarter of the screen
« Reply #4 on: April 06, 2012, 10:10:48 pm »
How do you render your fullscreen sprite? If it's a SFML sprite you need to uncomment this line:
//gl_Position = ftransform();
It's an SFML sprite with a texture from a renderTexture. Uncommenting doesn't help :(

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Drawing with shader = only quarter of the screen
« Reply #5 on: April 06, 2012, 10:30:47 pm »
If you keep the following line, the uncommented one is useless
gl_Position = vec4(Pos, 0.0, 1.0);

What is it supposed to do?
Laurent Gomila - SFML developer

Vovosunt

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Drawing with shader = only quarter of the screen
« Reply #6 on: April 07, 2012, 04:26:10 pm »
It's just a vertical (non-Gaussian) blur. I've got no idea what am I doing anymore O_O