[Bf-blender-cvs] [8b1daab] temp-cycles-microdisplacement: Remove triangles from DiagSplit implementation

Mai Lavelle noreply at git.blender.org
Fri Jun 24 19:26:50 CEST 2016


Commit: 8b1daab90b6f2c5a0841ce22e50bf42789f4fbb9
Author: Mai Lavelle
Date:   Mon Jun 20 02:26:56 2016 -0400
Branches: temp-cycles-microdisplacement
https://developer.blender.org/rB8b1daab90b6f2c5a0841ce22e50bf42789f4fbb9

Remove triangles from DiagSplit implementation

Not needed now that we have ngons

===================================================================

M	intern/cycles/subd/subd_dice.cpp
M	intern/cycles/subd/subd_dice.h
M	intern/cycles/subd/subd_patch.cpp
M	intern/cycles/subd/subd_patch.h
M	intern/cycles/subd/subd_split.cpp
M	intern/cycles/subd/subd_split.h

===================================================================

diff --git a/intern/cycles/subd/subd_dice.cpp b/intern/cycles/subd/subd_dice.cpp
index 1e7a403..d99050c 100644
--- a/intern/cycles/subd/subd_dice.cpp
+++ b/intern/cycles/subd/subd_dice.cpp
@@ -344,160 +344,5 @@ void QuadDice::dice(SubPatch& sub, EdgeFactors& ef)
 	assert(vert_offset == params.mesh->verts.size());
 }
 
