diff options
7 files changed, 71 insertions, 2 deletions
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py index f371cad6d72..4476f144ae5 100644 --- a/release/scripts/startup/bl_ui/space_view3d.py +++ b/release/scripts/startup/bl_ui/space_view3d.py @@ -3675,6 +3675,9 @@ class VIEW3D_PT_shading(Panel): sub.prop(shading, "object_outline_color", text="") col.prop(view, "show_world") + row = col.split(0.4) + row.active = not shading.show_xray + row.prop(shading, "show_anti_aliasing") elif shading.type in ('MATERIAL'): row = col.row() diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt index afb527a07c6..805da27b81b 100644 --- a/source/blender/draw/CMakeLists.txt +++ b/source/blender/draw/CMakeLists.txt @@ -208,6 +208,7 @@ data_to_c_simple(engines/workbench/shaders/workbench_checkerboard_depth_frag.gls data_to_c_simple(engines/workbench/shaders/workbench_common_lib.glsl SRC) data_to_c_simple(engines/workbench/shaders/workbench_data_lib.glsl SRC) data_to_c_simple(engines/workbench/shaders/workbench_deferred_composite_frag.glsl SRC) +data_to_c_simple(engines/workbench/shaders/workbench_effect_fxaa_frag.glsl SRC) data_to_c_simple(engines/workbench/shaders/workbench_forward_composite_frag.glsl SRC) data_to_c_simple(engines/workbench/shaders/workbench_forward_depth_frag.glsl SRC) data_to_c_simple(engines/workbench/shaders/workbench_forward_transparent_accum_frag.glsl SRC) diff --git a/source/blender/draw/engines/workbench/shaders/workbench_effect_fxaa_frag.glsl b/source/blender/draw/engines/workbench/shaders/workbench_effect_fxaa_frag.glsl new file mode 100644 index 00000000000..4ffd20c2839 --- /dev/null +++ b/source/blender/draw/engines/workbench/shaders/workbench_effect_fxaa_frag.glsl @@ -0,0 +1,19 @@ + +in vec4 uvcoordsvar; + +out vec4 FragColor; + +uniform sampler2D colorBuffer; +uniform vec2 invertedViewportSize; + +void main() +{ + FragColor = FxaaPixelShader( + uvcoordsvar.st, + colorBuffer, + invertedViewportSize, + 1.0, + 0.166, + 0.0833 + ); +} diff --git a/source/blender/draw/engines/workbench/workbench_deferred.c b/source/blender/draw/engines/workbench/workbench_deferred.c index 05f04c75aea..4d89e7cd566 100644 --- a/source/blender/draw/engines/workbench/workbench_deferred.c +++ b/source/blender/draw/engines/workbench/workbench_deferred.c @@ -65,6 +65,7 @@ static struct { struct GPUShader *shadow_pass_manifold_sh; struct GPUShader *shadow_caps_sh; struct GPUShader *shadow_caps_manifold_sh; + struct GPUShader *effect_fxaa_sh; struct GPUTexture *object_id_tx; /* ref only, not alloced */ struct GPUTexture *color_buffer_tx; /* ref only, not alloced */ @@ -72,6 +73,7 @@ static struct { struct GPUTexture *specular_buffer_tx; /* ref only, not alloced */ struct GPUTexture *normal_buffer_tx; /* ref only, not alloced */ struct GPUTexture *composite_buffer_tx; /* ref only, not alloced */ + struct GPUTexture *effect_buffer_tx; /* ref only, not alloced */ SceneDisplay display; /* world light direction for shadows */ float light_direction_vs[3]; @@ -84,6 +86,8 @@ static struct { } e_data = {{NULL}}; /* Shaders */ +extern char datatoc_common_fxaa_lib_glsl[]; +extern char datatoc_common_fullscreen_vert_glsl[]; extern char datatoc_common_hair_lib_glsl[]; extern char datatoc_workbench_prepass_vert_glsl[]; @@ -100,6 +104,7 @@ extern char datatoc_workbench_background_lib_glsl[]; extern char datatoc_workbench_cavity_lib_glsl[]; extern char datatoc_workbench_common_lib_glsl[]; extern char datatoc_workbench_data_lib_glsl[]; +extern char datatoc_workbench_effect_fxaa_frag_glsl[]; extern char datatoc_workbench_object_outline_lib_glsl[]; extern char datatoc_workbench_world_light_lib_glsl[]; @@ -317,6 +322,12 @@ void workbench_deferred_engine_init(WORKBENCH_Data *vedata) char *cavity_frag = workbench_build_cavity_frag(); e_data.cavity_sh = DRW_shader_create_fullscreen(cavity_frag, NULL); MEM_freeN(cavity_frag); + + e_data.effect_fxaa_sh = DRW_shader_create_with_lib( + datatoc_common_fullscreen_vert_glsl, NULL, + datatoc_workbench_effect_fxaa_frag_glsl, + datatoc_common_fxaa_lib_glsl, + NULL); } if (!stl->g_data) { @@ -336,6 +347,8 @@ void workbench_deferred_engine_init(WORKBENCH_Data *vedata) e_data.specular_buffer_tx = DRW_texture_pool_query_2D(size[0], size[1], GPU_RGBA8, &draw_engine_workbench_solid); e_data.composite_buffer_tx = DRW_texture_pool_query_2D( size[0], size[1], GPU_RGBA16F, &draw_engine_workbench_solid); + e_data.effect_buffer_tx = DRW_texture_pool_query_2D( + size[0], size[1], GPU_RGBA16F, &draw_engine_workbench_solid); if (NORMAL_ENCODING_ENABLED()) { e_data.normal_buffer_tx = DRW_texture_pool_query_2D( @@ -361,6 +374,10 @@ void workbench_deferred_engine_init(WORKBENCH_Data *vedata) GPU_ATTACHMENT_TEXTURE(dtxl->depth), GPU_ATTACHMENT_TEXTURE(e_data.composite_buffer_tx), }); + GPU_framebuffer_ensure_config(&fbl->effect_fb, { + GPU_ATTACHMENT_NONE, + GPU_ATTACHMENT_TEXTURE(e_data.effect_buffer_tx), + }); } { @@ -406,6 +423,14 @@ void workbench_deferred_engine_init(WORKBENCH_Data *vedata) DRW_shgroup_uniform_block(grp, "samples_block", e_data.sampling_ubo); DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL); } + + { + psl->effect_fxaa_pass = DRW_pass_create("Effect FXAA", DRW_STATE_WRITE_COLOR); + DRWShadingGroup *grp = DRW_shgroup_create(e_data.effect_fxaa_sh, psl->effect_fxaa_pass); + DRW_shgroup_uniform_texture_ref(grp, "colorBuffer", &e_data.composite_buffer_tx); + DRW_shgroup_uniform_vec2(grp, "invertedViewportSize", DRW_viewport_invert_size_get(), 1); + DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL); + } } void workbench_deferred_engine_free() @@ -425,6 +450,7 @@ void workbench_deferred_engine_free() DRW_SHADER_FREE_SAFE(e_data.shadow_caps_sh); DRW_SHADER_FREE_SAFE(e_data.shadow_caps_manifold_sh); + DRW_SHADER_FREE_SAFE(e_data.effect_fxaa_sh); } static void workbench_composite_uniforms(WORKBENCH_PrivateData *wpd, DRWShadingGroup *grp) @@ -867,8 +893,18 @@ void workbench_deferred_draw_scene(WORKBENCH_Data *vedata) DRW_draw_pass(psl->composite_pass); } - GPU_framebuffer_bind(dfbl->color_only_fb); - DRW_transform_to_display(e_data.composite_buffer_tx); + if (FXAA_ENABLED(wpd)) { + GPU_framebuffer_bind(fbl->effect_fb); + DRW_draw_pass(psl->effect_fxaa_pass); + + GPU_framebuffer_bind(dfbl->color_only_fb); + DRW_transform_to_display(e_data.effect_buffer_tx); + } + else { + GPU_framebuffer_bind(dfbl->color_only_fb); + DRW_transform_to_display(e_data.composite_buffer_tx); + } + workbench_private_data_free(wpd); } diff --git a/source/blender/draw/engines/workbench/workbench_private.h b/source/blender/draw/engines/workbench/workbench_private.h index b17cc93d148..e6921535063 100644 --- a/source/blender/draw/engines/workbench/workbench_private.h +++ b/source/blender/draw/engines/workbench/workbench_private.h @@ -50,6 +50,7 @@ #define STUDIOLIGHT_ORIENTATION_VIEWNORMAL_ENABLED(wpd) (MATCAP_ENABLED(wpd) && (wpd->studio_light->flag & STUDIOLIGHT_ORIENTATION_VIEWNORMAL)) #define CAVITY_ENABLED(wpd) (wpd->shading.flag & V3D_SHADING_CAVITY) #define SHADOW_ENABLED(wpd) (wpd->shading.flag & V3D_SHADING_SHADOW) +#define FXAA_ENABLED(wpd) (wpd->shading.flag & V3D_SHADING_EFFECT_FXAA) #define SPECULAR_HIGHLIGHT_ENABLED(wpd) ((wpd->shading.flag & V3D_SHADING_SPECULAR_HIGHLIGHT) && (!STUDIOLIGHT_ORIENTATION_VIEWNORMAL_ENABLED(wpd))) #define OBJECT_ID_PASS_ENABLED(wpd) (wpd->shading.flag & V3D_SHADING_OBJECT_OUTLINE) #define NORMAL_VIEWPORT_COMP_PASS_ENABLED(wpd) (MATCAP_ENABLED(wpd) || STUDIOLIGHT_ENABLED(wpd) || SHADOW_ENABLED(wpd) || SPECULAR_HIGHLIGHT_ENABLED(wpd)) @@ -61,6 +62,7 @@ typedef struct WORKBENCH_FramebufferList { struct GPUFrameBuffer *prepass_fb; struct GPUFrameBuffer *cavity_fb; struct GPUFrameBuffer *composite_fb; + struct GPUFrameBuffer *effect_fb; /* Forward render buffers */ struct GPUFrameBuffer *object_outline_fb; @@ -85,6 +87,7 @@ typedef struct WORKBENCH_PassList { struct DRWPass *shadow_depth_fail_caps_mani_pass; struct DRWPass *composite_pass; struct DRWPass *composite_shadow_pass; + struct DRWPass *effect_fxaa_pass; /* forward rendering */ struct DRWPass *transparent_accum_pass; diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h index 9686981d674..b7d12a3cf1d 100644 --- a/source/blender/makesdna/DNA_view3d_types.h +++ b/source/blender/makesdna/DNA_view3d_types.h @@ -353,6 +353,7 @@ enum { V3D_SHADING_SPECULAR_HIGHLIGHT = (1 << 4), V3D_SHADING_CAVITY = (1 << 5), V3D_SHADING_MATCAP_FLIP_X = (1 << 6), + V3D_SHADING_EFFECT_FXAA = (1 << 7), }; /* View3DShading->single_color_type */ diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index 5ce27a533b8..845218e3296 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -2346,6 +2346,12 @@ static void rna_def_space_view3d_shading(BlenderRNA *brna) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); + prop = RNA_def_property(srna, "show_anti_aliasing", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "shading.flag", V3D_SHADING_EFFECT_FXAA); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_ui_text(prop, "Anti Alias", "Draw the view using FXAA"); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); + prop = RNA_def_property(srna, "selected_studio_light", PROP_POINTER, PROP_NONE); RNA_def_property_struct_type(prop, "StudioLight"); RNA_define_verify_sdna(0); |