From 482a2f85f96cc1db0fcea508cae5c276874b05e1 Mon Sep 17 00:00:00 2001 From: Mikulas Florek Date: Fri, 27 Sep 2019 00:28:12 +0200 Subject: [PATCH] editor icons are darker when they are behind some scene geom --- data/pipelines/editor_icon.shd | 14 ++++++++++++-- data/pipelines/main.pln | 14 ++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/data/pipelines/editor_icon.shd b/data/pipelines/editor_icon.shd index 8202ae980..1f4f7ba77 100644 --- a/data/pipelines/editor_icon.shd +++ b/data/pipelines/editor_icon.shd @@ -1,3 +1,5 @@ +include "pipelines/common.glsl" + texture_slot { name = "Albedo", default_texture = "textures/common/white.tga" @@ -16,10 +18,13 @@ vertex_shader [[ const vec2 a_uv = vec2(0, 0); #endif layout (location = 0) out vec2 v_uv; + layout (location = 1) out vec3 v_wpos; void main() { v_uv = a_uv; - gl_Position = u_camera_projection * u_camera_view * u_model * vec4(a_position, 1); + vec4 p = u_camera_view * u_model * vec4(a_position, 1); + v_wpos = p.xyz; + gl_Position = u_camera_projection * p; } ]] @@ -27,15 +32,20 @@ vertex_shader [[ fragment_shader [[ layout (binding=0) uniform sampler2D u_albedomap; + layout (binding=1) uniform sampler2D u_gbuffer_depth; layout (location = 0) in vec2 v_uv; + layout (location = 1) in vec3 v_wpos; layout(location = 0) out vec4 o_color; void main() { + vec2 screen_uv = gl_FragCoord.xy / u_framebuffer_size; + vec3 wpos = getViewPosition(u_gbuffer_depth, u_camera_inv_view_projection, screen_uv); vec4 albedo = texture(u_albedomap, v_uv); #ifdef ALPHA_CUTOUT if(albedo.a < 0.5) discard; #endif o_color.rgb = albedo.rgb; - o_color.w = 1; + o_color.a = 1; + if(length(wpos) < length(v_wpos)) o_color.rgb *= 0.25; } ]] \ No newline at end of file diff --git a/data/pipelines/main.pln b/data/pipelines/main.pln index b0a02161b..1a3dee0d7 100644 --- a/data/pipelines/main.pln +++ b/data/pipelines/main.pln @@ -270,9 +270,11 @@ function main() end debugPass(res, shadowmap) + local icon_ds = -1 if SCENE_VIEW ~= nil then + icon_ds = createRenderbuffer(1, 1, true, "depth24stencil8", "icon_ds") pass(getCameraParams()) - setRenderTargets(res, gbuffer_depth) + setRenderTargets(res, icon_ds) clear(CLEAR_DEPTH, 0, 0, 0, 1, 0) renderGizmos() end @@ -280,11 +282,15 @@ function main() render2D() if SCENE_VIEW ~= nil then - if enable_icons then - renderIcons() - end renderDebugShapes() renderSelectionOutline(res) + if enable_icons then + setRenderTargets(res, icon_ds) + bindRenderbuffers({ + gbuffer_depth, + }, 1) + renderIcons() + end end setOutput(res)