Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

SSAO #97

Merged
merged 26 commits into from
May 17, 2020
Merged

SSAO #97

merged 26 commits into from
May 17, 2020

Conversation

ffreyer
Copy link
Collaborator

@ffreyer ffreyer commented Apr 28, 2020

Based on the learnopengl tutorial Simon posted in MakieOrg/Makie.jl#487

I believe SSAO is fully working at this point, but it's a very hacky implementation. I thought this would be a good point to get some feedback though, specifically on how connect this to GLMakie correctly.

Rough TODO

  • Pass projection in a less hacky way
  • Make things controllable using Makie attributes. (How would I go about this? They aren't directly available when creating the Framebuffer...) This includes:
    • number of SSAO samples (requires shader recompilation - how?)
    • bias (minimum depth difference for pixel to be occluded)
    • radius (distance checked for occlusion)
    • blur (related to number of pixels used in blur)
    • maybe some controls for randomness of noise and samples
  • on/off switch for SSAO
  • implement deferred shading (i.e. move light calculations to postprocessing) (not doing this results in a weird glowing effect) (nvm, the glow is a result of blurring)
  • fix background getting darkened (when there is no geometry)
  • allow SSAO to run w/o FXAA
  • fix lighting
  • fix glow
  • replace render_colorbuffer

Here are some pics:
cat w/o SSAO:
noSSAO

cat w/ SSAO
withSSAO

cat w/ only SSAO
occlusion

gl_Position = projection * view * position_world;
gl_Position = projection * o_view_pos;
// TODO calculate w/ normalmatrix (see o_normal links)
o_view_normal = transpose(inverse(mat3(view))) * normal;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we shouldn't calculate this in the shader ;)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some code to generate a normalmatrix in cached_robj!()

@SimonDanisch
Copy link
Member

Awesome :) On first sight, this looks pretty similar to how I'd have done it ;)

@ffreyer
Copy link
Collaborator Author

ffreyer commented Apr 30, 2020

I think I got SSAO working correctly for multiple scenes now. Took me quite a while to figure out why it wasn't working. I wrote a longer comment in the shader that explains what I'm doing and why I'm doing it.

Current cat(s):

Screenshot from 2020-04-30 04-12-22

src/rendering.jl Outdated
Comment on lines 110 to 112
# clear shouldn't be necessary. every pixel should be written to
glClearColor(1, 0, 1, 1)
glClear(GL_COLOR_BUFFER_BIT)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this clear color a jarring pink so I can see if it ever appears. Should be removed or set to white before merging. There's another one of these further down (using green)

Copy link
Collaborator Author

@ffreyer ffreyer May 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pink becomes visible if bias < 0.

Comment on lines +245 to +248
// position in view space (as seen from camera)
o_view_pos = view * position_world;
// position in clip space (w/ depth)
gl_Position = projection * o_view_pos;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these require a v /= v.w?

@ffreyer ffreyer requested a review from SimonDanisch May 2, 2020 20:10
Comment on lines 236 to 244
o_normal = normalmatrix * normal;
// position in view space (as seen from camera)
o_view_pos = view * position_world;
// direction to light
o_lightdir = normalize(lightposition - position_world.xyz);
o_lightdir = normalize(view*vec4(lightposition, 1.0) - o_view_pos).xyz;
// direction to camera
o_camdir = normalize(eyeposition - position_world.xyz);
// screen space coordinates of the vertex
gl_Position = projection * view * position_world;
o_camdir = normalize(view*vec4(eyeposition, 1.0) - o_view_pos).xyz;
// position in clip space (w/ depth)
gl_Position = projection * o_view_pos;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, we could also do

o_normal = normal_model_matrix * normal;
o_view_normal = normal_view_matrix * normal; // pass this to SSAO
o_lightdir = normalize(lightposition - position_world.xyz);
o_camdir = normalize(eyeposition - position_world.xyz);
o_view_pos = view * position_world; // pass this to SSAO
gl_Position = projection * o_view_pos;

where the normal matrices are transpose(inv(view) and tranpose(inv(model)). Not sure which is better...

@ffreyer
Copy link
Collaborator Author

ffreyer commented May 8, 2020

using Colors, Makie
s1, radius = textslider(0.0f0:0.1f0:2f0, "Radius", start = 0.5f0)
s2, bias = textslider(0f0:0.005f0:0.1f0, "Bias", start = 0.025f0)
s3, blur = textslider(Int32(0):Int32(1):Int32(5), "Blur", start = Int32(2))
ssao_attrib = Attributes(radius=radius, bias=bias, blur=blur)

ps = rand(Point3f0, 100)
colors = rand(RGB, 100)
scene1 = meshscatter(ps, color=colors, ssao=true, SSAO=ssao_attrib)
scene2 = meshscatter(ps, color=colors, ssao=false) # default
hbox(vbox(s1, s2, s3), vbox(scene1, scene2))

Here's a little example for playing around with attributes. The left side uses SSAO, the right side doesn't. Depending on the colors the shine/glow issue is quite noticeable here, and by modifying blur (which sets the pixel-range for blurring) you can see that it is connected to that.

@SimonDanisch SimonDanisch merged commit c2c0510 into JuliaPlots:master May 17, 2020
kragol pushed a commit to kragol/GLMakie.jl that referenced this pull request Sep 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants