Advertisement

Need help with ssao

Started by August 04, 2018 04:19 PM
4 comments, last by _WeirdCat_ 6 years, 6 months ago

I try to implement ssao, i've read few tutorials and they use view space calculations - like you need a texture with viewspace positions of each fragment blablabla, but what are the numbers that define viewspace are they in range of 0..1?

How do i multiply a vertex by view matrix do i use matrix row 4th component too to calculate it?

Additionally i would like to ask what was the difference in vertex 4th component? I recall that 1.0? were for positions and 0.0 were for vectors right?

So if i want to calc viewspace normal i dont then use 4th matrix row component at all?

So i decided to reinvent a wheel (......)

Forget about view space, perspective divisions and kerenels random vectors - just sample all pixels around each pixel and compare their depths to find occlusion value...

And i came with that ugly result,(see attachement

maybe i could improove it. And if not i would like to not use viewspace thing cause i have no imagination on that kind of thing and rather use worldspace but still maybe theres a way of doing ssao without involving rotation of kernel samples, i would like to avoid filling tangent information to gpu buffer and calculating rotation matrix for world space solution of this kind of thing.

sketch-1533398356512.png

Oh I remember the SSAO days. Those were fun (but tough) times.

You may not like this, but you will definitely want to implement SSAO with the usage of view space. If you are curious about the mathematics then you should definitely focus on that. You can also experiment with it and output the Z values as a color value to get an idea of the actual view space values if you want.

Sampling depth values around the pixel without view space wouldn't work because for one thing you need to be in view space to get the correct depth values as Z values. Another issue is if you don't take random samples with randomly rotated vectors, the results will look too solid and you will need to apply more blurring, which will be more expensive in the long run.

In short, study and experiment with the mathematics until you get a feel for it, then look for a good tutorial on SSAO. Read the shader code they provide, if there is any, and try to understand it piece by piece.

View my game dev blog here!

Advertisement

Sampling depth values around the pixel without view space wouldn't work because for one thing you need to be in view space to get the correct depth values as Z values

 

 

And here why i tried my way of doing this i thought that im sampling anyway depth values around a fragment so why not just sample fragments around, i think i get your point of view - fornflat surfaces i get alwaysnocclusion thing when while using normals none of samples would intersect the same surface leaving it full bright...

Well back to coding then....

 

Ok so now i see only an outline a a bunch of white circles if im close enough to geometry.

What i do

Draw depth to texture

Draw normals to texture

Draw vectors perpendicular to normals to texture

Now in ssao shader

Reconstruct actual depth and world position - fragmentwpos

Construct a rotation matrix out of normal, perpendicular vector and normal x perpend_vec

Go through all samples

{

Rotate sample by matrix

New sample pos=fragmentwpos+rotated_kern_sample*ssao_radius;

Muktiply that pos above by mvp matrix and get 0..1 coordinates from that so i can sample depth map and get its value

}

And that should contribute to overall fragment occlusion factor - if somethings wrong in way im doing it please tell me (all normals, positions, tangents are in worldspace)

And actually i came up with outline shader rather than ssao im quite satisfied with results anyway, user can clearly see depth, however not in all cases cause whenever 2 diff surfaces have the same normal algorrithm cracks and doesnt profuce an outline and whenever two geometric shapes stick together i get darkened bonded areas but well it aint that bad, so what i do now is the algo from first post but now i use a normalmap to see if im testing against samensurface (well same normalbtruth to be told) i could use some sort of instancing (not instancing in the meaning if it) but i could draw different colors for each surface and check whenever it doesnt match so i can improove that outline ssao wannabe thing and few scrs ?

 

Screenshot_20180805-205802.png

Screenshot_20180805-210822.png

Screenshot_20180805-220315.png

Screenshot_20180805-220359.png

Screenshot_20180805-220505.png

Screenshot_20180805-220602.png

Screenshot_20180805-220617.png

Screenshot_20180805-220625.png

This topic is closed to new replies.

Advertisement