[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59030] branches/soc-2011-tomato/source/ blender/compositor/operations: Replace our own box AA filter with BLI_jitter-based

Sergey Sharybin sergey.vfx at gmail.com
Fri Aug 9 03:10:35 CEST 2013


Revision: 59030
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59030
Author:   nazgul
Date:     2013-08-09 01:10:35 +0000 (Fri, 09 Aug 2013)
Log Message:
-----------
Replace our own box AA filter with BLI_jitter-based

Using box filtering for AA makes image too much blurry,
so here's an attempt to use generic BLI_jitter routines
to do sampling.

It's expected to be exactly the same as opengl renderer
does, but i could have got something wrong.

But anyway, results seems to be a little bit less fuzzy.

Modified Paths:
--------------
    branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackCommonOperation.cpp
    branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackCommonOperation.h
    branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackMaskOperation.cpp
    branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackMaskOperation.h
    branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackWarpImageOperation.cpp
    branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackWarpImageOperation.h

Modified: branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackCommonOperation.cpp
===================================================================
--- branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackCommonOperation.cpp	2013-08-09 01:09:55 UTC (rev 59029)
+++ branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackCommonOperation.cpp	2013-08-09 01:10:35 UTC (rev 59030)
@@ -47,6 +47,7 @@
 	MovieTrackingObject *object;
 
 	memset(this->m_corners, 0, sizeof(this->m_corners));
+	memset(this->m_frameSpaceCorners, 0, sizeof(this->m_frameSpaceCorners));
 
 	if (!this->m_movieClip)
 		return;
@@ -67,6 +68,11 @@
 			memcpy(this->m_corners, plane_marker->corners, sizeof(this->m_corners));
 		}
 	}
+
+	for (int i = 0; i < 4; i++) {
+		this->m_frameSpaceCorners[i][0] = this->m_corners[i][0] * this->getWidth();
+		this->m_frameSpaceCorners[i][1] = this->m_corners[i][1] * this->getHeight();
+	}
 }
 
 void PlaneTrackCommonOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2])

Modified: branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackCommonOperation.h
===================================================================
--- branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackCommonOperation.h	2013-08-09 01:09:55 UTC (rev 59029)
+++ branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackCommonOperation.h	2013-08-09 01:10:35 UTC (rev 59030)
@@ -40,7 +40,8 @@
 	char m_trackingObjectName[64];
 	char m_planeTrackName[64];
 
