[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53588] trunk/blender/source/blender: Changes for opengl render to reflect new alpha premul pipeline

Sergey Sharybin sergey.vfx at gmail.com
Sat Jan 5 16:33:22 CET 2013


Revision: 53588
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53588
Author:   nazgul
Date:     2013-01-05 15:33:18 +0000 (Sat, 05 Jan 2013)
Log Message:
-----------
Changes for opengl render to reflect new alpha premul pipeline
without hurting quick texture painting

- ED_view3d_draw_offscreen will now output buffer with
  transparent alpha, if sky needed it should be alpha-undered
  later.

- ED_view3d_draw_offscreen_imbuf now accepts alpha mode as an
  argument which could be either R_ADDSKY or R_PREMULALPHA

- OpenGL render and sequencer's opengl preview will now reflect
  scene's Alpha Mode

- Quick Edit will use OpenGL with transparent alpha mode

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/sequencer.c
    trunk/blender/source/blender/editors/include/ED_view3d.h
    trunk/blender/source/blender/editors/render/render_opengl.c
    trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
    trunk/blender/source/blender/editors/space_view3d/view3d_draw.c
    trunk/blender/source/blender/imbuf/IMB_imbuf.h
    trunk/blender/source/blender/imbuf/intern/imageprocess.c
    trunk/blender/source/blender/windowmanager/intern/wm_files.c

Modified: trunk/blender/source/blender/blenkernel/intern/sequencer.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/sequencer.c	2013-01-05 14:56:37 UTC (rev 53587)
+++ trunk/blender/source/blender/blenkernel/intern/sequencer.c	2013-01-05 15:33:18 UTC (rev 53588)
@@ -2391,7 +2391,7 @@
 		BKE_scene_update_for_newframe(context.bmain, scene, scene->lay);
 		ibuf = sequencer_view3d_cb(scene, camera, context.rectx, context.recty, IB_rect,
 		                           context.scene->r.seq_prev_type, context.scene->r.seq_flag & R_SEQ_SOLID_TEX,
-		                           TRUE, FALSE, err_out);
+		                           TRUE, scene->r.alphamode, err_out);
 		if (ibuf == NULL) {
 			fprintf(stderr, "seq_render_scene_strip failed to get opengl buffer: %s\n", err_out);
 		}

Modified: trunk/blender/source/blender/editors/include/ED_view3d.h
===================================================================
--- trunk/blender/source/blender/editors/include/ED_view3d.h	2013-01-05 14:56:37 UTC (rev 53587)
+++ trunk/blender/source/blender/editors/include/ED_view3d.h	2013-01-05 15:33:18 UTC (rev 53588)
@@ -270,14 +270,14 @@
 int ED_view3d_context_activate(struct bContext *C);
 void ED_view3d_draw_offscreen_init(struct Scene *scene, struct View3D *v3d);
 void ED_view3d_draw_offscreen(struct Scene *scene, struct View3D *v3d, struct ARegion *ar,
-                              int winx, int winy, float viewmat[4][4], float winmat[4][4], int do_bgpic, int colormanage_background);
+                              int winx, int winy, float viewmat[4][4], float winmat[4][4], int do_bgpic);
 
 struct ImBuf *ED_view3d_draw_offscreen_imbuf(struct Scene *scene, struct View3D *v3d, struct ARegion *ar, int sizex, int sizey, unsigned int flag,
-                                             int draw_background, int colormanage_background, char err_out[256]);
+                                             int draw_background, int alpha_mode, 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,
-                                                    int use_solid_tex, int draw_background, int colormanage_background, char err_out[256]);
+                                                    int use_solid_tex, int draw_background, int alpha_mode, char err_out[256]);
+void ED_view3d_offscreen_sky_color_get(struct Scene *scene, float sky_color[3]);
 
-
 struct Base *ED_view3d_give_base_under_cursor(struct bContext *C, const int mval[2]);
 void ED_view3d_quadview_update(struct ScrArea *sa, struct ARegion *ar, short do_clip);
 void ED_view3d_update_viewmat(struct Scene *scene, struct View3D *v3d, struct ARegion *ar, float viewmat[4][4], float winmat[4][4]);