-/* TriangleDice */
-
-TriangleDice::TriangleDice(const SubdParams& params_)
-: EdgeDice(params_)
-{
-}
-
-void TriangleDice::reserve(EdgeFactors& ef, int M)
-{
-	int num_verts = ef.tu + ef.tv + ef.tw;
-
-	for(int m = M-2; m > 0; m -= 2)
-		num_verts += 3 + (m-1)*3;
-	
-	if(!(M & 1))
-		num_verts++;
-	
-	EdgeDice::reserve(num_verts);
-}
-
-float2 TriangleDice::map_uv(SubPatch& sub, float2 uv)
-{
-	/* map UV from subpatch to patch parametric coordinates */
-	return uv.x*sub.Pu + uv.y*sub.Pv + (1.0f - uv.x - uv.y)*sub.Pw;
-}
-
-int TriangleDice::add_vert(SubPatch& sub, float2 uv)
-{
-	return EdgeDice::add_vert(sub.patch, map_uv(sub, uv));
-}
-
-void TriangleDice::add_grid(SubPatch& sub, EdgeFactors& ef, int M)
-{
-	// XXX normals are flipped, why?
-
-	/* grid is constructed starting from the outside edges, and adding
-	 * progressively smaller inner triangles that connected to the outer
-	 * one, until M = 1 or 2, the we fill up the last part. */
-	vector<int> outer_u, outer_v, outer_w;
-	int m;
-
-	/* add outer corners vertices */
-	{
-		float2 p_u = make_float2(1.0f, 0.0f);
-		float2 p_v = make_float2(0.0f, 1.0f);
-		float2 p_w = make_float2(0.0f, 0.0f);
-
-		int corner_u = add_vert(sub, p_u);
-		int corner_v = add_vert(sub, p_v);
-		int corner_w = add_vert(sub, p_w);
-
-		outer_u.push_back(corner_v);
-		outer_v.push_back(corner_w);
-		outer_w.push_back(corner_u);
-
-		for(int i = 1; i < ef.tu; i++)
-			outer_u.push_back(add_vert(sub, interp(p_v, p_w, i/(float)ef.tu)));
-		for(int i = 1; i < ef.tv; i++)
-			outer_v.push_back(add_vert(sub, interp(p_w, p_u, i/(float)ef.tv)));
-		for(int i = 1; i < ef.tw; i++)
-			outer_w.push_back(add_vert(sub, interp(p_u, p_v, i/(float)ef.tw)));
-
-		outer_u.push_back(corner_w);
-		outer_v.push_back(corner_u);
-		outer_w.push_back(corner_v);
-	}
-
-	for(m = M-2; m > 0; m -= 2) {
-		vector<int> inner_u, inner_v, inner_w;
-
-		const float t0 = m / (float)M;
-		float2 center = make_float2(1.0f/3.0f, 1.0f/3.0f);
-
-		/* 3 corner vertices */
-		float2 p_u = interp(center, make_float2(1.0f, 0.0f), t0);
-		float2 p_v = interp(center, make_float2(0.0f, 1.0f), t0);
-		float2 p_w = interp(center, make_float2(0.0f, 0.0f), t0);
-
-		int corner_u = add_vert(sub, p_u);
-		int corner_v = add_vert(sub, p_v);
-		int corner_w = add_vert(sub, p_w);
-
-		/* construct array of vertex indices for each side */
-		inner_u.push_back(corner_v);
-		inner_v.push_back(corner_w);
-		inner_w.push_back(corner_u);
-
-		for(int i = 1; i < m; i++) {
-			/* add vertices between corners */
-			const float t1 = i / (float)m;
-
-			inner_u.push_back(add_vert(sub, interp(p_v, p_w, t1)));
-			inner_v.push_back(add_vert(sub, interp(p_w, p_u, t1)));
-			inner_w.push_back(add_vert(sub, interp(p_u, p_v, t1)));
-		}
-
-		inner_u.push_back(corner_w);
-		inner_v.push_back(corner_u);
-		inner_w.push_back(corner_v);
-
-		/* stitch together inner/outer with triangles */
-		stitch_triangles(sub.patch, outer_u, inner_u);
-		stitch_triangles(sub.patch, outer_v, inner_v);
-		stitch_triangles(sub.patch, outer_w, inner_w);
-
-		outer_u = inner_u;
-		outer_v = inner_v;
-		outer_w = inner_w;
-	}
-
-	/* fill up last part */
-	if(m == -1) {
-		/* single triangle */
-		add_triangle(sub.patch, outer_w[0], outer_u[0], outer_v[0]);
-	}
-	else {
-		/* center vertex + up to 6 triangles */
-		int center = add_vert(sub, make_float2(1.0f/3.0f, 1.0f/3.0f));
-
-		add_triangle(sub.patch, outer_w[0], outer_w[1], center);
-		/* if this is false then there is only one triangle on this side */
-		if(outer_w.size() > 2)
-			add_triangle(sub.patch, outer_w[1], outer_w[2], center);
-
-		add_triangle(sub.patch, outer_u[0], outer_u[1], center);
-		if(outer_u.size() > 2)
-			add_triangle(sub.patch, outer_u[1], outer_u[2], center);
-
-		add_triangle(sub.patch, outer_v[0], outer_v[1], center);
-		if(outer_v.size() > 2)
-			add_triangle(sub.patch, outer_v[1], outer_v[2], center);
-	}
-}
-
-void TriangleDice::dice(SubPatch& sub, EdgeFactors& ef)
-{
-	/* todo: handle 2 1 1 resolution */
-	int M = max(ef.tu, max(ef.tv, ef.tw));
-
-	/* Due to the "slant" of the edges of a triangle compared to a quad, the internal
-	 * triangles end up smaller, causing over-tessellation. This is to correct for this
-	 * difference in area. Technically its only correct for equilateral triangles, but
-	 * its better than how it was.
-	 *
-	 * (2*cos(radians(30))/3)**0.5
-	 */
-	float S = 0.7598356856515927f;
-	M = max((int)ceil(S*M), 1);
-
-	reserve(ef, M);
-	add_grid(sub, ef, M);
-
-	assert(vert_offset == params.mesh->verts.size());
-}
-
 CCL_NAMESPACE_END
 
