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

subd_dice.h « subd « cycles « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 71879f1f5f1d3fc6681f6b0af3f8179e1fdaba80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
 * Copyright 2011, Blender Foundation.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#ifndef __SUBD_DICE_H__
#define __SUBD_DICE_H__

/* DX11 like EdgeDice implementation, with different tesselation factors for
 * each edge for watertight tesselation, with subpatch remapping to work with
 * DiagSplit. For more algorithm details, see the DiagSplit paper or the
 * ARB_tessellation_shader OpenGL extension, Section 2.X.2. */

#include "util_types.h"
#include "util_vector.h"

CCL_NAMESPACE_BEGIN

class Camera;
class Mesh;
class Patch;

/* EdgeDice Base */

class EdgeDice {
public:
	Camera *camera;
	Mesh *mesh;
	float3 *mesh_P;
	float3 *mesh_N;
	float dicing_rate;
	size_t vert_offset;
	size_t tri_offset;
	int shader;
	bool smooth;

	EdgeDice(Mesh *mesh, int shader, bool smooth, float dicing_rate);

	void reserve(int num_verts, int num_tris);

	int add_vert(Patch *patch, float2 uv);
	void add_triangle(int v0, int v1, int v2);

	void stitch_triangles(vector<int>& outer, vector<int>& inner);
};

/* Quad EdgeDice
 *
 * Edge tesselation factors and subpatch coordinates are as follows:
 *
 *            tu1
 *     P01 --------- P11 
 *     |               |
 * tv0 |               | tv1
 *     |               |
 *     P00 --------- P10
 *            tu0
 */

class QuadDice : public EdgeDice {
public:
	struct SubPatch {
		Patch *patch;

		float2 P00;
		float2 P10;
		float2 P01;
		float2 P11;
	};

	struct EdgeFactors {
		int tu0;
		int tu1;
		int tv0;
		int tv1;
	};

	QuadDice(Mesh *mesh, int shader, bool smooth, float dicing_rate);

	void reserve(EdgeFactors& ef, int Mu, int Mv);
	float3 eval_projected(SubPatch& sub, float u, float v);

	float2 map_uv(SubPatch& sub, float u, float v);
	int add_vert(SubPatch& sub, float u, float v);

	void add_corners(SubPatch& sub);
	void add_grid(SubPatch& sub, int Mu, int Mv, int offset);

	void add_side_u(SubPatch& sub,
		vector<int>& outer, vector<int>& inner,
		int Mu, int Mv, int tu, int side, int offset);

	void add_side_v(SubPatch& sub,
		vector<int>& outer, vector<int>& inner,
		int Mu, int Mv, int tv, int side, int offset);

	float quad_area(const float3& a, const float3& b, const float3& c, const float3& d);
	float scale_factor(SubPatch& sub, EdgeFactors& ef, int Mu, int Mv);

	void dice(SubPatch& sub, EdgeFactors& ef);
};

/* Triangle EdgeDice
 *
 * Edge tesselation 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;
	};

	TriangleDice(Mesh *mesh, int shader, bool smooth, float dicing_rate);

	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__ */