From 9b5337e101b6b1e28b049cadc3b17cb9caed02ee Mon Sep 17 00:00:00 2001 From: ffreyer Date: Fri, 10 Dec 2021 13:29:22 +0100 Subject: [PATCH 1/4] make weight scaling factor adjustable --- GLMakie/src/GLVisualize/visualize_interface.jl | 5 +++-- GLMakie/src/gl_backend.jl | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/GLMakie/src/GLVisualize/visualize_interface.jl b/GLMakie/src/GLVisualize/visualize_interface.jl index 5cabe63be1a..e50cf682808 100644 --- a/GLMakie/src/GLVisualize/visualize_interface.jl +++ b/GLMakie/src/GLVisualize/visualize_interface.jl @@ -167,7 +167,7 @@ function visualize(@nospecialize(main), @nospecialize(s), @nospecialize(data)) end # Make changes to fragment_output to match what's needed for postprocessing -using ..GLMakie: enable_SSAO +using ..GLMakie: enable_SSAO, transparency_weight_scale function output_buffers(transparency = false) if transparency @@ -186,8 +186,9 @@ end function output_buffer_writes(transparency = false) if transparency + scale = transparency_weight_scale[] """ - float weight = color.a * max(0.01, 3000 * pow((1 - gl_FragCoord.z), 3)); + float weight = color.a * max(0.01, $scale * pow((1 - gl_FragCoord.z), 3)); coverage = color.a; fragment_color.rgb = weight * color.rgb; fragment_color.a = weight; diff --git a/GLMakie/src/gl_backend.jl b/GLMakie/src/gl_backend.jl index 285052992aa..58d3b0e0e50 100644 --- a/GLMakie/src/gl_backend.jl +++ b/GLMakie/src/gl_backend.jl @@ -55,8 +55,14 @@ function get_texture!(atlas) end # TODO +# find a better way to handle this +# enable_SSAO and FXAA adjust the rendering pipeline and are currently per screen const enable_SSAO = Ref(false) const enable_FXAA = Ref(true) +# This adjusts a factor in the rendering shaders for order independent +# transparency. This should be the same for all of them (within one rendering +# pipeline) otherwise depth "order" will be broken. +const transparency_weight_scale = Ref(1000f0) include("GLVisualize/GLVisualize.jl") using .GLVisualize From 96169dc222bca072dd97ccedf8eaa18b43b73927 Mon Sep 17 00:00:00 2001 From: ffreyer Date: Fri, 10 Dec 2021 13:49:16 +0100 Subject: [PATCH 2/4] adjust near plane --- src/makielayout/layoutables/axis3d.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/makielayout/layoutables/axis3d.jl b/src/makielayout/layoutables/axis3d.jl index d2a69758e80..c3c27ee5e6e 100644 --- a/src/makielayout/layoutables/axis3d.jl +++ b/src/makielayout/layoutables/axis3d.jl @@ -220,7 +220,7 @@ function calculate_matrices(limits, px_area, elev, azim, perspectiveness, aspect end function projectionmatrix(viewmatrix, limits, eyepos, radius, azim, elev, angle, width, height, scales, viewmode) - near = radius - sqrt(3) + near = 1f-2 far = radius + 2 * sqrt(3) aspect_ratio = width / height From 816c08198ed14355bf62ac1a0daafd8dd9fd479c Mon Sep 17 00:00:00 2001 From: ffreyer Date: Fri, 10 Dec 2021 14:07:20 +0100 Subject: [PATCH 3/4] add notes on #1505 --- docs/documentation/transparency.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/documentation/transparency.md b/docs/documentation/transparency.md index 0457a047eab..08a5312990d 100644 --- a/docs/documentation/transparency.md +++ b/docs/documentation/transparency.md @@ -139,4 +139,11 @@ fig ``` \end{examplefigure} -Note that you can mix opaque `transparency = false` plots with transparent OIT plots without problems. So the first issue is not really an issue for truly opaque plots but rather close to opaque plots. \ No newline at end of file +Note that you can mix opaque `transparency = false` plots with transparent OIT plots without problems. So the first issue is not really an issue for truly opaque plots but rather close to opaque plots. + +Another problem you may run into is that part of your plot becomes black or white. This is a result of floats becoming infinite during the OIT calculation because of a large number of transparent colors being added close to the camera. You can fix this in two way: + +1. Move the `near` clipping plane closer to the camera. For an `ax::LScene` this can be done by adjusting `ax.scene.camera_controls.near[]` closer to 0 and calling `update_cam!(ax.scene, ax.scene.camera_controls)`. +2. Reducing `GLMakie.transparency_weight_scale[]` which controls the maximum weight given to a transparent color. The default is `1000f0`. + +Adjusting the latter may also help with sharpness. \ No newline at end of file From 627b598fe458e2c5729c7e7591b98260626c5cbe Mon Sep 17 00:00:00 2001 From: Simon Date: Fri, 10 Dec 2021 19:47:31 +0100 Subject: [PATCH 4/4] use more common writing of float --- src/makielayout/layoutables/axis3d.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/makielayout/layoutables/axis3d.jl b/src/makielayout/layoutables/axis3d.jl index c3c27ee5e6e..13aa6c06cd1 100644 --- a/src/makielayout/layoutables/axis3d.jl +++ b/src/makielayout/layoutables/axis3d.jl @@ -220,7 +220,7 @@ function calculate_matrices(limits, px_area, elev, azim, perspectiveness, aspect end function projectionmatrix(viewmatrix, limits, eyepos, radius, azim, elev, angle, width, height, scales, viewmode) - near = 1f-2 + near = 0.01f0 far = radius + 2 * sqrt(3) aspect_ratio = width / height