-	float m_corners[4][2];
+	float m_corners[4][2];            /* Corners coordinates in normalized space. */
+	float m_frameSpaceCorners[4][2];  /* Corners coordinates in pixel space. */
 
 	/**
 	 * Determine the output resolution. The resolution is retrieved from the Renderer

Modified: branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackMaskOperation.cpp
===================================================================
--- branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackMaskOperation.cpp	2013-08-09 01:09:55 UTC (rev 59029)
+++ branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackMaskOperation.cpp	2013-08-09 01:10:35 UTC (rev 59030)
@@ -28,6 +28,8 @@
 #include "BLI_math_color.h"
 
 extern "C" {
+	#include "BLI_jitter.h"
+
 	#include "BKE_movieclip.h"
 	#include "BKE_node.h"
 	#include "BKE_tracking.h"
@@ -38,30 +40,30 @@
 	this->addOutputSocket(COM_DT_VALUE);
 }
 
+void PlaneTrackMaskOperation::initExecution()
+{
+	PlaneTrackCommonOperation::initExecution();
+
+	const int osa = 8;
+	this->m_osa = osa;
+	BLI_jitter_init(this->m_jitter[0], osa);
+}
+
 void PlaneTrackMaskOperation::executePixel(float output[4], float x, float y, PixelSampler sampler)
 {
-	const int kernel_size = 4;
 	float point[2];
-	float frame_space_corners[4][2];
 
-	for (int i = 0; i < 4; i++) {
-		frame_space_corners[i][0] = this->m_corners[i][0] * this->getWidth() ;
-		frame_space_corners[i][1] = this->m_corners[i][1] * this->getHeight();
-	}
-
 	int inside_counter = 0;
-	for (int dx = 0; dx < kernel_size; dx++) {
-		for (int dy = 0; dy < kernel_size; dy++) {
-			point[0] = x + (float) dx / kernel_size;
-			point[1] = y + (float) dy / kernel_size;
+	for (int sample = 0; sample < this->m_osa; sample++) {
+		point[0] = x + this->m_jitter[sample][0];
+		point[1] = y + this->m_jitter[sample][1];
 
-			if (isect_point_tri_v2(point, frame_space_corners[0], frame_space_corners[1], frame_space_corners[2]) ||
-			    isect_point_tri_v2(point, frame_space_corners[0], frame_space_corners[2], frame_space_corners[3]))
-			{
-				inside_counter++;
-			}
+		if (isect_point_tri_v2(point, this->m_frameSpaceCorners[0], this->m_frameSpaceCorners[1], this->m_frameSpaceCorners[2]) ||
+		    isect_point_tri_v2(point, this->m_frameSpaceCorners[0], this->m_frameSpaceCorners[2], this->m_frameSpaceCorners[3]))
+		{
+			inside_counter++;
 		}
 	}
 
-	output[0] = (float) inside_counter / (kernel_size * kernel_size);
+	output[0] = (float) inside_counter / this->m_osa;
 }

Modified: branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackMaskOperation.h
===================================================================
--- branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackMaskOperation.h	2013-08-09 01:09:55 UTC (rev 59029)
+++ branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackMaskOperation.h	2013-08-09 01:10:35 UTC (rev 59030)
@@ -34,9 +34,15 @@
 #include "BLI_string.h"
 
 class PlaneTrackMaskOperation : public PlaneTrackCommonOperation {
+protected:
+	int m_osa;
+	float m_jitter[32][2];
+
 public:
 	PlaneTrackMaskOperation();
 
+	void initExecution();
+
 	void executePixel(float output[4], float x, float y, PixelSampler sampler);
 };
 

Modified: branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackWarpImageOperation.cpp
===================================================================
--- branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackWarpImageOperation.cpp	2013-08-09 01:09:55 UTC (rev 59029)
+++ branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackWarpImageOperation.cpp	2013-08-09 01:10:35 UTC (rev 59030)
@@ -29,6 +29,8 @@
 #include "BLI_math_color.h"
 
 extern "C" {
+	#include "BLI_jitter.h"
+
 	#include "BKE_movieclip.h"
 	#include "BKE_node.h"
 	#include "BKE_tracking.h"
@@ -133,6 +135,10 @@
 	PlaneTrackCommonOperation::initExecution();
 
 	this->m_pixelReader = this->getInputSocketReader(0);
+
+	const int osa = 8;
+	this->m_osa = osa;
+	BLI_jitter_init(this->m_jitter[0], osa);
 }
 
 void PlaneTrackWarpImageOperation::deinitExecution()
@@ -142,37 +148,28 @@
 
 void PlaneTrackWarpImageOperation::executePixel(float output[4], float x, float y, PixelSampler sampler)
 {
-	const int kernel_size = 4;
-	float frame_space_corners[4][2];
 	float color_accum[4];
 
-	for (int i = 0; i < 4; i++) {
-		frame_space_corners[i][0] = this->m_corners[i][0] * this->getWidth();
-		frame_space_corners[i][1] = this->m_corners[i][1] * this->getHeight();
-	}
-
 	zero_v4(color_accum);
-	for (int sample_dx = 0; sample_dx < kernel_size; sample_dx++) {
-		for (int sample_dy = 0; sample_dy < kernel_size; sample_dy++) {
-			float current_x = x + (float)sample_dx / kernel_size,
-			      current_y = y + (float)sample_dy / kernel_size;
-			if (isPointInsideQuad(current_x, current_y, frame_space_corners)) {
-				float current_color[4];
-				float u, v, dx, dy;
+	for (int sample = 0; sample < this->m_osa; sample++) {
+		float current_x = x + this->m_jitter[sample][0],
+		      current_y = y + this->m_jitter[sample][1];
+		if (isPointInsideQuad(current_x, current_y, this->m_frameSpaceCorners)) {
+			float current_color[4];
+			float u, v, dx, dy;
 
-				resolveUVAndDxDy(current_x, current_y, frame_space_corners, &u, &v, &dx, &dy);
+			resolveUVAndDxDy(current_x, current_y, this->m_frameSpaceCorners, &u, &v, &dx, &dy);
 
-				u *= this->m_pixelReader->getWidth();
-				v *= this->m_pixelReader->getHeight();
+			u *= this->m_pixelReader->getWidth();
+			v *= this->m_pixelReader->getHeight();
 
-				this->m_pixelReader->read(current_color, u, v, dx, dy, COM_PS_BICUBIC);
-				premul_to_straight_v4(current_color);
-				add_v4_v4(color_accum, current_color);
-			}
+			this->m_pixelReader->read(current_color, u, v, dx, dy, COM_PS_BICUBIC);
+			premul_to_straight_v4(current_color);
+			add_v4_v4(color_accum, current_color);
 		}
 	}
 
-	mul_v4_v4fl(output, color_accum, 1.0f / (kernel_size * kernel_size));
+	mul_v4_v4fl(output, color_accum, 1.0f / this->m_osa);
 	straight_to_premul_v4(output);
 }
 

Modified: branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackWarpImageOperation.h
===================================================================
--- branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackWarpImageOperation.h	2013-08-09 01:09:55 UTC (rev 59029)
+++ branches/soc-2011-tomato/source/blender/compositor/operations/COM_PlaneTrackWarpImageOperation.h	2013-08-09 01:10:35 UTC (rev 59030)
@@ -36,6 +36,8 @@
 class PlaneTrackWarpImageOperation : public PlaneTrackCommonOperation {
 protected:
 	SocketReader *m_pixelReader;
+	int m_osa;
+	float m_jitter[32][2];
 
 public:
 	PlaneTrackWarpImageOperation();




More information about the Bf-blender-cvs mailing list