Blender V2.61 - r43446

subd_dice.h

Go to the documentation of this file.
00001 /*
00002  * Copyright 2011, Blender Foundation.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 #ifndef __SUBD_DICE_H__
00020 #define __SUBD_DICE_H__
00021 
00022 /* DX11 like EdgeDice implementation, with different tesselation factors for
00023  * each edge for watertight tesselation, with subpatch remapping to work with
00024  * DiagSplit. For more algorithm details, see the DiagSplit paper or the
00025  * ARB_tessellation_shader OpenGL extension, Section 2.X.2. */
00026 
00027 #include "util_types.h"
00028 #include "util_vector.h"
00029 
00030 CCL_NAMESPACE_BEGIN
00031 
00032 class Camera;
00033 class Mesh;
00034 class Patch;
00035 
00036 /* EdgeDice Base */
00037 
00038 class EdgeDice {
00039 public:
00040     Camera *camera;
00041     Mesh *mesh;
00042     float3 *mesh_P;
00043     float3 *mesh_N;
00044     float dicing_rate;
00045     size_t vert_offset;
00046     size_t tri_offset;
00047     int shader;
00048     bool smooth;
00049 
00050     EdgeDice(Mesh *mesh, int shader, bool smooth, float dicing_rate);
00051 
00052     void reserve(int num_verts, int num_tris);
00053 
00054     int add_vert(Patch *patch, float2 uv);
00055     void add_triangle(int v0, int v1, int v2);
00056 
00057     void stitch_triangles(vector<int>& outer, vector<int>& inner);
00058 };
00059 
00060 /* Quad EdgeDice
00061  *
00062  * Edge tesselation factors and subpatch coordinates are as follows:
00063  *
00064  *            tu1
00065  *     P01 --------- P11 
00066  *     |               |
00067  * tv0 |               | tv1
00068  *     |               |
00069  *     P00 --------- P10
00070  *            tu0
00071  */
00072 
00073 class QuadDice : public EdgeDice {
00074 public:
00075     struct SubPatch {
00076         Patch *patch;
00077 
00078         float2 P00;
00079         float2 P10;
00080         float2 P01;
00081         float2 P11;
00082     };
00083 
00084     struct EdgeFactors {
00085         int tu0;
00086         int tu1;
00087         int tv0;
00088         int tv1;
00089     };
00090 
00091     QuadDice(Mesh *mesh, int shader, bool smooth, float dicing_rate);
00092 
00093     void reserve(EdgeFactors& ef, int Mu, int Mv);
00094     float3 eval_projected(SubPatch& sub, float u, float v);
00095 
00096     float2 map_uv(SubPatch& sub, float u, float v);
00097     int add_vert(SubPatch& sub, float u, float v);
00098 
00099     void add_corners(SubPatch& sub);
00100     void add_grid(SubPatch& sub, int Mu, int Mv, int offset);
00101 
00102     void add_side_u(SubPatch& sub,
00103         vector<int>& outer, vector<int>& inner,
00104         int Mu, int Mv, int tu, int side, int offset);
00105 
00106     void add_side_v(SubPatch& sub,
00107         vector<int>& outer, vector<int>& inner,
00108         int Mu, int Mv, int tv, int side, int offset);
00109 
00110     float quad_area(const float3& a, const float3& b, const float3& c, const float3& d);
00111     float scale_factor(SubPatch& sub, EdgeFactors& ef, int Mu, int Mv);
00112 
00113     void dice(SubPatch& sub, EdgeFactors& ef);
00114 };
00115 
00116 /* Triangle EdgeDice
00117  *
00118  * Edge tesselation factors and subpatch coordinates are as follows:
00119  *
00120  *        Pw
00121  *        /\
00122  *    tv /  \ tu
00123  *      /    \
00124  *     /      \
00125  *  Pu -------- Pv
00126  *        tw     
00127  */
00128 
00129 class TriangleDice : public EdgeDice {
00130 public:
00131     struct SubPatch {
00132         Patch *patch;
00133 
00134         float2 Pu;
00135         float2 Pv;
00136         float2 Pw;
00137     };
00138 
00139     struct EdgeFactors {
00140         int tu;
00141         int tv;
00142         int tw;
00143     };
00144 
00145     TriangleDice(Mesh *mesh, int shader, bool smooth, float dicing_rate);
00146 
00147     void reserve(EdgeFactors& ef, int M);
00148 
00149     float2 map_uv(SubPatch& sub, float2 uv);
00150     int add_vert(SubPatch& sub, float2 uv);
00151 
00152     void add_grid(SubPatch& sub, EdgeFactors& ef, int M);
00153     void dice(SubPatch& sub, EdgeFactors& ef);
00154 };
00155 
00156 CCL_NAMESPACE_END
00157 
00158 #endif /* __SUBD_DICE_H__ */
00159