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
Merged
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
ce9d10b
skip second framebuffer & dynamic attachment ids
ffreyer af9a584
draft OIT implementation
ffreyer 14185d8
combine shaders
ffreyer 4670567
rename and simply colorbuffer attachment
ffreyer 27e005c
reduce SSAO buffer size and reuse HDR_color
ffreyer 4a837b0
add some convenience
ffreyer 1b2ccb8
fix typos
ffreyer 497d3b1
fix error for nonstandard prerenderers
ffreyer 12f0005
cleanup
ffreyer e6eaa93
fix transparency with transparency = false
ffreyer dceac53
remove alpha from weight sum
ffreyer e44ead8
switch back to Float32 for position buffer
ffreyer 47f7ba7
reuse HDR color buffer for FXAA
ffreyer 18bac48
add note on buffer reuse
ffreyer c242b0a
Merge branch 'master' into ff/OIT
ffreyer 05527a7
cleanup some comments
ffreyer 787ce50
fix discoloration
ffreyer dcb96fa
remove warning
ffreyer 3f6968c
use that opaque alpha = 0
ffreyer 091b9ea
add OIT test
ffreyer cf2d511
add transparency
ffreyer 7db7666
avoid reading and writing to the same colorbuffer
ffreyer 1e67a48
reduce position buffer size
ffreyer a74212e
Merge branch 'master' into ff/OIT
ffreyer 307f76d
fix 3d contour
ffreyer d81ef29
Merge branch 'master' into ff/OIT
SimonDanisch 237264c
Update runtests.jl
SimonDanisch 4fe8752
Update runtests.jl
SimonDanisch 9aea42e
add docs for transparency and OIT
ffreyer File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{{GLSL_VERSION}} | ||
|
||
// See https://github.com/JuliaPlots/Makie.jl/issues/1390 | ||
|
||
in vec2 frag_uv; | ||
// contains opaque color from previous main render steps | ||
uniform sampler2D opaque_color; | ||
// contains sum_i C_i * weight(depth_i, alpha_i) | ||
uniform sampler2D sum_color; | ||
// contains pod_i (1 - alpha_i) | ||
uniform sampler2D prod_alpha; | ||
|
||
out vec4 fragment_color; | ||
|
||
void main(void) | ||
{ | ||
vec4 color = texture(opaque_color, frag_uv); | ||
vec4 summed_color_weight = texture(sum_color, frag_uv); | ||
float transmittance = texture(prod_alpha, frag_uv).r; | ||
|
||
vec3 weighted_transparent = summed_color_weight.rgb / max(summed_color_weight.a, 0.00001); | ||
vec3 full_weighted_transparent = weighted_transparent * (1 - transmittance); | ||
vec3 weighted_opaque = (color.rgb * color.a) * transmittance; | ||
|
||
fragment_color.rgb = full_weighted_transparent + weighted_opaque; | ||
fragment_color.a = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{{GLSL_VERSION}} | ||
|
||
layout(location=0) out vec4 fragment_color; // RGBAF16 | ||
layout(location=1) out uvec2 fragment_groupid; // keep this? | ||
layout(location=2) out float coverage; // F16 or N0f8 | ||
|
||
|
||
in vec4 o_view_pos; | ||
in vec3 o_normal; | ||
|
||
|
||
void write2framebuffer(vec4 color, uvec2 id){ | ||
if(color.a <= 0.0) | ||
discard; | ||
|
||
// frag_Depth is in (-1, 1) right? | ||
// summation/product via blend functions | ||
float weight = color.a * max(0.01, 3000 * pow((1 - gl_FragCoord.z), 3)); | ||
fragment_color = weight * color; | ||
coverage = color.a; | ||
fragment_groupid = id; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,9 @@ end | |
|
||
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 | ||
|
@@ -25,50 +26,88 @@ function attach_framebuffer(t::Texture{T, 2}, attachment) where T | |
glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, GL_TEXTURE_2D, t.id, 0) | ||
end | ||
|
||
function GLFramebuffer(fb_size::NTuple{2, Int}) | ||
# First Framebuffer | ||
render_framebuffer = glGenFramebuffers() | ||
glBindFramebuffer(GL_FRAMEBUFFER, render_framebuffer) | ||
# attach texture as color attachment with automatic id picking | ||
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 commentThe 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. |
||
|
||
function GLFramebuffer(fb_size::NTuple{2, Int}) | ||
# Create framebuffer | ||
frambuffer_id = glGenFramebuffers() | ||
glBindFramebuffer(GL_FRAMEBUFFER, frambuffer_id) | ||
|
||
# Buffers we always need | ||
# Holds the image that eventually gets displayed | ||
color_buffer = Texture( | ||
RGBA{N0f8}, fb_size, minfilter = :nearest, x_repeat = :clamp_to_edge | ||
) | ||
# Holds a (plot id, element id) for point picking | ||
objectid_buffer = Texture( | ||
Vec{2, GLuint}, fb_size, minfilter = :nearest, x_repeat = :clamp_to_edge | ||
) | ||
# holds depth and stencil values | ||
depth_buffer = Texture( | ||
Ptr{GLAbstraction.DepthStencil_24_8}(C_NULL), fb_size, | ||
minfilter = :nearest, x_repeat = :clamp_to_edge, | ||
internalformat = GL_DEPTH24_STENCIL8, | ||
format = GL_DEPTH_STENCIL | ||
) | ||
# Order Independent Transparency | ||
HDR_color_buffer = Texture( | ||
RGBA{Float16}, fb_size, minfilter = :nearest, x_repeat = :clamp_to_edge | ||
) | ||
OIT_weight_buffer = Texture( | ||
N0f8, fb_size, minfilter = :nearest, x_repeat = :clamp_to_edge | ||
) | ||
# opaque is color, depth is depth, tonemapped_luma is luma? | ||
|
||
attach_framebuffer(color_buffer, GL_COLOR_ATTACHMENT0) | ||
attach_framebuffer(objectid_buffer, GL_COLOR_ATTACHMENT1) | ||
attach_framebuffer(HDR_color_buffer, GL_COLOR_ATTACHMENT2) | ||
attach_framebuffer(OIT_weight_buffer, GL_COLOR_ATTACHMENT3) | ||
attach_framebuffer(depth_buffer, GL_DEPTH_ATTACHMENT) | ||
attach_framebuffer(depth_buffer, GL_STENCIL_ATTACHMENT) | ||
|
||
status = glCheckFramebufferStatus(GL_FRAMEBUFFER) | ||
@assert status == GL_FRAMEBUFFER_COMPLETE | ||
|
||
|
||
# Second Framebuffer | ||
# postprocessor adds buffers here | ||
color_luma_framebuffer = glGenFramebuffers() | ||
glBindFramebuffer(GL_FRAMEBUFFER, color_luma_framebuffer) | ||
|
||
@assert status == GL_FRAMEBUFFER_COMPLETE | ||
|
||
glBindFramebuffer(GL_FRAMEBUFFER, 0) | ||
fb_size_node = Observable(fb_size) | ||
|
||
# To allow adding postprocessors in various combinations we need to keep | ||
# track of the buffer ids that are already in use. We may also want to reuse | ||
# buffers so we give them names for easy fetching. | ||
buffer_ids = Dict( | ||
:color => GL_COLOR_ATTACHMENT0, | ||
:objectid => GL_COLOR_ATTACHMENT1, | ||
:HDR_color => GL_COLOR_ATTACHMENT2, | ||
:OIT_weight => GL_COLOR_ATTACHMENT3, | ||
:depth => GL_DEPTH_ATTACHMENT, | ||
:stencil => GL_STENCIL_ATTACHMENT, | ||
) | ||
buffers = Dict( | ||
:color => color_buffer, | ||
:color => color_buffer, | ||
:objectid => objectid_buffer, | ||
:depth => depth_buffer | ||
:HDR_color => HDR_color_buffer, | ||
:OIT_weight => OIT_weight_buffer, | ||
:depth => depth_buffer, | ||
:stencil => depth_buffer | ||
) | ||
|
||
return GLFramebuffer( | ||
fb_size_node, | ||
(render_framebuffer, color_luma_framebuffer), | ||
buffers, | ||
fb_size_node, frambuffer_id, | ||
buffer_ids, buffers, | ||
[GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1] | ||
) | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.