diff --git a/intern/cycles/subd/subd_dice.h b/intern/cycles/subd/subd_dice.h
index 85bd0ea..a051f7e 100644
--- a/intern/cycles/subd/subd_dice.h
+++ b/intern/cycles/subd/subd_dice.h
@@ -136,46 +136,6 @@ public:
 	void dice(SubPatch& sub, EdgeFactors& ef);
 };
 
-/* Triangle EdgeDice
- *
- * Edge tessellation factors and subpatch coordinates are as follows:
- *
- *        Pw
- *        /\
- *    tv /  \ tu
- *      /    \
- *     /      \
- *  Pu -------- Pv
- *        tw     
- */
-
-class TriangleDice : public EdgeDice {
-public:
-	struct SubPatch {
-		Patch *patch;
-
-		float2 Pu;
-		float2 Pv;
-		float2 Pw;
-	};
-
-	struct EdgeFactors {
-		int tu;
-		int tv;
-		int tw;
-	};
-
-	explicit TriangleDice(const SubdParams& params);
-
-	void reserve(EdgeFactors& ef, int M);
-
-	float2 map_uv(SubPatch& sub, float2 uv);
-	int add_vert(SubPatch& sub, float2 uv);
-
-	void add_grid(SubPatch& sub, EdgeFactors& ef, int M);
-	void dice(SubPatch& sub, EdgeFactors& ef);
-};
-
 CCL_NAMESPACE_END
 
 #endif /* __SUBD_DICE_H__ */
diff --git a/intern/cycles/subd/subd_patch.cpp b/intern/cycles/subd/subd_patch.cpp
index 60a7801..d3319c5 100644
--- a/intern/cycles/subd/subd_patch.cpp
+++ b/intern/cycles/subd/subd_patch.cpp
@@ -84,32 +84,6 @@ BoundBox LinearQuadPatch::bound()
 	return bbox;
 }
 
-/* Linear Triangle Patch */
-
-void LinearTrianglePatch::eval(float3 *P, float3 *dPdu, float3 *dPdv, float3 *N, float u, float v)
-{
-	*P = u*hull[0] + v*hull[1] + (1.0f - u - v)*hull[2];
-
-	if(dPdu && dPdv) {
-		*dPdu = hull[0] - hull[2];
-		*dPdv = hull[1] - hull[2];
-	}
-
-	if(N) {
-		*N = normalize(u*normals[0] + v*normals[1] + (1.0f - u - v)*normals[2]);
-	}
-}
-
-BoundBox LinearTrianglePatch::bound()
-{
-	BoundBox bbox = BoundBox::empty;
-
-	for(int i = 0; i < 3; i++)
-		bbox.grow(hull[i]);
-	
-	return bbox;
-}
-
 /* Bicubic Patch */
 
 void BicubicPatch::eval(float3 *P, float3 *dPdu, float3 *dPdv, float3 *N, float u, float v)
diff --git a/intern/cycles/subd/subd_patch.h b/intern/cycles/subd/subd_patch.h
index 0cf930f..3d7d833 100644
--- a/intern/cycles/subd/subd_patch.h
+++ b/intern/cycles/subd/subd_patch.h
@@ -26,7 +26,6 @@ class Patch {
 public:
 	virtual ~Patch() {}
 	virtual void eval(float3 *P, float3 *dPdu, float3 *dPdv, float3 *N, float u, float v) = 0;
-	virtual bool is_triangle() { return false; }
 	virtual BoundBox bound() = 0;
 	virtual int ptex_face_id() { return -1; }
 
@@ -41,19 +40,6 @@ public:
 	float3 normals[4];
 
 	void eval(float3 *P, float3 *dPdu, float3 *dPdv, float3 *N, float u, float v);
-	bool is_triangle() { return false; }
-	BoundBox bound();
-};
-
-/* Linear Triangle Patch */
-
-class LinearTrianglePatch : public Patch {
-public:
-	float3 hull[3];
-	float3 normals[3];
-
-	void eval(float3 *P, float3 *dPdu, float3 *dPdv, float3 *N, float u, float v);
-	bool is_triangle() { return true; }
 	BoundBox bound();
 };
 
