Cycles: add ptex face ID and UV attributes.

Not the most memory efficient way to store these things but it's simple and
implementing it better requires some work to natively support subd grids as
a primitive in some way.
This commit is contained in:
Brecht Van Lommel
2013-11-28 01:28:57 +01:00
parent 731ffd3cd4
commit 44d1c92e60
7 changed files with 63 additions and 2 deletions

View File

@@ -34,6 +34,11 @@ EdgeDice::EdgeDice(const SubdParams& params_)
vert_offset = 0;
params.mesh->attributes.add(ATTR_STD_VERTEX_NORMAL);
if(params.ptex) {
params.mesh->attributes.add(ATTR_STD_PTEX_UV);
params.mesh->attributes.add(ATTR_STD_PTEX_FACE_ID);
}
}
void EdgeDice::reserve(int num_verts, int num_tris)
@@ -63,12 +68,29 @@ int EdgeDice::add_vert(Patch *patch, float2 uv)
mesh_P[vert_offset] = P;
mesh_N[vert_offset] = N;
if(params.ptex) {
Attribute *attr_ptex_uv = params.mesh->attributes.add(ATTR_STD_PTEX_UV);
params.mesh->attributes.reserve();
float3 *ptex_uv = attr_ptex_uv->data_float3();
ptex_uv[vert_offset] = make_float3(uv.x, uv.y, 0.0f);
}
return vert_offset++;
}
void EdgeDice::add_triangle(Patch *patch, int v0, int v1, int v2)
{
params.mesh->add_triangle(v0, v1, v2, params.shader, params.smooth);
if(params.ptex) {
Attribute *attr_ptex_face_id = params.mesh->attributes.add(ATTR_STD_PTEX_FACE_ID);
params.mesh->attributes.reserve();
float *ptex_face_id = attr_ptex_face_id->data_float();
ptex_face_id[tri_offset] = (float)patch->ptex_face_id();
}
tri_offset++;
}

View File

@@ -35,17 +35,19 @@ struct SubdParams {
Mesh *mesh;
int shader;
bool smooth;
bool ptex;
int test_steps;
int split_threshold;
float dicing_rate;
Camera *camera;
SubdParams(Mesh *mesh_, int shader_, bool smooth_ = true)
SubdParams(Mesh *mesh_, int shader_, bool smooth_ = true, bool ptex_ = false)
{
mesh = mesh_;
shader = shader_;
smooth = smooth_;
ptex = ptex_;
test_steps = 3;
split_threshold = 1;

View File

@@ -28,6 +28,7 @@ public:
virtual void eval(float3 *P, float3 *dPdu, float3 *dPdv, float u, float v) = 0;
virtual bool is_triangle() { return false; }
virtual BoundBox bound() = 0;
virtual int ptex_face_id() { return -1; }
};
/* Linear Quad Patch */