Modified: trunk/blender/source/blender/editors/render/render_opengl.c
===================================================================
--- trunk/blender/source/blender/editors/render/render_opengl.c	2013-01-05 14:56:37 UTC (rev 53587)
+++ trunk/blender/source/blender/editors/render/render_opengl.c	2013-01-05 15:33:18 UTC (rev 53588)
@@ -43,6 +43,7 @@
 
 #include "DNA_scene_types.h"
 #include "DNA_object_types.h"
+#include "DNA_world_types.h"
 
 #include "BKE_context.h"
 #include "BKE_global.h"
@@ -192,7 +193,7 @@
 		}
 
 		if ((scene->r.mode & R_OSA) == 0) {
-			ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, winmat, TRUE, FALSE);
+			ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, winmat, TRUE);
 			GPU_offscreen_read_pixels(oglrender->ofs, GL_FLOAT, rr->rectf);
 		}
 		else {
@@ -206,7 +207,7 @@
 			BLI_jitter_init(jit_ofs[0], scene->r.osa);
 
 			/* first sample buffer, also initializes 'rv3d->persmat' */
-			ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, winmat, TRUE, FALSE);
+			ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, winmat, TRUE);
 			GPU_offscreen_read_pixels(oglrender->ofs, GL_FLOAT, accum_buffer);
 
 			/* skip the first sample */
@@ -216,7 +217,7 @@
 				                    (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, TRUE, FALSE);
+				ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, winmat_jitter, TRUE);
 				GPU_offscreen_read_pixels(oglrender->ofs, GL_FLOAT, accum_tmp);
 				add_vn_vn(accum_buffer, accum_tmp, sizex * sizey * sizeof(float));
 			}
@@ -232,7 +233,8 @@
 	else {
 		/* shouldnt suddenly give errors mid-render but possible */
 		char err_out[256] = "unknown";
-		ImBuf *ibuf_view = ED_view3d_draw_offscreen_imbuf_simple(scene, scene->camera, oglrender->sizex, oglrender->sizey, IB_rectfloat, OB_SOLID, FALSE, TRUE, FALSE, err_out);
+		ImBuf *ibuf_view = ED_view3d_draw_offscreen_imbuf_simple(scene, scene->camera, oglrender->sizex, oglrender->sizey,
+		                                                         IB_rectfloat, OB_SOLID, FALSE, TRUE, R_ALPHAPREMUL, err_out);
 		camera = scene->camera;
 
 		if (ibuf_view) {
@@ -243,7 +245,13 @@
 			fprintf(stderr, "%s: failed to get buffer, %s\n", __func__, err_out);
 		}
 	}
-	
+
+	if (scene->r.alphamode == R_ADDSKY) {
+		float sky_color[3];
+		ED_view3d_offscreen_sky_color_get(scene, sky_color);
+		IMB_alpha_under_color_float(rr->rectf, sizex, sizey, sky_color);
+	}
+
 	/* note on color management:
 	 *
 	 * OpenGL renders into sRGB colors, but render buffers are expected to be

Modified: trunk/blender/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- trunk/blender/source/blender/editors/sculpt_paint/paint_image.c	2013-01-05 14:56:37 UTC (rev 53587)
+++ trunk/blender/source/blender/editors/sculpt_paint/paint_image.c	2013-01-05 15:33:18 UTC (rev 53588)
@@ -6038,7 +6038,7 @@
 	if (w > maxsize) w = maxsize;
 	if (h > maxsize) h = maxsize;
 
-	ibuf = ED_view3d_draw_offscreen_imbuf(CTX_data_scene(C), CTX_wm_view3d(C), CTX_wm_region(C), w, h, IB_rect, FALSE, FALSE, err_out);
+	ibuf = ED_view3d_draw_offscreen_imbuf(CTX_data_scene(C), CTX_wm_view3d(C), CTX_wm_region(C), w, h, IB_rect, FALSE, R_ALPHAPREMUL, err_out);
 	if (!ibuf) {
 		/* Mostly happens when OpenGL offscreen buffer was failed to create, */
 		/* but could be other reasons. Should be handled in the future. nazgul */

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_draw.c	2013-01-05 14:56:37 UTC (rev 53587)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_draw.c	2013-01-05 15:33:18 UTC (rev 53588)
@@ -2393,7 +2393,7 @@
 		invert_m4_m4(rv3d.persinv, rv3d.viewinv);
 
 		/* no need to call ED_view3d_draw_offscreen_init since shadow buffers were already updated */
