I have a path tracing program which I created a while ago and I thought it would be an awesome project to convert it to work on the GPU using a HLSL pixel shader. However, path tracing requires thousands of random numbers for each pixel of the final image, and there is no random number generator in HLSL. So, I came up with an idea to create my own:
1) Create an array of random numbers in the main program, with the resolution of the final path traced image. Send it into the shader as a texture.
2) At the top of the pixel shader, create a variable which keeps track of how many random number calls have been made for this pixel. Let's call it nRandomCalls. Every time the path tracer asks for a new random number, increment it by 1.
3) Sample the noise texture using the location of the current pixel. This assigns a value to each pixel which is random, but always the same for this particular pixel. Use the obtained number to generate a set of texture coordinates.
Now, here is my idea for how to get the random numbers themselves. Every time a new random number is needed...
4) Increment nRandomCalls by 1.
5) Sample the noise texture again using the texture coordinates from part (3) plus an offset which is determined using nRandomCalls. This produces our final random number.
As long as the initial array is random enough, this should act as a good source of noise, right? Is there any reason why this wouldn't work? Thanks