[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55759] trunk/blender: Bunch of fixes for GLSL display transform

Sergey Sharybin sergey.vfx at gmail.com
Wed Apr 3 17:59:55 CEST 2013


Revision: 55759
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55759
Author:   nazgul
Date:     2013-04-03 15:59:54 +0000 (Wed, 03 Apr 2013)
Log Message:
-----------
Bunch of fixes for GLSL display transform

- GLSL shader wasn't aware of alpha predivide option,
  always assuming alpha is straight. Gave wrong results
  when displaying transparent float buffers.

- GLSL display wasn't aware of float buffers with number
  of channels different from 4, crashing when trying to
  display image with different number of channels.

  This required a bit larger changes, namely now it's
  possible to pass format (GL_RGB, GL_RGBAm GL_LUMINANCE)
  to glaDrawPixelsTex, This also implied adding format to
  glaDrawPixelsAuto and modifying all places where this
  functions are called.

  Now GLSL will handle both 3 and 4 channels buffers,
  single channel images are handled by CPU.

- Replaced hack for render result displaying with a bit
  different hack.

  Namely CPU conversion will happen only during render,
  once render is done GLSL would be used for displaying
  render result on a screen.

  This is so because of the way renderer updates parts
  of the image -- it happens without respect to active
  render layer in image user. This is harmless because
  only display buffer is modifying, but this is tricky
  because we don't have original buffer opened during
  rendering.

  One more related fix here was about when rendering
  multiple layers, wrong image would be displaying when
  rendering is done. Added a signal to invalidate
  display buffer once rendering is done (only happens
  when using multiple layers). This solves issue with
  wrong buffer stuck on the display when using regular
  CPU display space transform and if GLSL is available
  it'll make image displayed with a GLSL shader.

- As an additional change, byte buffers now also uses
  GLSL display transform.

  So now only dutehr and RGB curves are stoppers for
  using GLSL for all kind of display transforms.

Modified Paths:
--------------
    trunk/blender/intern/opencolorio/fallback_impl.cc
    trunk/blender/intern/opencolorio/ocio_capi.cc
    trunk/blender/intern/opencolorio/ocio_capi.h
    trunk/blender/intern/opencolorio/ocio_impl.h
    trunk/blender/intern/opencolorio/ocio_impl_glsl.cc
    trunk/blender/source/blender/editors/include/BIF_glutil.h
    trunk/blender/source/blender/editors/interface/interface_draw.c
    trunk/blender/source/blender/editors/render/render_internal.c
    trunk/blender/source/blender/editors/screen/glutil.c
    trunk/blender/source/blender/editors/space_file/file_draw.c
    trunk/blender/source/blender/editors/space_node/drawnode.c
    trunk/blender/source/blender/editors/space_node/node_draw.c
    trunk/blender/source/blender/editors/space_view3d/drawobject.c
    trunk/blender/source/blender/editors/space_view3d/view3d_draw.c
    trunk/blender/source/blender/imbuf/IMB_colormanagement.h
    trunk/blender/source/blender/imbuf/intern/colormanagement.c
    trunk/blender/source/blender/windowmanager/intern/wm_dragdrop.c

Modified: trunk/blender/intern/opencolorio/fallback_impl.cc
===================================================================
--- trunk/blender/intern/opencolorio/fallback_impl.cc	2013-04-03 15:04:24 UTC (rev 55758)
+++ trunk/blender/intern/opencolorio/fallback_impl.cc	2013-04-03 15:59:54 UTC (rev 55759)
@@ -381,7 +381,7 @@
 {
 }
 
-bool FallbackImpl::setupGLSLDraw(struct OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRcPtr *processor)
+bool FallbackImpl::setupGLSLDraw(struct OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRcPtr *processor, bool predivide)
 {
 	return false;
 }

Modified: trunk/blender/intern/opencolorio/ocio_capi.cc
===================================================================
--- trunk/blender/intern/opencolorio/ocio_capi.cc	2013-04-03 15:04:24 UTC (rev 55758)
+++ trunk/blender/intern/opencolorio/ocio_capi.cc	2013-04-03 15:59:54 UTC (rev 55759)
@@ -283,9 +283,9 @@
 	impl->matrixTransformScale(m44, offset4, scale4f);
 }
 
-int OCIO_setupGLSLDraw(struct OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRcPtr *processor)
+int OCIO_setupGLSLDraw(struct OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRcPtr *processor, int predivide)
 {
-	return (int) impl->setupGLSLDraw(state_r, processor);
+	return (int) impl->setupGLSLDraw(state_r, processor, (bool) predivide);
 }
 
 void OCIO_finishGLSLDraw(struct OCIO_GLSLDrawState *state)

Modified: trunk/blender/intern/opencolorio/ocio_capi.h
===================================================================
--- trunk/blender/intern/opencolorio/ocio_capi.h	2013-04-03 15:04:24 UTC (rev 55758)
+++ trunk/blender/intern/opencolorio/ocio_capi.h	2013-04-03 15:59:54 UTC (rev 55759)
@@ -121,7 +121,7 @@
 
 void OCIO_matrixTransformScale(float * m44, float * offset4, const float * scale4);
 
