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

Change stencil to scissor test in SSAO #175

Merged
merged 1 commit into from
Apr 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/postprocessing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,29 +122,39 @@ function ssao_postprocessor(framebuffer)
glViewport(0, 0, w, h)
# glClearColor(1, 1, 1, 1) # 1 means no darkening
# glClear(GL_COLOR_BUFFER_BIT)
glDisable(GL_STENCIL_TEST)
glEnable(GL_SCISSOR_TEST)

for (screenid, scene) in screen.screens
# Select the area of one leaf scene
# This should be per scene because projection may vary between
# scenes. It should be a leaf scene to avoid repeatedly shading
# the same region (though this is not guaranteed...)
isempty(scene.children) || continue
a = pixelarea(scene)[]
glScissor(minimum(a)..., widths(a)...)
# update uniforms
SSAO = scene.SSAO
data1[:projection][] = scene.camera.projection[]
data1[:bias][] = Float32(to_value(get(SSAO, :bias, 0.025)))
data1[:radius][] = Float32(to_value(get(SSAO, :radius, 0.5)))
# use stencil to select one scene
glStencilFunc(GL_EQUAL, screenid, 0xff)
GLAbstraction.render(pass1)
end


# SSAO - blur occlusion and apply to color
glDrawBuffer(GL_COLOR_ATTACHMENT0) # color buffer
for (screenid, scene) in screen.screens
# Select the area of one leaf scene
isempty(scene.children) || continue
a = pixelarea(scene)[]
glScissor(minimum(a)..., widths(a)...)
# update uniforms
SSAO = scene.attributes.SSAO
data2[:blur_range][] = Int32(to_value(get(SSAO, :blur, 2)))
# use stencil to select one scene
glStencilFunc(GL_EQUAL, screenid, 0xff)
GLAbstraction.render(pass2)
end
glDisable(GL_STENCIL_TEST)
glDisable(GL_SCISSOR_TEST)
end

PostProcessor([pass1, pass2], full_render)
Expand Down