(SSR) Screen-Space Reflections Shader v0.7

Shaders are faster, when they are cached. that means, that you gonna have to add the shader to the sourcecode or (c++ and glsl part.)

Hello! i used a bunch of code from this project and made some screen space raytraced global illumination in the bge.


Also: glossy reflection using a Cook-Torrance BRDF


No importance sampling just yet but i’ll get to work on it when i get the time. (i will probably switch over to the Blinn BRDF, which already has simple expressions for importance sampling).

1 Like

I’ve been having some fun learning to derive all of the formulas used in importance sampling. And even though this particular filter is becoming useless soon, i think it was worth it; it was hell of a lot of fun.

By the way, you have to add three properties to the object to which you add this filter: a float called “roughness” (use the range -1 to 1), a float called “reflectance” (use the range 0 to 1) and an integer called “rays” (1 or higher should be fine).

Anyways. New shiny update. I hope someone manages to get some use out of this.

it doesn’t work for me somehow. It just darkens the object edges

I tried tweaking your code, but your code doesn’t seem to be the problem.
Any suggestions?

if you upload a blend file with the issue i can take a look at it and tell you what’s wrong

Yey i just remade this thing from scratch. it’s slow af. but it looks pretty. so yeah.

1 Like

ouh boy can’t wait for half-life 2 remake on this engine. I think water shader is also made for bge, so only thing left is to add half-life assets models, animations and PHYSICS of ragdoll at least.

Hλlf-Life 2
I own copy of Half-Life on steam and have big collection of BGE shaders and projects of other sort of creations

Unrealistically thinking I bet I could put indoor prison scene without flying alien bugs in 7 hours

Thanks for the reply! I wasn’t active on this forum for some time.
The problem was my slightly non-standard blender 2.78 install.
It’s fine in 2.79.

Wow this is amazing! I works just fine :slight_smile:

Here is a small test I did with a sample level that I’m working right now with the UPBGE

2 Likes

Thank you for sharing this amazing shader. I am currently implementing this in my own C++ framework and have run into a little issue that I’d like to get your opinion on.

The code calculates a view space normal by sampling the depth buffer, calculating the view space position and then finding the normal by means of a process similar to forward differencing. However, due to the relatively low resolution of my meshes, the normals look like this (left side):

reflected_normals

It also doesn’t work well with normal mapping, which I’d love to take into account. Therefor, I decided to render the normals to a second target that I can simply sample in the reflection shader. The normals then look like the right side of the image.

Much smoother, as you can see. However, the normals are not the same, which is easy to see because the colors differ. It seems like the calculated normals have a zero (or very small) Z-component. The reflection shader does not work with the normals sampled from my buffer.

Could you explain what getViewNormal() does exactly? Would it be possible to somehow make this work with the proper normals?

-Paul

I found out what it was: the normals calculated by getViewNormal() have their Z-component flipped.

I can replace that function with the following to obtain smooth normals:

vec3 getViewNormal( in vec2 coord )
{
  vec3 normal = normalize( texture( uNormalTexture, coord ).xyz * 2.0 - 1.0 );
  return normal * vec3( 1, 1, -1 );
}

-Paul

I see you managed to figure it out quite quickly. Nice one! I look forward to seeing some examples of this working on your framework

I’m sure you’ll eventually replace all of my sloppy my code (if you are using any of it to begin with, that is), sorry about that.

Ohh wow, reflections look waaay better when there are some flashy FX to reflect on the scene. Nicely done!!

Also, that game looks nice, are you posting your progress somewhere?

is this any good on low end computers?

If by low-end computers you mean modern very-low-end computers (like R3 2200G combined with 2x4 GB of DDR4-2667 memory), then it’s good and should work fine (especially if you can make it run at half-resolution trace), with slight framerate reduction, but still keeping the game somewhat playable if the rest of the shading and post processing is relatively light weight. If by low-end you mean old potato, then no, this will probably bring your FPS down from your typical 30 to something more like 10. In nowadays software is made for now hardware and the old hardware just won’t handle it.

i mean a hewlletpackard from a couple years ago.

-quality
-performance
-cost

Choose 2.

Joking aside: I don’t think an integrated Intel GPU will be able to run this shader smoothly at high quality settings. However, you can tweak parameters such as the number of samples, the step size, the start scale and the number of roughness samples.

As promised, here’s the result of this shader running in my C++ framework. For the screenshot, I ran at ridiculously high settings (samples: 256, step size: 0.01, start scale: 1, roughness samples: 256).

At interactive rates, the result is much more noisy. When settings number of roughness samples to 1 and disabling the rand() function, I can see a clear stepping pattern in the raymarch. Could the raymarch algorithm be improved to reduce this? What would you try first?

-Paul

You could try 3x3 kernel blur to smooth out roughness (and make it’s exponent depend on roughness where no roughness = no blur and full roughness = full blur).

Thanks for the suggestion. I think applying SMAA to the end result would also help a bit.

But the stepping I was mentioning is another matter. It’s not noticeable for relatively rough surfaces, but much more so for smooth ones. I was wondering how the raymarch algorithm can be rewritten to reduce this.

Here’s a screenshot with number of roughness samples set to 1 and the rand() function disabled (returns 0):

-Paul