Jump to content
  • Advertisement

Recommended Posts

Posted (edited)

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

Edited by _WeirdCat_

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites

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....

 

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!