-int OCIO_setupGLSLDraw(struct OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRcPtr *processor);
+int OCIO_setupGLSLDraw(struct OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRcPtr *processor, int predivide);
 void OCIO_finishGLSLDraw(struct OCIO_GLSLDrawState *state);
 void OCIO_freeOGLState(struct OCIO_GLSLDrawState *state);
 

Modified: trunk/blender/intern/opencolorio/ocio_impl.h
===================================================================
--- trunk/blender/intern/opencolorio/ocio_impl.h	2013-04-03 15:04:24 UTC (rev 55758)
+++ trunk/blender/intern/opencolorio/ocio_impl.h	2013-04-03 15:59:54 UTC (rev 55759)
@@ -96,7 +96,7 @@
 
 	virtual void matrixTransformScale(float * m44, float * offset4, const float * scale4) = 0;
 
-	virtual bool setupGLSLDraw(struct OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRcPtr *processor) = 0;
+	virtual bool setupGLSLDraw(struct OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRcPtr *processor, bool predivide) = 0;
 	virtual void finishGLSLDraw(struct OCIO_GLSLDrawState *state) = 0;
 	virtual void freeGLState(struct OCIO_GLSLDrawState *state_r) = 0;
 };
@@ -169,7 +169,7 @@
 
 	void matrixTransformScale(float * m44, float * offset4, const float * scale4);
 
-	bool setupGLSLDraw(struct OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRcPtr *processor);
+	bool setupGLSLDraw(struct OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRcPtr *processor, bool predivide);
 	void finishGLSLDraw(struct OCIO_GLSLDrawState *state);
 	void freeGLState(struct OCIO_GLSLDrawState *state_r);
 };
@@ -243,7 +243,7 @@
 
 	void matrixTransformScale(float * m44, float * offset4, const float * scale4);
 
-	bool setupGLSLDraw(struct OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRcPtr *processor);
+	bool setupGLSLDraw(struct OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRcPtr *processor, bool predivide);
 	void finishGLSLDraw(struct OCIO_GLSLDrawState *state);
 	void freeGLState(struct OCIO_GLSLDrawState *state_r);
 };

Modified: trunk/blender/intern/opencolorio/ocio_impl_glsl.cc
===================================================================
--- trunk/blender/intern/opencolorio/ocio_impl_glsl.cc	2013-04-03 15:04:24 UTC (rev 55758)
+++ trunk/blender/intern/opencolorio/ocio_impl_glsl.cc	2013-04-03 15:59:54 UTC (rev 55759)
@@ -77,15 +77,33 @@
 	GLint last_texture, last_texture_unit;
 } OCIO_GLSLDrawState;
 
-static const char * g_fragShaderText = ""
+/* Hardcoded to do alpha predivide before color space conversion */
+static const char *g_fragShaderText = ""
 "\n"
 "uniform sampler2D tex1;\n"
 "uniform sampler3D tex2;\n"
+"uniform bool predivide;\n"
 "\n"
 "void main()\n"
 "{\n"
 "    vec4 col = texture2D(tex1, gl_TexCoord[0].st);\n"
-"    gl_FragColor = OCIODisplay(col, tex2);\n"
+"    if (predivide == false || col[3] == 1.0f || col[3] == 0.0f) {\n"
+"      gl_FragColor = OCIODisplay(col, tex2);\n"
+"    } else {\n"
+"      float alpha = col[3];\n"
+"      float inv_alpha = 1.0f / alpha;\n"
+"\n"
+"      col[0] *= inv_alpha;\n"
+"      col[1] *= inv_alpha;\n"
+"      col[2] *= inv_alpha;\n"
+"\n"
+"      gl_FragColor = OCIODisplay(col, tex2);\n"
+"\n"
+"      col[0] *= alpha;\n"
+"      col[1] *= alpha;\n"
+"      col[2] *= alpha;\n"
+"    }\n"
+"\n"
 "}\n";
 
 static GLuint compileShaderText(GLenum shaderType, const char *text)
@@ -187,7 +205,7 @@
  * When all drawing is finished, finishGLSLDraw shall be called to
  * restore OpenGL context to it's pre-GLSL draw state.
  */
-bool OCIOImpl::setupGLSLDraw(OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRcPtr *processor)
+bool OCIOImpl::setupGLSLDraw(OCIO_GLSLDrawState **state_r, OCIO_ConstProcessorRcPtr *processor, bool predivide)
 {
 	ConstProcessorRcPtr ocio_processor = *(ConstProcessorRcPtr *) processor;
 
@@ -252,6 +270,7 @@
 		glUseProgram(state->program);
 		glUniform1i(glGetUniformLocation(state->program, "tex1"), 0);
 		glUniform1i(glGetUniformLocation(state->program, "tex2"), 1);
+		glUniform1i(glGetUniformLocation(state->program, "predivide"), predivide);
 
 		return true;
 	}

