Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2015-11-11 16:06:26 +0300
committerCampbell Barton <ideasman42@gmail.com>2015-11-11 16:25:09 +0300
commit7b96f02f5b7e08712874eadaad7275140d0f6ef5 (patch)
treebe5a9e30afef99c119f29ab514bc207b15251ae5
parent145298e2d3b2edfc3ddb6d8ccfb3f393232dafb9 (diff)
OpenGL Render: Support full-sample Anti-Aliasing
This brings back old (slower), higher quality method. Useful since graphics cards often use a faster MSAA which only oversamples edges.
-rw-r--r--release/scripts/startup/bl_ui/space_info.py3
-rw-r--r--source/blender/blenkernel/BKE_sequencer.h3
-rw-r--r--source/blender/blenkernel/intern/sequencer.c3
-rw-r--r--source/blender/editors/include/ED_view3d.h4
-rw-r--r--source/blender/editors/render/render_opengl.c12
-rw-r--r--source/blender/editors/sculpt_paint/paint_image_proj.c2
-rw-r--r--source/blender/editors/space_view3d/view3d_draw.c98
-rw-r--r--source/blender/windowmanager/intern/wm_files.c4
8 files changed, 102 insertions, 27 deletions
diff --git a/release/scripts/startup/bl_ui/space_info.py b/release/scripts/startup/bl_ui/space_info.py
index d295cc19fb7..369656f2620 100644
--- a/release/scripts/startup/bl_ui/space_info.py
+++ b/release/scripts/startup/bl_ui/space_info.py
@@ -262,8 +262,9 @@ class INFO_MT_opengl_render(Menu):
layout = self.layout
rd = context.scene.render
-
layout.prop(rd, "use_antialiasing")
+ layout.prop(rd, "use_full_sample")
+
layout.prop_menu_enum(rd, "antialiasing_samples")
layout.prop_menu_enum(rd, "alpha_mode")
diff --git a/source/blender/blenkernel/BKE_sequencer.h b/source/blender/blenkernel/BKE_sequencer.h
index 350edde407b..0a2a2c7131f 100644
--- a/source/blender/blenkernel/BKE_sequencer.h
+++ b/source/blender/blenkernel/BKE_sequencer.h
@@ -108,6 +108,7 @@ typedef struct SeqRenderData {
struct GPUOffScreen *gpu_offscreen;
struct GPUFX *gpu_fx;
int gpu_samples;
+ bool gpu_full_samples;
} SeqRenderData;
void BKE_sequencer_new_render_data(
@@ -418,7 +419,7 @@ struct Sequence *BKE_sequencer_add_movie_strip(struct bContext *C, ListBase *seq
typedef struct ImBuf *(*SequencerDrawView)(
struct Scene *, struct Object *, int, int,
unsigned int, int, bool, bool, bool,
- int, int, const char *,
+ int, int, bool, const char *,
struct GPUFX *, struct GPUOffScreen *, char[256]);
extern SequencerDrawView sequencer_view3d_cb;
diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c
index 6d583651e0f..08975fe17f0 100644
--- a/source/blender/blenkernel/intern/sequencer.c
+++ b/source/blender/blenkernel/intern/sequencer.c
@@ -565,6 +565,7 @@ void BKE_sequencer_new_render_data(
r_context->view_id = 0;
r_context->gpu_offscreen = NULL;
r_context->gpu_samples = (scene->r.mode & R_OSA) ? scene->r.osa : 0;
+ r_context->gpu_full_samples = (r_context->gpu_samples) && (scene->r.scemode & R_FULL_SAMPLE);
}
/* ************************* iterator ************************** */
@@ -3221,7 +3222,7 @@ static ImBuf *seq_render_scene_strip(const SeqRenderData *context, Sequence *seq
context->scene->r.seq_prev_type,
(context->scene->r.seq_flag & R_SEQ_SOLID_TEX) != 0,
use_gpencil, true, scene->r.alphamode,
- context->gpu_samples, viewname,
+ context->gpu_samples, context->gpu_full_samples, viewname,
context->gpu_fx, context->gpu_offscreen, err_out);
if (ibuf == NULL) {
fprintf(stderr, "seq_render_scene_strip failed to get opengl buffer: %s\n", err_out);
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index e5fe163ce40..83a71c651cd 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -333,12 +333,12 @@ void ED_view3d_draw_offscreen(
struct ImBuf *ED_view3d_draw_offscreen_imbuf(
struct Scene *scene, struct View3D *v3d, struct ARegion *ar, int sizex, int sizey,
unsigned int flag, bool draw_background,
- int alpha_mode, int samples, const char *viewname,
+ int alpha_mode, int samples, bool full_samples, const char *viewname,
struct GPUFX *fx, struct GPUOffScreen *ofs, char err_out[256]);
struct ImBuf *ED_view3d_draw_offscreen_imbuf_simple(
struct Scene *scene, struct Object *camera, int width, int height,
unsigned int flag, int drawtype, bool use_solid_tex, bool use_gpencil, bool draw_background,
- int alpha_mode, int samples, const char *viewname,
+ int alpha_mode, int samples, bool full_samples, const char *viewname,
struct GPUFX *fx, struct GPUOffScreen *ofs, char err_out[256]);
struct Base *ED_view3d_give_base_under_cursor(struct bContext *C, const int mval[2]);
diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c
index 2a48d30dfd1..738ee1faed3 100644
--- a/source/blender/editors/render/render_opengl.c
+++ b/source/blender/editors/render/render_opengl.c
@@ -97,6 +97,7 @@ typedef struct OGLRender {
GPUOffScreen *ofs;
int ofs_samples;
+ bool ofs_full_samples;
GPUFX *fx;
int sizex, sizey;
int write_still;
@@ -276,7 +277,7 @@ static void screen_opengl_render_doit(OGLRender *oglrender, RenderResult *rr)
context.view_id = BKE_scene_multiview_view_id_get(&scene->r, viewname);
context.gpu_offscreen = oglrender->ofs;
context.gpu_fx = oglrender->fx;
- context.gpu_samples = oglrender->ofs_samples;
+ context.gpu_full_samples = oglrender->ofs_full_samples;
ibuf = BKE_sequencer_give_ibuf(&context, CFRA, chanshown);
@@ -341,12 +342,13 @@ static void screen_opengl_render_doit(OGLRender *oglrender, RenderResult *rr)
/* shouldnt suddenly give errors mid-render but possible */
char err_out[256] = "unknown";
ImBuf *ibuf_view;
+ const int alpha_mode = (draw_sky) ? R_ADDSKY : R_ALPHAPREMUL;
if (view_context) {
ibuf_view = ED_view3d_draw_offscreen_imbuf(
scene, v3d, ar, sizex, sizey,
IB_rect, draw_bgpic,
- (draw_sky) ? R_ADDSKY : R_ALPHAPREMUL, oglrender->ofs_samples, viewname,
+ alpha_mode, oglrender->ofs_samples, oglrender->ofs_full_samples, viewname,
oglrender->fx, oglrender->ofs, err_out);
/* for stamp only */
@@ -358,7 +360,7 @@ static void screen_opengl_render_doit(OGLRender *oglrender, RenderResult *rr)
ibuf_view = ED_view3d_draw_offscreen_imbuf_simple(
scene, scene->camera, oglrender->sizex, oglrender->sizey,
IB_rect, OB_SOLID, false, true, true,
- (draw_sky) ? R_ADDSKY : R_ALPHAPREMUL, oglrender->ofs_samples, viewname,
+ alpha_mode, oglrender->ofs_samples, oglrender->ofs_full_samples, viewname,
oglrender->fx, oglrender->ofs, err_out);
camera = scene->camera;
}
@@ -471,6 +473,7 @@ static bool screen_opengl_render_init(bContext *C, wmOperator *op)
OGLRender *oglrender;
int sizex, sizey;
const int samples = (scene->r.mode & R_OSA) ? scene->r.osa : 0;
+ const bool full_samples = (samples != 0) && (scene->r.scemode & R_FULL_SAMPLE);
bool is_view_context = RNA_boolean_get(op->ptr, "view_context");
const bool is_animation = RNA_boolean_get(op->ptr, "animation");
const bool is_sequencer = RNA_boolean_get(op->ptr, "sequencer");
@@ -515,7 +518,7 @@ static bool screen_opengl_render_init(bContext *C, wmOperator *op)
sizey = (scene->r.size * scene->r.ysch) / 100;
/* corrects render size with actual size, not every card supports non-power-of-two dimensions */
- ofs = GPU_offscreen_create(sizex, sizey, samples, err_out);
+ ofs = GPU_offscreen_create(sizex, sizey, full_samples ? 0 : samples, err_out);
if (!ofs) {
BKE_reportf(op->reports, RPT_ERROR, "Failed to create OpenGL off-screen buffer, %s", err_out);
@@ -528,6 +531,7 @@ static bool screen_opengl_render_init(bContext *C, wmOperator *op)
oglrender->ofs = ofs;
oglrender->ofs_samples = samples;
+ oglrender->ofs_full_samples = full_samples;
oglrender->sizex = sizex;
oglrender->sizey = sizey;
oglrender->bmain = CTX_data_main(C);
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 3b6f88f0538..6ebf965b215 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -5401,7 +5401,7 @@ static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op)
ibuf = ED_view3d_draw_offscreen_imbuf(
scene, CTX_wm_view3d(C), CTX_wm_region(C),
- w, h, IB_rect, false, R_ALPHAPREMUL, 0, NULL,
+ w, h, IB_rect, false, R_ALPHAPREMUL, 0, false, NULL,
NULL, NULL, err_out);
if (!ibuf) {
/* Mostly happens when OpenGL offscreen buffer was failed to create, */
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 14861734bfa..ab0d02aab66 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -48,6 +48,7 @@
#include "BLI_blenlib.h"
#include "BLI_math.h"
+#include "BLI_jitter.h"
#include "BLI_utildefines.h"
#include "BLI_endian_switch.h"
#include "BLI_threads.h"
@@ -3294,7 +3295,7 @@ void ED_view3d_draw_offscreen(
ImBuf *ED_view3d_draw_offscreen_imbuf(
Scene *scene, View3D *v3d, ARegion *ar, int sizex, int sizey,
unsigned int flag, bool draw_background,
- int alpha_mode, int samples, const char *viewname,
+ int alpha_mode, int samples, bool full_samples, const char *viewname,
/* output vars */
GPUFX *fx, GPUOffScreen *ofs, char err_out[256])
{
@@ -3305,8 +3306,8 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
/* view state */
GPUFXSettings fx_settings = {NULL};
+ bool is_ortho = false;
float winmat[4][4];
- bool is_ortho;
if (UNLIKELY(v3d == NULL))
return NULL;
@@ -3316,7 +3317,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
glPushAttrib(GL_LIGHTING_BIT);
/* bind */
- ofs = GPU_offscreen_create(sizex, sizey, samples, err_out);
+ ofs = GPU_offscreen_create(sizex, sizey, full_samples ? 0 : samples, err_out);
if (ofs == NULL) {
glPopAttrib();
return NULL;
@@ -3327,6 +3328,9 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
GPU_offscreen_bind(ofs, true);
+ /* read in pixels & stamp */
+ ibuf = IMB_allocImBuf(sizex, sizey, 32, flag);
+
/* render 3d view */
if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
CameraParams params;
@@ -3361,18 +3365,82 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
}
}
- ED_view3d_draw_offscreen(
- scene, v3d, ar, sizex, sizey, NULL, winmat,
- draw_background, draw_sky, !is_ortho, viewname,
- fx, &fx_settings, ofs);
+ if ((samples && full_samples) == 0) {
+ /* Single-pass render, common case */
+ ED_view3d_draw_offscreen(
+ scene, v3d, ar, sizex, sizey, NULL, winmat,
+ draw_background, draw_sky, !is_ortho, viewname,
+ fx, &fx_settings, ofs);
- /* read in pixels & stamp */
- ibuf = IMB_allocImBuf(sizex, sizey, 32, flag);
+ if (ibuf->rect_float) {
+ GPU_offscreen_read_pixels(ofs, GL_FLOAT, ibuf->rect_float);
+ }
+ else if (ibuf->rect) {
+ GPU_offscreen_read_pixels(ofs, GL_UNSIGNED_BYTE, ibuf->rect);
+ }
+ }
+ else {
+ /* Multi-pass render, use accumulation buffer & jitter for 'full' oversampling.
+ * Use becauise OpenGL may use a lower quality MSAA, and only oversample edges. */
+ static float jit_ofs[32][2];
+ float winmat_jitter[4][4];
+ /* use imbuf as temp storage, before writing into it from accumulation buffer */
+ unsigned char *rect_temp = ibuf->rect ? (void *)ibuf->rect : (void *)ibuf->rect_float;
+ unsigned int *accum_buffer = MEM_mallocN(sizex * sizey * sizeof(int[4]), "accum1");
+ unsigned int i;
+ int j;
+
+ BLI_jitter_init(jit_ofs, scene->r.osa);
+
+ /* first sample buffer, also initializes 'rv3d->persmat' */
+ ED_view3d_draw_offscreen(
+ scene, v3d, ar, sizex, sizey, NULL, winmat,
+ draw_background, draw_sky, !is_ortho, viewname,
+ fx, &fx_settings, ofs);
+ GPU_offscreen_read_pixels(ofs, GL_UNSIGNED_BYTE, rect_temp);
+
+ i = sizex * sizey * 4;
+ while (i--) {
+ accum_buffer[i] = rect_temp[i];
+ }
- if (ibuf->rect_float)
- GPU_offscreen_read_pixels(ofs, GL_FLOAT, ibuf->rect_float);
- else if (ibuf->rect)
- GPU_offscreen_read_pixels(ofs, GL_UNSIGNED_BYTE, ibuf->rect);
+ /* skip the first sample */
+ for (j = 1; j < samples; j++) {
+ copy_m4_m4(winmat_jitter, winmat);
+ window_translate_m4(
+ winmat_jitter, rv3d->persmat,
+ (jit_ofs[j][0] * 2.0f) / sizex,
+ (jit_ofs[j][1] * 2.0f) / sizey);
+
+ ED_view3d_draw_offscreen(
+ scene, v3d, ar, sizex, sizey, NULL, winmat_jitter,
+ draw_background, draw_sky, !is_ortho, viewname,
+ fx, &fx_settings, ofs);
+ GPU_offscreen_read_pixels(ofs, GL_UNSIGNED_BYTE, rect_temp);
+
+ i = sizex * sizey * 4;
+ while (i--) {
+ accum_buffer[i] += rect_temp[i];
+ }
+ }
+
+ if (ibuf->rect_float) {
+ float *rect_float = ibuf->rect_float;
+ i = sizex * sizey * 4;
+ while (i--) {
+ rect_float[i] = (float)(accum_buffer[i] / samples) * (1.0f / 255.0f);
+ }
+ }
+ else {
+ unsigned char *rect_ub = (unsigned char *)ibuf->rect;
+ i = sizex * sizey * 4;
+ while (i--) {
+ rect_ub[i] = accum_buffer[i] / samples;
+ }
+ }
+
+ MEM_freeN(accum_buffer);
+ }
/* unbind */
GPU_offscreen_unbind(ofs, true);
@@ -3400,7 +3468,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
ImBuf *ED_view3d_draw_offscreen_imbuf_simple(
Scene *scene, Object *camera, int width, int height,
unsigned int flag, int drawtype, bool use_solid_tex, bool use_gpencil, bool draw_background,
- int alpha_mode, int samples, const char *viewname,
+ int alpha_mode, int samples, bool full_samples, const char *viewname,
GPUFX *fx, GPUOffScreen *ofs, char err_out[256])
{
View3D v3d = {NULL};
@@ -3450,7 +3518,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf_simple(
return ED_view3d_draw_offscreen_imbuf(
scene, &v3d, &ar, width, height, flag,
- draw_background, alpha_mode, samples, viewname,
+ draw_background, alpha_mode, samples, full_samples, viewname,
fx, ofs, err_out);
}
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index 87f8c17ca1f..e87be231025 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -935,14 +935,14 @@ static ImBuf *blend_file_thumb(Scene *scene, bScreen *screen, BlendThumbnail **t
ibuf = ED_view3d_draw_offscreen_imbuf_simple(
scene, scene->camera,
BLEN_THUMB_SIZE * 2, BLEN_THUMB_SIZE * 2,
- IB_rect, OB_SOLID, false, false, false, R_ALPHAPREMUL, 0, NULL,
+ IB_rect, OB_SOLID, false, false, false, R_ALPHAPREMUL, 0, false, NULL,
NULL, NULL, err_out);
}
else {
ibuf = ED_view3d_draw_offscreen_imbuf(
scene, v3d, ar,
BLEN_THUMB_SIZE * 2, BLEN_THUMB_SIZE * 2,
- IB_rect, false, R_ALPHAPREMUL, 0, NULL,
+ IB_rect, false, R_ALPHAPREMUL, 0, false, NULL,
NULL, NULL, err_out);
}