SSAO in Unity Free

Hi,
After days of tweaking, testing, writing shaders… i finally got an SSAO effect working in Unity free.
For now, the result is not perfect, there is halo, some artifact at the edge of the screen, but it looks good.
I’m currently using a modified version of IndieEffects, and performances are not good currently (drop from 70 to 25 fps),
so it need some optimizations.
There is some limitations too : max far range is 50 (but i found a trick), there is a little banding, and a bug with skybox (for now).

The method i use is Disk to Disk SSAO, which is an hybrid method between SSAO,HBAO and Disk AO.

Here is some pics :

No SSAO :

With SSAO :

No SSAO :

With SSAO :

AO only :

Tell me if you are interested in it :wink:

I am 500% interested in it. Looks FANTASTIC!
Looking forward to final product here, will buy this :smile:

How’s performance? What’s the advantage over baking it?

The advantage over baking it is it’s in realtime. Performances are as i said, for now, not very good (because it uses ReadPixels).

PS : Someone has an idea on how i can have a 16 bit depth buffer in Unity free ?
Because for now i only have an access to a 8bit*2 depth buffer so only 0-512 range.

Looks good hope to see more.

Encode depth (32 bit float) into an ARGB32 texture before you read it back instead of just writing it to R. Unity has builtin functions for it if you look into UnityCG.cginc. Then decompress it on the CPU and voila 32 bit depth. Not that it’s gonna be fast :wink:

i want it :open_mouth:

Looking great. I really like that large radius AO look, creates very nice gradients over surfaces.

Are you sure i will have a 32 bit depth ? Because i think it’s rather 8bit * 4 channel = 0-255 range * 4 = 0-1024 range = 10 bit.
16 bit have a 0-65535 range.

Well, if you store in linearly like that, yeah. You’re basically converting the float to an integer, which is not want you want to do.
Instead, use these functions to encode and decode the depth. They’re taken straight from UnityCG.cginc, so you can just call EncodeFloatRGBA right away (naturally, presuming you’re including UnityCG). Then just decode that into a float on the CPU using the decode function.

inline float4 EncodeFloatRGBA( float v )
{
	float4 kEncodeMul = float4(1.0, 255.0, 65025.0, 160581375.0);
	float kEncodeBit = 1.0/255.0;
	float4 enc = kEncodeMul * v;
	enc = frac (enc);
	enc -= enc.yzww * kEncodeBit;
	return enc;
}
inline float DecodeFloatRGBA( float4 enc )
{
	float4 kDecodeDot = float4(1.0, 1/255.0, 1/65025.0, 1/160581375.0);
	return dot( enc, kDecodeDot );
}

I’m currently using EncodeDepthNormals , so 1 texture for both depth and normals. So it’s 16 bit for each ?
The problem i have for now is if i increase the far clip range over 50 (like 100 or 200), the ao effect is only visible for far objects but near doesn’t have any ao on it.
Based on what you say, it would not be a problem of depth precision.

However here is a webplayer of what i have yet : https://dl.dropboxusercontent.com/s/w9oaujevoyuwp4e/SSAO_Webplayer.html

Oh right, Unity’s depth/normal texture is an ARGB32. Is there any way in Unity free to get depth into a 32 bit texture? I don’t remember the exact limitations. Is it possible to create a R32 texture and render only depth via replacement shaders? If that’s not possible, then I’m sorry I was wrong and I don’t think it’s possible to achieve greater precision in Unity free :stuck_out_tongue:

New webplayer : Unity Web Player | RobotLab_Unity
Tell me how much FPS you have and you configuration please :slight_smile: .

Change Log :

  • Far clip increased to ~5000
  • Black halo are removed
  • Better looking SSAO
  • Problem with skyboxes solved

There is only 2 things i have to do now, optimize the shader and make it to work for particles, trees and grass.

If you have any comment, suggestion or tip, say it to me :wink:


1644349--102176--$SSAO With.jpg
1644349--102177--$SSAO Without.jpg


60 fps in webplayer. System specs: CPU FX-8350, GPU GTX 780 on Windows 7

would like to get a standalone build if possible, to see performance at full resolution and highest Quallity settings
EDIT: and if you do that please disable v-sync

I’m getting 80 fps.

New topic (release is soon) : http://forum.unity3d.com/threads/248836-SSAO-for-Unity-Free?p=1645888#post1645888

ASUS EP121
Intel i5 (1st Gen Sandy Bridge)
Intel HD Graphics (1st Gen Sandy Bridge)
4 GB RAM
64 MB Dedicated Video
Windows 8.1 64 bit + current patches
Chrome v35

SSAO - 5 FPS
!SSAO - 8 FPS

Excellent work though.

@Goat: I got higher than that on mine, and it’s a core i3! maybe a Win8 prob?

I’m definitely interested for my interior designs on my current project.

Only 1-3 fps decrease.

  • I average 44-47(sometimes jumps to 55 for a few seconds)

running on a A8-6500 apu. with an r7 265 discrete graphics card installed

-Great work!