Blender V4.3
overlay_antialiasing.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2019 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
43#include "DRW_render.hh"
44
45#include "ED_screen.hh"
46
47#include "overlay_private.hh"
48
50{
51 OVERLAY_FramebufferList *fbl = vedata->fbl;
52 OVERLAY_TextureList *txl = vedata->txl;
53 OVERLAY_PrivateData *pd = vedata->stl->pd;
55
56 /* Small texture which will have very small impact on render-time. */
57 if (txl->dummy_depth_tx == nullptr) {
58 const float pixel[1] = {1.0f};
60 1, 1, GPU_DEPTH_COMPONENT24, DRWTextureFlag(0), pixel);
61 }
62
63 if (!DRW_state_is_fbo()) {
64 pd->antialiasing.enabled = false;
65 return;
66 }
67
68 bool need_wire_expansion = (G_draw.block.size_pixel > 1.0f);
69 pd->antialiasing.enabled = need_wire_expansion ||
70 ((U.gpu_flag & USER_GPU_FLAG_OVERLAY_SMOOTH_WIRE) != 0);
71
72 GPUTexture *color_tex = nullptr;
73 GPUTexture *line_tex = nullptr;
74
75 if (pd->antialiasing.enabled) {
78
79 color_tex = txl->overlay_color_tx;
80 line_tex = txl->overlay_line_tx;
81 }
82 else {
83 /* Just a copy of the defaults frame-buffers. */
84 color_tex = dtxl->color_overlay;
85 }
86
88 {
89 GPU_ATTACHMENT_NONE,
90 GPU_ATTACHMENT_TEXTURE(color_tex),
91 });
93 {
94 GPU_ATTACHMENT_TEXTURE(dtxl->depth),
95 GPU_ATTACHMENT_TEXTURE(color_tex),
96 });
98 {
99 GPU_ATTACHMENT_TEXTURE(dtxl->depth),
100 GPU_ATTACHMENT_TEXTURE(color_tex),
101 GPU_ATTACHMENT_TEXTURE(line_tex),
102 });
103}
104
106{
107 OVERLAY_TextureList *txl = vedata->txl;
108 OVERLAY_PrivateData *pd = vedata->stl->pd;
109 OVERLAY_PassList *psl = vedata->psl;
111 GPUShader *sh;
112 DRWShadingGroup *grp;
113
114 if (pd->antialiasing.enabled) {
115 /* `antialiasing.enabled` is also enabled for wire expansion. Check here if
116 * anti aliasing is needed. */
117 const bool do_smooth_lines = (U.gpu_flag & USER_GPU_FLAG_OVERLAY_SMOOTH_WIRE) != 0;
118
120
122 grp = DRW_shgroup_create(sh, psl->antialiasing_ps);
123 DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo);
124 DRW_shgroup_uniform_bool_copy(grp, "doSmoothLines", do_smooth_lines);
125 DRW_shgroup_uniform_texture_ref(grp, "depthTex", &dtxl->depth);
129 }
130
131 /* A bit out of place... not related to antialiasing. */
132 if (pd->xray_enabled) {
134
136 grp = DRW_shgroup_create(sh, psl->xray_fade_ps);
137 DRW_shgroup_uniform_texture_ref(grp, "depthTex", &dtxl->depth);
138 DRW_shgroup_uniform_texture_ref(grp, "xrayDepthTex", &txl->temp_depth_tx);
139 DRW_shgroup_uniform_float_copy(grp, "opacity", 1.0f - pd->xray_opacity);
141 }
142}
143
145{
146 OVERLAY_FramebufferList *fbl = vedata->fbl;
147 OVERLAY_TextureList *txl = vedata->txl;
148 OVERLAY_PassList *psl = vedata->psl;
149 OVERLAY_PrivateData *pd = vedata->stl->pd;
151
152 if (pd->antialiasing.enabled) {
154 {GPU_ATTACHMENT_TEXTURE(dtxl->depth_in_front),
155 GPU_ATTACHMENT_TEXTURE(txl->overlay_color_tx)});
156
158 {GPU_ATTACHMENT_TEXTURE(dtxl->depth_in_front),
159 GPU_ATTACHMENT_TEXTURE(txl->overlay_color_tx),
160 GPU_ATTACHMENT_TEXTURE(txl->overlay_line_tx)});
161 }
162 else {
164 {GPU_ATTACHMENT_TEXTURE(dtxl->depth_in_front),
165 GPU_ATTACHMENT_TEXTURE(dtxl->color_overlay)});
166
168 {GPU_ATTACHMENT_TEXTURE(dtxl->depth_in_front),
169 GPU_ATTACHMENT_TEXTURE(dtxl->color_overlay),
170 GPU_ATTACHMENT_TEXTURE(txl->overlay_line_tx)});
171 }
172
173 pd->antialiasing.do_depth_copy = !(psl->wireframe_ps == nullptr ||
175 (pd->xray_enabled && pd->xray_opacity > 0.0f);
176 pd->antialiasing.do_depth_infront_copy = !(psl->wireframe_xray_ps == nullptr ||
178
179 const bool do_wireframe = pd->antialiasing.do_depth_copy ||
181 if (pd->xray_enabled || do_wireframe) {
183 }
184}
185
187{
188 OVERLAY_FramebufferList *fbl = vedata->fbl;
189 OVERLAY_PrivateData *pd = vedata->stl->pd;
190
191 if (pd->antialiasing.enabled) {
192 const float clear_col[4] = {0.0f, 0.0f, 0.0f, 0.0f};
195 }
196
197 /* If we are not in solid shading mode, we clear the depth. */
198 if (DRW_state_is_fbo() && pd->clear_in_front) {
199 /* TODO(fclem): This clear should be done in a global place. */
202 }
203}
204
206{
207 OVERLAY_FramebufferList *fbl = vedata->fbl;
208 OVERLAY_TextureList *txl = vedata->txl;
209 OVERLAY_PrivateData *pd = vedata->stl->pd;
210
213 /* We copy the depth of the rendered geometry to be able to compare to the overlays depth. */
215 }
216
217 if (DRW_state_is_fbo() && pd->xray_enabled) {
218 /* We then clear to not occlude the overlays directly. */
221 }
222}
223
225{
226 OVERLAY_TextureList *txl = vedata->txl;
227 OVERLAY_PrivateData *pd = vedata->stl->pd;
228
231 /* We copy the depth of the rendered geometry to be able to compare to the overlays depth. */
233 }
234}
235
237{
238 OVERLAY_PassList *psl = vedata->psl;
239 OVERLAY_PrivateData *pd = vedata->stl->pd;
240
241 if (DRW_state_is_fbo() && pd->xray_enabled && pd->xray_opacity > 0.0f) {
242 /* Partially occlude overlays using the geometry depth pass. */
244 }
245}
246
@ USER_GPU_FLAG_OVERLAY_SMOOTH_WIRE
DRWTextureFlag
@ DRW_TEX_FILTER
#define DRW_PASS_CREATE(pass, state)
#define DRW_shgroup_uniform_block(shgroup, name, ubo)
void GPU_framebuffer_bind(GPUFrameBuffer *framebuffer)
void GPU_framebuffer_clear_color(GPUFrameBuffer *fb, const float clear_col[4])
#define GPU_framebuffer_ensure_config(_fb,...)
void GPU_framebuffer_clear_depth(GPUFrameBuffer *fb, float clear_depth)
void GPU_texture_copy(GPUTexture *dst, GPUTexture *src)
@ GPU_SRGB8_A8
@ GPU_DEPTH24_STENCIL8
@ GPU_DEPTH_COMPONENT24
struct GPUShader GPUShader
unsigned int U
Definition btGjkEpa3.h:78
DRW_Global G_draw
DefaultFramebufferList * DRW_viewport_framebuffer_list_get()
DefaultTextureList * DRW_viewport_texture_list_get()
bool DRW_state_is_fbo()
DRWShadingGroup * DRW_shgroup_create(GPUShader *shader, DRWPass *pass)
void DRW_shgroup_uniform_float_copy(DRWShadingGroup *shgroup, const char *name, const float value)
bool DRW_pass_is_empty(DRWPass *pass)
void DRW_shgroup_call_procedural_triangles(DRWShadingGroup *shgroup, const Object *ob, uint tri_count)
void DRW_shgroup_uniform_texture_ref(DRWShadingGroup *shgroup, const char *name, GPUTexture **tex)
void DRW_shgroup_uniform_bool_copy(DRWShadingGroup *shgroup, const char *name, const bool value)
void DRW_draw_pass(DRWPass *pass)
void DRW_texture_ensure_fullscreen_2d(GPUTexture **tex, eGPUTextureFormat format, DRWTextureFlag flags)
GPUTexture * DRW_texture_create_2d(int w, int h, eGPUTextureFormat format, DRWTextureFlag flags, const float *fpixels)
@ DRW_STATE_WRITE_COLOR
Definition draw_state.hh:30
@ DRW_STATE_BLEND_ALPHA_PREMUL
Definition draw_state.hh:57
@ DRW_STATE_BLEND_MUL
Definition draw_state.hh:60
RAYTRACE_GROUP_SIZE additional_info("eevee_shared", "eevee_gbuffer_data", "eevee_global_ubo", "eevee_sampling_data", "eevee_utility_texture", "eevee_hiz_data", "draw_view") .specialization_constant(Type RAYTRACE_GROUP_SIZE in_sh_0_tx in_sh_2_tx screen_normal_tx GPU_RGBA8
void OVERLAY_antialiasing_cache_init(OVERLAY_Data *vedata)
void OVERLAY_antialiasing_cache_finish(OVERLAY_Data *vedata)
void OVERLAY_antialiasing_init(OVERLAY_Data *vedata)
void OVERLAY_xray_depth_copy(OVERLAY_Data *vedata)
void OVERLAY_antialiasing_start(OVERLAY_Data *vedata)
void OVERLAY_xray_depth_infront_copy(OVERLAY_Data *vedata)
void OVERLAY_xray_fade_draw(OVERLAY_Data *vedata)
void OVERLAY_antialiasing_end(OVERLAY_Data *vedata)
GPUShader * OVERLAY_shader_xray_fade()
GPUShader * OVERLAY_shader_antialiasing()
GlobalsUboStorage block
GPUUniformBuf * block_ubo
GPUFrameBuffer * overlay_only_fb
GPUTexture * depth_in_front
GPUTexture * color_overlay
OVERLAY_PassList * psl
OVERLAY_StorageList * stl
OVERLAY_FramebufferList * fbl
OVERLAY_TextureList * txl
GPUFrameBuffer * overlay_line_fb
GPUFrameBuffer * overlay_default_fb
GPUFrameBuffer * overlay_color_only_fb
GPUFrameBuffer * overlay_line_in_front_fb
GPUFrameBuffer * overlay_in_front_fb
DRWPass * antialiasing_ps
DRWPass * wireframe_xray_ps
struct OVERLAY_PrivateData::@227 antialiasing
OVERLAY_PrivateData * pd
GPUTexture * dummy_depth_tx
GPUTexture * temp_depth_tx
GPUTexture * overlay_line_tx
GPUTexture * overlay_color_tx