@@ -64,7 +50,6 @@ public:
 	float3 hull[16];
 
 	void eval(float3 *P, float3 *dPdu, float3 *dPdv, float3 *N, float u, float v);
-	bool is_triangle() { return false; }
 	BoundBox bound();
 };
 
diff --git a/intern/cycles/subd/subd_split.cpp b/intern/cycles/subd/subd_split.cpp
index c4af8cc..15df4e4 100644
--- a/intern/cycles/subd/subd_split.cpp
+++ b/intern/cycles/subd/subd_split.cpp
@@ -40,12 +40,6 @@ void DiagSplit::dispatch(QuadDice::SubPatch& sub, QuadDice::EdgeFactors& ef)
 	edgefactors_quad.push_back(ef);
 }
 
-void DiagSplit::dispatch(TriangleDice::SubPatch& sub, TriangleDice::EdgeFactors& ef)
-{
-	subpatches_triangle.push_back(sub);
-	edgefactors_triangle.push_back(ef);
-}
-
 float3 DiagSplit::to_world(Patch *patch, float2 uv)
 {
 	float3 P;
@@ -112,34 +106,6 @@ void DiagSplit::partition_edge(Patch *patch, float2 *P, int *t0, int *t1, float2
 	}
 }
 
-static float2 right_to_equilateral(float2 P)
-{
-	static const float2 A = make_float2(1.0f, 0.5f);
-	static const float2 B = make_float2(0.0f, sinf(M_PI_F/3.0f));
-	return make_float2(dot(P, A), dot(P, B));
-}
-
-static void limit_edge_factors(const TriangleDice::SubPatch& sub, TriangleDice::EdgeFactors& ef, int max_t)
-{
-	float2 Pu = sub.Pu;
-	float2 Pv = sub.Pv;
-	float2 Pw = sub.Pw;
-
-	if(sub.patch->is_triangle()) {
-		Pu = right_to_equilateral(Pu);
-		Pv = right_to_equilateral(Pv);
-		Pw = right_to_equilateral(Pw);
-	}
-
-	int tu = int(max_t * len(Pw - Pv));
-	int tv = int(max_t * len(Pw - Pu));
-	int tw = int(max_t * len(Pv - Pu));
-
-	ef.tu = tu <= 1 ? 1 : min(ef.tu, tu);
-	ef.tv = tv <= 1 ? 1 : min(ef.tv, tv);
-	ef.tw = tw <= 1 ? 1 : min(ef.tw, tw);
-}
-
 static void limit_edge_factors(const QuadDice::SubPatch& sub, QuadDice::EdgeFactors& ef, int max_t)
 {
 	float2 P00 = sub.P00;
@@ -147,13 +113,6 @@ static void limit_edge_factors(const QuadDice::SubPatch& sub, QuadDice::EdgeFact
 	float2 P10 = sub.P10;
 	float2 P11 = sub.P11;
 
-	if(sub.patch->is_triangle()) {
-		P00 = right_to_equilateral(P00);
-		P01 = right_to_equilateral(P01);
-		P10 = right_to_equilateral(P10);
-		P11 = right_to_equilateral(P11);
-	}
-
 	int tu0 = int(max_t * len(P10 - P00));
 	int tu1 = int(max_t * len(P11 - P01));
 	int tv0 = int(max_t * len(P01 - P00));
@@ -165,84 +124,6 @@ static void limit_edge_factors(const QuadDice::SubPatch& sub, QuadDice::EdgeFact
 	ef.tv1 = tv1 <= 1 ? 1 : min(ef.tv1, tv1);
 }
 
-void DiagSplit::split(TriangleDice::SubPatch& sub, TriangleDice::EdgeFactors& ef, int depth)
-{
-	if

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list