Modified: trunk/blender/source/blender/editors/include/BIF_glutil.h
===================================================================
--- trunk/blender/source/blender/editors/include/BIF_glutil.h	2013-04-03 15:04:24 UTC (rev 55758)
+++ trunk/blender/source/blender/editors/include/BIF_glutil.h	2013-04-03 15:59:54 UTC (rev 55759)
@@ -144,17 +144,17 @@
  * 1-to-1 mapping to screen space.
  */
 
-void glaDrawPixelsTex(float x, float y, int img_w, int img_h, int format, int zoomfilter, void *rect);
+void glaDrawPixelsTex(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect);
 
 /**
  * glaDrawPixelsAuto - Switches between texture or pixel drawing using UserDef.
  * only RGBA
  * needs glaDefine2DArea to be set.
  */
-void glaDrawPixelsAuto(float x, float y, int img_w, int img_h, int format, int zoomfilter, void *rect);
+void glaDrawPixelsAuto(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect);
 
 
-void glaDrawPixelsTexScaled(float x, float y, int img_w, int img_h, int format, int zoomfilter, void *rect, float scaleX, float scaleY);
+void glaDrawPixelsTexScaled(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect, float scaleX, float scaleY);
 
 /* 2D Drawing Assistance */
 

Modified: trunk/blender/source/blender/editors/interface/interface_draw.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_draw.c	2013-04-03 15:04:24 UTC (rev 55758)
+++ trunk/blender/source/blender/editors/interface/interface_draw.c	2013-04-03 15:59:54 UTC (rev 55759)
@@ -454,7 +454,7 @@
 		float facy = (float)h / (float)ibuf->y;
 		glPixelZoom(facx, facy);
 	}
-	glaDrawPixelsAuto((float)rect->xmin, (float)rect->ymin, ibuf->x, ibuf->y, GL_UNSIGNED_BYTE, GL_NEAREST, ibuf->rect);
+	glaDrawPixelsAuto((float)rect->xmin, (float)rect->ymin, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, ibuf->rect);
 	
 	glPixelZoom(1.0f, 1.0f);
 	

Modified: trunk/blender/source/blender/editors/render/render_internal.c
===================================================================
--- trunk/blender/source/blender/editors/render/render_internal.c	2013-04-03 15:04:24 UTC (rev 55758)
+++ trunk/blender/source/blender/editors/render/render_internal.c	2013-04-03 15:59:54 UTC (rev 55759)
@@ -429,10 +429,38 @@
 		nodeUpdateID(rj->scene->nodetree, &rj->scene->id);
 		WM_main_add_notifier(NC_NODE | NA_EDITED, rj->scene);
 	}
-	
+
 	/* XXX render stability hack */
 	G.is_rendering = FALSE;
 	WM_main_add_notifier(NC_WINDOW, NULL);
+
+	/* Partial render result will always update display buffer
+	 * for first render layer only. This is nice because you'll
+	 * see render progress during rendering, but it ends up in
+	 * wrong display buffer shown after rendering.
+	 *
+	 * The code below will mark display buffer as invalid after
+	 * rendering in case multiple layers were rendered, which
+	 * ensures display buffer matches render layer after
+	 * rendering.
+	 *
+	 * Perhaps proper way would be to toggle active render
+	 * layer in image editor and job, so we always display
+	 * layer being currently rendered. But this is not so much
+	 * trivial at this moment, especially because of external
+	 * engine API, so lets use simple and robust way for now
+	 *                                          - sergey -
+	 */
+	if (rj->scene->r.layers.first != rj->scene->r.layers.last) {
+		void *lock;
+		Image *ima = rj->image;
+		ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &rj->iuser, &lock);
+
+		if (ibuf)
+			ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID;
+
+		BKE_image_release_ibuf(ima, ibuf, lock);
+	}
 }
 
 /* called by render, check job 'stop' value or the global */

Modified: trunk/blender/source/blender/editors/screen/glutil.c
===================================================================
--- trunk/blender/source/blender/editors/screen/glutil.c	2013-04-03 15:04:24 UTC (rev 55758)
+++ trunk/blender/source/blender/editors/screen/glutil.c	2013-04-03 15:59:54 UTC (rev 55759)
@@ -42,6 +42,7 @@
 #include "BLI_threads.h"
 
 #include "BKE_blender.h"
+#include "BKE_global.h"
 #include "BKE_colortools.h"
 #include "BKE_context.h"
 
@@ -488,7 +489,7 @@
 	return texid;
 }
 
-void glaDrawPixelsTexScaled(float x, float y, int img_w, int img_h, int format, int zoomfilter, void *rect, float scaleX, float scaleY)
+void glaDrawPixelsTexScaled(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect, float scaleX, float scaleY)
 {
 	unsigned char *uc_rect = (unsigned char *) rect;
 	float *f_rect = (float *)rect;

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list