Skip to content

Commit

Permalink
[spline/bezier]Add some comments and fix to avoid division, use multi…
Browse files Browse the repository at this point in the history
…ply instead.
  • Loading branch information
xebra authored and hrydgard committed Jan 23, 2017
1 parent 7530e35 commit 54a2dcd
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions GPU/Common/SplineCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,22 +223,24 @@ static void spline_knot(int n, int type, float *knot) {
}
}

// Prepare mesh of one patch for "Instanced Tessellation".
static void TessellateSplinePatchHardware(u8 *&dest, u16 *indices, int &count, const SplinePatchLocal &spatch) {
SimpleVertex *&vertices = (SimpleVertex*&)dest;

float inv_u = 1.0f / (float)spatch.tess_u;
float inv_v = 1.0f / (float)spatch.tess_v;

// Generating simple input vertices for the spline-computing vertex shader.
for (int tile_v = 0; tile_v < spatch.tess_v + 1; ++tile_v) {
for (int tile_u = 0; tile_u < spatch.tess_u + 1; ++tile_u) {
float u = ((float)tile_u / (float)spatch.tess_u);
float v = ((float)tile_v / (float)spatch.tess_v);

SimpleVertex &vert = vertices[tile_v * (spatch.tess_u + 1) + tile_u];
vert.pos.x = (float)tile_u * inv_u;
vert.pos.y = (float)tile_v * inv_v;

vert.pos.x = u;
vert.pos.y = v;

// TODO: Move to shader uniform and unify this method spline and bezier if necessary.
// For compute normal
vert.nrm.x = 1.0f / (float)spatch.tess_u;
vert.nrm.y = 1.0f / (float)spatch.tess_v;
vert.nrm.x = inv_u;
vert.nrm.y = inv_v;
}
}

Expand Down Expand Up @@ -800,18 +802,20 @@ static void _BezierPatchHighQuality(u8 *&dest, u16 *&indices, int &count, int te
dest += (tess_u + 1) * (tess_v + 1) * sizeof(SimpleVertex);
}

// Prepare mesh of one patch for "Instanced Tessellation".
static void TesselateBezierPatchHardware(u8 *&dest, u16 *indices, int &count, int tess_u, int tess_v, GEPatchPrimType primType) {
SimpleVertex *&vertices = (SimpleVertex*&)dest;

float inv_u = 1.0f / (float)tess_u;
float inv_v = 1.0f / (float)tess_v;

// Generating simple input vertices for the bezier-computing vertex shader.
for (int tile_v = 0; tile_v < tess_v + 1; ++tile_v) {
for (int tile_u = 0; tile_u < tess_u + 1; ++tile_u) {
float u = ((float)tile_u / (float)tess_u);
float v = ((float)tile_v / (float)tess_v);

SimpleVertex &vert = vertices[tile_v * (tess_u + 1) + tile_u];

vert.pos.x = u;
vert.pos.y = v;
vert.pos.x = (float)tile_u * inv_u;
vert.pos.y = (float)tile_v * inv_v;
}
}

Expand Down

0 comments on commit 54a2dcd

Please sign in to comment.