New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Order independent transparency #1418
Conversation
mutable struct GLFramebuffer | ||
resolution::Observable{NTuple{2, Int}} | ||
id::NTuple{2, GLuint} | ||
id::GLuint | ||
|
||
buffer_ids::Dict{Symbol, GLuint} | ||
buffers::Dict{Symbol, Texture} | ||
render_buffer_ids::Vector{GLuint} | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before I end up forgetting this - I removed the second framebuffer because it doesn't seem necessary to me. Because of that there is only one id here. FXAA now uses a second texture/color buffer on the primary framebuffer instead.
GLMakie/src/glwindow.jl
Outdated
function attach_framebuffer!(fb::GLFramebuffer, t::Texture{T, 2}) where T | ||
max_color_id = GL_COLOR_ATTACHMENT0 | ||
for id in values(fb.buffer_ids) | ||
if GL_COLOR_ATTACHMENT0 <= id <= GL_COLOR_ATTACHMENT15 && id > max_color_id | ||
max_color_id = id | ||
end | ||
end | ||
next_color_id = max_color_id + 0x1 | ||
if next_color_id > GL_COLOR_ATTACHMENT15 | ||
error("Ran out of color buffers.") | ||
end | ||
|
||
color_buffer = Texture(RGBA{N0f8}, fb_size, minfilter = :nearest, x_repeat = :clamp_to_edge) | ||
objectid_buffer = Texture(Vec{2, GLuint}, fb_size, minfilter = :nearest, x_repeat = :clamp_to_edge) | ||
glFramebufferTexture2D(GL_FRAMEBUFFER, next_color_id, GL_TEXTURE_2D, t.id, 0) | ||
return next_color_id | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also added a new function to attach color buffers. It looks through the already attached ids and figures out the next one automatically.
One problem with OIT is that colors can get overexposed in the transparency pass because its color buffer isn't fixed to a (0, 1) range. The current output for overlapping panes (lit front, unlit back) looks like this: We could explicitly Or a more extreme All the images use panes with colors |
Looks like |
Yeah the axis moved out of scene into lscene, so you need to directly pass show_axis to the lscene |
Also is the upload of the test images gone or am I just blind? |
i.e. scatter, text, etc
this is looking great! |
The current implementation is reading from and writing to the same color buffer. Is this something I should avoid? I switched to doing it with blend functions. |
This breaks Fixed it |
I added a documentation page on transparency. Do I need to include it in some list somewhere or is it automatically included? |
Awesome! :) |
Using commit #dceac53
with
See #1390
I'll try to summarize my changes a bit:
For OIT I added a
RGBA{Float16}
color buffer and aN0f8
buffer. The former holds the sum of transparent colors and weights. The latter holds the product of all(1-alpha_i)
. They are written to infragment_output.frag
via mustache replacements, sotransparency
is a static per plot just likeshading
. The summation and the product of colors, weights and alpha values work via blending functions. Alltransparency = true
plots are rendered and then merged into the main color buffer (via OIT postprocessor) at the same stage, after SSAO and before FXAA.I also made some general adjustments:
I reduced the position buffer for SSAO to Float16I went back on this because the positions are not normalized. I'm worried using Float16 might break SSAO in a large coordinate space. I'm not sure if it works in the first place though.GL_COLOR_ATTACHMENT
s to be successive numbers.enabletransparency()
to keep the output alpha at 1 for the opaque color buffer. I also adjusted the OIT blending shader to ignore other values. One of those two seems to be necessary.After merging this pr, rendering will require
4*8 color + 2*32 objectid + 24+8 depth & stencil + 4*16 transparent color & weight + 8 alpha = 200 Byte per pixel
without SSAO active (8 more than before with FXAA active, 72 more with FXAA off)200 + 3*32 position = 296 Bytes per pixel
with FXAA+SSAO active (152 less than before)