Jump to content
  • Advertisement
Sign in to follow this  
monkeyboi

produce randomness in shader

This topic is 2849 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

how to produce a random number in shader?
I know I can use extern variable to import a random from cpu
But in my app I create an array to store particles
when one's position is high then a certain value I replace it back to the position of emitter and I wanna give it some randomness to make them around the emitter instead of just at emitter's pos
so if I use extern variable once more than one particle need to replace do they get the same random number, if yes there is not randomness in it any more

Share this post


Link to post
Share on other sites
Advertisement
Every random generator need a seed. If you represent the positions as pixels in a pixel shader, each position will have their own seed but I don't know how your simulation is implemented.

Share this post


Link to post
Share on other sites
I did think about using noise texture but I need random tex coordinate as well that means I also need to make some random number

In my app, I used texture to store the position of particles each frame sample from this texture and check the value if it is higher than certain value raplace it back to the position of emitter,then store position as color in another texture(double buffer swap each frame). and here is my problem I wanna make some randomness. you said every random generator need a seed, so assume I hav seeds already is there any function or way to generate random number?

Share this post


Link to post
Share on other sites
Quote:
Original post by monkeyboi
I did think about using noise texture but I need random tex coordinate as well that means I also need to make some random number
I pass a uniform float containing the time since the simulation began (updated each frame), and an instance ID (a unique integer value for each renderable object, generated on the CPU). You can combine the two of those to obtain a random seed, and then use that to index into your noise texture.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!