Sign in to follow this  

Using halton sequnce in shader

Recommended Posts

Hi!

 

I'm trying to add importance sampling to my screen space reflection shader. Currently I'm following the approach mentioned in Frostbite's stochastic ssr presentation but I am confused about how to use halton random number in shader.

First I pre-calculate and store the halton sequence in an array and then pass the array to shader. After that I use the following code to get the random numbers in GLSL shader.

float rand(vec2 co){
    return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}


void main()
{
..........
//somwhere in main
    float random1=rand(TexCoords);
    float random2=rand(TexCoords+vec2(0.301f));
    int index1=int(random1*100);
    int index2=int(random2*100);
    vec2 Xi=vec2(haltonNum[index1],haltonNum[index2]);
    ImportanceSampleGGX(Xi, roughness);

..........
}

Then I will calculate the hit position, reproject it to previous frame and sample its color and neighbour pixels' color .

 

Unfortunately my result image has a lot of flickering black holes/gaps. It looks like the generated samples are pretty unstable. However if I sample Gbuffer directly I won't have such issue. Some other random functions(like the rand() presented above) work fine but the result is extremely noisy.

 

Does anyone know how to use halton sequence? Any help would be appreciated.

Edited by megav0xel

Share this post


Link to post
Share on other sites
  • Why random1*100 and random2*100? How long is the haltonNum array? How do you deal with out of range indices?
  • What does ImportanceSampleGGX return? Where do multiple samples, which should need a pseudorandom point each, come from?
  • "I will calculate the hit position, reproject it to previous frame and sample its color and neighbour pixels' color".
    Not very clear, but if the "hit position" depends on the pseudorandom points, how do you guarantee it is close to the one in the previous frame and not jumping around between unrelated surfaces?

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