# Using halton sequnce in shader

This topic is 658 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

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

1. 1
Rutin
26
2. 2
3. 3
4. 4
5. 5

• 11
• 10
• 13
• 20
• 14
• ### Forum Statistics

• Total Topics
632950
• Total Posts
3009380
• ### Who's Online (See full list)

There are no registered users currently online

×