BGE HBAO Ambient Occlusion Shader

what kinds of errors?
errors of the type: your console prints things and the AO don’t renders at all?

or the AO effect just looks weird?

i get this one: upbge 2.5

GPUShader: compile error:
Fragment shader failed to compile with the following errors:
ERROR: 0:137: error(#143) Undeclared identifier: lt
ERROR: 0:137: error(#162) Wrong operand types: no operation "&" exists that takes a left-hand operand of type "float" and a right operand of type "float" (or there is no acceptable conversion)
ERROR: 0:137: error(#132) Syntax error: ";" parse error
ERROR: error(#273) 3 compilation errors.  No code generated
1 Like

Hi, same problem as Cotaks have.

edit. i actually have another problem. Few years ago i was experimenting with bge and wrote little script. Now ive opened file in upbge and overwrite it. In upbge it works fine but in 2.79 there is no keyboard/mouse inputs working.

Replace &lt by < and &gt by >
It was an issue of blenderartists.org

I upload them here again:
HBAO2.79b.blend (1.2 MB) hbao.blend (558.6 KB)

3 Likes

Thanks,

2.79 works in 0.2.5

hbao.blend gives a spreaded result
hbao

Now i need to figure out what looks best, the ssao that i have for like 5+ years or hbao.

upbge blends are not compatible with 2.79, if you want it to work, append all files from the upbge blend into bge blend.

1 Like

you have to adjust the user variables to suit your scene. The below gives me nice results at 60 fps:

//USER VARIABLES-----------------------------------------------
const float intensity = 1.2;            //Intensity of the AO effect
const float sampleRadius = 1.0;         //Radius of the AO, bigger values need more performance

const float sampleDirections = 8.0;    //Main sample count, affects performance heavily 
const float sampleSteps = 4.0;         //SubSample count, sometimes higher values are faster

const bool useAttenuation = true;      //Applies attenuation to each AO sample, different values look better depending on your scene
const float attenuationScale = 1.0;     //Depth scale of the attenuation, different values look better depending on your scene

const float angleBias = 0.3;            //Brightens up the AO effect to reduce noise and artifacts

const bool noise = false;               //Use noise instead of pattern for sample dithering, much slower but more accurate
const float noiseamount = 0.5;          //Per-Pixel noise amount, bigger values need more performance
const float jitterAmount = 0.5;         //Per-Sample noise amount, bigger values need more performance

const float lumInfluence = 0.3;         //Influence of the luminance on the AO effect

const bool onlyAO = false;               //Only show AO pass for debugging
const bool externalBlur = false;         //Store AO in alpha pass for a later blur
//-------------------------------------------------------------

AO_performance

1 Like

And here it is with high sampling: expand the image


const float sampleDirections = 16.0;

@riceart
You should have kept the original and saved a copy to port your projects to Upbge cuz there is no backward compatibility to Bge, as @Cotaks said. You can go from one to the other, but no back (without the hard work).

3 Likes

That effect just sucks xD that’s not hbao.
Also this hbao shader is not optimized for amd. Or it must be the driver again.

i rather stick with the ssao filter i have.
i’ve toned it down to be there and you will notice it ingame, here is a .gif, no noise at all, nothing is covered with boxes.

(zoom in/click to see the effect better)
SSAO

as you can see it make things pop, or rather it creates depth, i don’t see that in this hbao filter, and the noise/checker board effect is silly.

i also said how to go back :wink: so yes there is a way to get back. Scripts needs their code adjusted to bge (mouselook for example, or key inputs), but you can convert it back.

1 Like

i am using Nvidia, with updated drivers.(i think)
If I understood, you don’t have any noise/checker board effect by default? or the effect is forgivable to you? or the shader looks ugly to you anyway?

sorry i was about to edit the portability part.

I do have the checker board effect.

The shader has flaws, meaning it’s ugly. even in the opening post you can see the spreaded result.
It’s a great effect if you can live with the checker board effect, and the rather strange smudging of the hbao effect (looking at your or OP screenshot). But i rather stick with the SSAO i have, give way better results (my opinion)

exactly. That is the point i was making when i brought back the topic 2 year later, 12 hours ago:
if only we could mipmap the filter with low-bias it would be great.
with 2 to 4 samples we could run it in real time and not just a static scene that looks good (the tech demo by ThePajlok UPBGE Photorealistic Tech-demo Topic).

I exaggerated the effect in the screenshot.
it can be further increased to make it like ’ ‘‘dirty edges’’ ’ Nick_Manchul was talking about.
i also use a old ssao by martish, but looks cartoony at low sample. Its fine for some game style.

the author(and others agreed) said it is ‘very beautiful and up-to-date’ technique and this page says its faster and more physically correct: HBAO+ tech

so…

Ok, thanks for the tip. I will stick to upbge for now.

Wow, didn’t think people would still care about this (or BGE in general).

I have made some updates to this shader over the time - will prepare the new version for a release later today (maybe in a few hours).

Will also try to answer some of your questions in the following.

1 Like

If you enable the “externalBlur” option, the AO result will be written to the alpha channel of the rendered frame. You could then add another shader which loads the alpha channel and applies blur / mipmapping.

UPDATE - UPBGE only

Ok as promised, here is the update.

IMPORTANT:
To increase performance and quality on smooth curves, the shader uses the UPBGE render attachments to read the normals from.

Setup guide:

  1. Add an Attachment under “Render”-tab > “Attachments” (UPBGE v0.2.5+) and set up like this:
    setup_1

  2. For EACH MATERIAL in your scene, use material nodes and output the attachment like this:


    (you can also replace the normals from the Geometry node with the normals from a “Material” or “Normal Map” node to include textured normals)

  3. Add the HBAO shader
    hbao.glsl (8.2 KB)

  4. Configure shader variables under “THIS NEEDS TO MATCH YOUR CAMERA SETTINGS” and “USER VARIABLES”

  5. Enjoy

Results:

AO Only:

Shaded scene:

Changelog:

  • Implemented dedicated normal pass through UPBGE Attachments
  • Improved noise influence to break up the before clearly visible sampling ray directions
  • The geometry distance now influences the AO radius, so the AO effect doesn’t “scale up” when you move away / “scale down” when you move closer
  • Fixed bug where the “sampleSteps” variable wasn’t used correctly
  • Slight performance increase

Todo:

  • Fix on AMD (I only have an Nvidia card)

Note:

Because this came up many times:

The HBAO algorithm is VERY performance hungry, this is something I cannot change. So don’t expect your inbuild/old graphics card to run this!

Even current AAA games only use HBAO if you are on HIGH settings!

Anyways, hope this update will help you.

8 Likes

Thanks man, we need glsl wizards like you around here!!! :sparkling_heart: :innocent: :star_struck:

GOT IT!!!

aoBlur.glsl


uniform sampler2D bgl_RenderedTexture;

void main()
{
float ao = texture2D(bgl_RenderedTexture,gl_TexCoord[0].st, 1.0).a;
vec3 col = texture2D(bgl_RenderedTexture,gl_TexCoord[0].st).rgb;
gl_FragColor.rgb = vec3(col*ao);
}
2 Likes

Wait, I uploaded a debug version of the shader. Updating post…

1 Like

Here is an improved blur shader:

ao_blur.glsl (3.8 KB)

It supports 4 blur algorithms: Gaussian, Linear, Darkest Pixel and Mipmap only. Blur size is also adjustable.

But be careful with larger blur sizes, they’ll lead to color bleeding on edges.

4 Likes

Large scale demo:

AO Only (small AO size):

AO Only (large AO size):

Full colored frame:

Without AO:

All screenshots are real-time on a Ryzen 3 + GTX 1660, the low frame rate in the screenshots is caused by the complex geometry and huge textures, otherwise it runs perfectly at 60 FPS.

This “demo” was originally a test for further improvements to the shader, update will be released soon.

13 Likes