Jump to content
  • Advertisement
Sign in to follow this  
ms75214

GLSL

This topic is 2548 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Here is how random number generator works in C++ (actually, source code of it):

int seed = 1;

int rand()
{
seed = seed * 22695477 + 1;
return (seed>>16)&0x7fff;
}

void srand(int value)
{
seed = value;
rand();
}


I these functions can be used on GPU. Now it's your play time with it.

Best wishes, FXACE.

Share this post


Link to post
Share on other sites

Here is how random number generator works in C++ (actually, source code of it):

I these functions can be used on GPU. Now it's your play time with it.

Best wishes, FXACE.


There is no way to write to a global variable in GLSL so that method doesn't work. In GLSL the closing thing to random numbers is creating noise. This involves taking input data, such as a texture coordinate or world position, then you pass those values through a function that scrambles up that information to make it appear random. This means that the noise function will always generate the same output with the given input. This means that the "random" values will be the same every frame unless the input values are changed. To make different values each frame for a given set in input, introduce a value that changes every frame, such as time, into the noise function. The link supplied in the first post shows how to do this.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!