Sign in to follow this  

HLSL random function?

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

Guest Anonymous Poster
Under the Intrinsic Functions listing in the DX-HLSL docs, there does not exist a random number generator. You should be able to implement one yourself using a standard template, but the general complexity of a "good" random number generator would probably exceed the amount of allowed instructions in the lower pixel shader versions. The seed could then be supplied by an externally set parameter, or taken from some input data out of the vertex data, texel data, or a combination of both.

Share this post


Link to post
Share on other sites
Your best bet is to get the CPU to generate some random numbers and then try and find a "random-ish" way of looking at said numbers [smile]

For example, if you're going to heavily use random numbers create a 1024*1024 texture - you can store 4194304 8-bit random offsets created by the CPU.

For each pass, indicate a particular sub-region that it can examine and then do some screen-space look-up (etc..) to pick a value inside that region. Texture filtering could work nicely here as well.

Sure, it's not as good as a proper random number generator but you can probably get close enough...

hth
Jack

Share this post


Link to post
Share on other sites
That certainly sounds like an interesting idea, I will have to try and figure that out. Also, how would I get a texture to scroll across a plane? I thought adding a delta time to the texture coordinates would do it, but that just stretches it out.

-Chris

Share this post


Link to post
Share on other sites
You might want to look into "texture coordinate transformation" - there are a number of articles/threads/resources on it. Basically it's a way of applying a matrix-transform (scaling/rotation/translation etc..) to texture coordinates - might well do what you're after [smile]

Jack

Share this post


Link to post
Share on other sites

This topic is 4391 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.

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