-		ED_view3d_draw_offscreen(scene, v3d, &ar, winsize, winsize, viewmat, winmat, FALSE, FALSE);
+		ED_view3d_draw_offscreen(scene, v3d, &ar, winsize, winsize, viewmat, winmat, FALSE);
 		GPU_lamp_shadow_buffer_unbind(shadow->lamp);
 		
 		v3d->drawtype = drawtype;
@@ -2540,13 +2540,11 @@
 /* ED_view3d_draw_offscreen_init should be called before this to initialize
  * stuff like shadow buffers
  */
-void ED_view3d_draw_offscreen(Scene *scene, View3D *v3d, ARegion *ar,
-                              int winx, int winy, float viewmat[4][4], float winmat[4][4],
-                              int do_bgpic, int colormanage_background)
+void ED_view3d_draw_offscreen(Scene *scene, View3D *v3d, ARegion *ar, int winx, int winy,
+                              float viewmat[4][4], float winmat[4][4], int do_bgpic)
 {
 	RegionView3D *rv3d = ar->regiondata;
 	Base *base;
-	float backcol[3];
 	int bwinx, bwiny;
 	rcti brect;
 
@@ -2574,35 +2572,8 @@
 	 * warning! can be slow so only free animated images - campbell */
 	GPU_free_images_anim();
 
-	/* set background color, fallback on the view background color
-	 * (if active clip is set but frame is failed to load fallback to horizon color as background) */
-	if (scene->world) {
-		/* NOTE: currently OpenGL is supposed to always work in sRGB space and do not
-		 *       apply any tonemaps since it's really tricky to support for all features (GLSL, textures, etc)
-		 *       but due to compatibility issues background is being affected display transform, so we can
-		 *       emulate behavior of disabled color management
-		 *       but this function is also used for sequencer's scene strips which shouldn't be affected by
-		 *       tonemaps now and should be purely sRGB, that's why we've got this colormanage_background
-		 *       we can drop this flag in cost of some compatibility loss -- background wouldn't be
-		 *       color managed in 3d viewport
-		 *       same goes to opengl rendering, where color profile should be applied as very final step
-		 */
+	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
 
-		if (colormanage_background) {
-			IMB_colormanagement_pixel_to_display_space_v3(backcol, &scene->world->horr, &scene->view_settings,
-			                                              &scene->display_settings);
-		}
-		else {
-			linearrgb_to_srgb_v3_v3(backcol, &scene->world->horr);
-		}
-
-		glClearColor(backcol[0], backcol[1], backcol[2], 0.0f);
-	}
-	else {
-		 UI_ThemeClearColor(TH_BACK);
-	}
-
-
 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
 	/* setup view matrices */
@@ -2703,10 +2674,30 @@
 	G.f &= ~G_RENDER_OGL;
 }
 
+/* get a color used for offscreen sky, returns color in sRGB space */
+void ED_view3d_offscreen_sky_color_get(Scene *scene, float sky_color[3])
+{
+	if (scene->world)
+		linearrgb_to_srgb_v3_v3(sky_color, &scene->world->horr);
+	else
+		UI_GetThemeColor3fv(TH_BACK, sky_color);
+}
+
+static void offscreen_imbuf_add_sky(ImBuf *ibuf, Scene *scene)
+{
+	float sky_color[3];
+
+	ED_view3d_offscreen_sky_color_get(scene, sky_color);
+
+	if (ibuf->rect_float)
+		IMB_alpha_under_color_float(ibuf->rect_float, ibuf->x, ibuf->y, sky_color);
+	else
+		IMB_alpha_under_color_byte((unsigned char *) ibuf->rect, ibuf->x, ibuf->y, sky_color);
+}
+
 /* utility func for ED_view3d_draw_offscreen */
-ImBuf *ED_view3d_draw_offscreen_imbuf(Scene *scene, View3D *v3d, ARegion *ar,
-                                      int sizex, int sizey, unsigned int flag, int draw_background,

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list