produce randomness in shader

Started by
3 comments, last by swiftcoder 13 years, 6 months ago
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
Advertisement
Use a noise texture

http://www.gamedev.net/community/forums/topic.asp?topic_id=389617
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.
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?
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.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

This topic is closed to new replies.

Advertisement