Sign in to follow this  
monkeyboi

produce randomness in shader

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this