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

Author Topic: PostFX - random numbers?  (Read 6319 times)

0 Members and 1 Guest are viewing this topic.

peaman

  • Newbie
  • *
  • Posts: 8
    • View Profile
PostFX - random numbers?
« on: May 11, 2008, 01:54:40 pm »
Hello

Anybody knows how to generate random numbers in glsl? I'm trying to write a blur effect with jitter. I know there are functions like noise1, noise2 etc. but somehow they seem not to do anything but return zero. Maybe I'm doing something wrong?

best regards

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
PostFX - random numbers?
« Reply #1 on: May 11, 2008, 02:00:39 pm »
I've read somewhere that noise functions where not implemented for some version of GLSL.

Why don't you just pass these numbers as variables from your C++ code ?
Laurent Gomila - SFML developer

peaman

  • Newbie
  • *
  • Posts: 8
    • View Profile
PostFX - random numbers?
« Reply #2 on: May 11, 2008, 02:54:27 pm »
Hi

I don't pass the numbers because I need different ones for each pixel that is processed.
I'm thinking now about using a texture that contains the noise. That might be a workaround.

deps

  • Newbie
  • *
  • Posts: 14
    • View Profile
PostFX - random numbers?
« Reply #3 on: May 11, 2008, 03:38:07 pm »
I'm haven't used GLSL at all, ever, but you can still create functions in it? If so, why don't you make your own random function?

It won't be truly random, but there doesn't exist anything remotely like a truly random function on home computers. Yet it might be good enough to do what you want. You can pass values to it from C++ to use as a random seed. I'm sure you would find info about this rather quickly using google.

peaman

  • Newbie
  • *
  • Posts: 8
    • View Profile
PostFX - random numbers?
« Reply #4 on: May 11, 2008, 04:16:20 pm »
Quote from: "deps"
I'm haven't used GLSL at all, ever, but you can still create functions in it? If so, why don't you make your own random function?

It won't be truly random, but there doesn't exist anything remotely like a truly random function on home computers. Yet it might be good enough to do what you want. You can pass values to it from C++ to use as a random seed. I'm sure you would find info about this rather quickly using google.


thanks for the tip, but glsl has no static variables. Another problem is that there are no bitwise operations.

deps

  • Newbie
  • *
  • Posts: 14
    • View Profile
PostFX - random numbers?
« Reply #5 on: May 11, 2008, 04:26:44 pm »
Make it simpler? :)
Psuedo code:
Code: [Select]

int table[] = { 0,9,1,8,2,7,3,6,4,5 }
int random()
{
  int v = table[i];
  i++;
  if( i > 9 ) i = 0;
  return v;
}

Make the table bigger, is a nice suggestion. :P

But then again, a texture might be a better solution.

workmad3

  • Jr. Member
  • **
  • Posts: 71
    • View Profile
PostFX - random numbers?
« Reply #6 on: May 11, 2008, 07:07:46 pm »
texture is a better idea as textures are arrays for glsl :)

so a noise texture is the same as that idea, but with a large, auto-generated array :)

 

anything