I'm trying to implement screen space reflections and global illumination, but I'm encountering a performance drop when I sample in a random direction. The strange thing is that when I sample with roughness set to 0, the renderer runs smoothly as usual. However, when the roughness is even slightly greater than 0, the program begins to lag significantly.
Here’s the function I’m using to generate random noise:
vec3 hash(vec3 a){
a = fract((a * 10+randomSeed) * 0.8);
a += dot(a, a.yxz + 19.19);
return fract((a.xxy + a.yxx)*a.zyx);
}
I calculate the reflected direction like this:
vec3 specReflected = reflect(normalize(viewPos), viewNormal);
vec3 randDir = normalize(hash(viewPos*12)-0.5);
vec3 reflected = specReflected+linRoughness*randDir;
Finally, I use the screenTrace function to find an intersection with the scene (sorry for the messy code).
By the way, I’m new to graphics programming and coding in general, so I apologize if my code is messy and if my questions are basic.