2

I'm experimenting trying to implement "as simple as possible" SSR in GLSL. Any chance someone could please help me set up an extremely basic ssr code?

I do not need (for now) any roughness/metalness calculations, no Fresnel, no fading in-out effect, nothing fancy - I just want the most simple setup that I can understand, learn and maybe later improve upon.

I have 4 source textures: Color, Position, Normal, and a copy of the previous final frame's image (Reflection)

attributes.position is the position texture (FLOAT16F) - WorldSpace

attributes.normal is the normal texture (FLOAT16F) - WorldSpace

sys_CameraPosition is the eye's position in WorldSpace

rd is supposed to be the reflection direction in WorldSpace

texture(SOURCE_2, projectedCoord.xy) is the position texture at the current reflection-dir endpoint

vec3 rd = normalize(reflect(attributes.position - sys_CameraPosition, attributes.normal));

vec2 uvs;
vec4 projectedCoord;

for (int i = 0; i < 10; i++)
{
    // Calculate screen space position from ray's current world position:
    projectedCoord = sys_ProjectionMatrix * sys_ViewMatrix * vec4(attributes.position + rd, 1.0);
    projectedCoord.xy /= projectedCoord.w;
    projectedCoord.xy = projectedCoord.xy * 0.5 + 0.5;

    // this bit is tripping me up
    if (distance(texture(SOURCE_2, projectedCoord.xy).xyz, (attributes.position + rd)) > 0.1)
        rd += rd;
    else
        uvs = projectedCoord.xy;
        break;
}

out_color += (texture(SOURCE_REFL, uvs).rgb);

Is this even possible, using worldSpace coordinates? When I multiply the first pass' outputs with the viewMatrix aswell as the modelMatrix, my light calculations go tits up, because they are also in worldSpace...

Unfortunately there is no basic SSR tutorials on the internet, that explain just the SSR bit and nothing else, so I thought I'd give it a shot here, I really can't seem to get my head around this...

Jack
  • 73
  • 1
  • 5
  • 1
    What is this "SSR" you're talking about? – Nicol Bolas Aug 11 '17 at 14:27
  • Hey, sorry, I meant screen space reflections, I've modified the code a bit to multiply the reflection vector with the distance from the position at the vector's screen space position, which looks ok for the most part but artifacts appear even after setting the reflection color to 0.0 where the reflection vector's screen space position returns less than 0.0 or greater than 1.0 – Jack Aug 11 '17 at 16:39

0 Answers0