Fix stencil tangents incorrect magnitude scale

The tangents were only scaled in the "bail-out" code branch that
pushes vertices to the limit and performs bi-linear interpolation.

Now we are also scaling the bi-cubic patch interpolation code branch.

There may be another code path left to fix (as well as some pointers
being currently unchecked)

fixes #243
This commit is contained in:
manuelk 2013-12-02 19:07:09 -08:00
parent ee26835d47
commit d9562164f7

View File

@ -653,6 +653,13 @@ private:
// Updates the cached BSpline stencils // Updates the cached BSpline stencils
void _UpdateBSplineStencils( HbrFace<T> const * f ); void _UpdateBSplineStencils( HbrFace<T> const * f );
// Scale tangent stencils so that magnitudes are consistent across
// isolation levels.
static void _ScaleTangentStencil( HbrFace<T> const * f,
int stencilsize,
float *uderiv,
float *vderiv );
// Computes BSpline stencil weights at (u,v) // Computes BSpline stencil weights at (u,v)
void _GetBSplineStencilsAtUV( float u, void _GetBSplineStencilsAtUV( float u,
float v, float v,
@ -1335,6 +1342,7 @@ FarStencilTablesFactory<T>::Patch::_GetBSplineStencilsAtUV( float u,
} }
FarVertexStencil::AddScaled(deriv2, _bsplineStencils[12+j], prevWeight); FarVertexStencil::AddScaled(deriv2, _bsplineStencils[12+j], prevWeight);
} }
_ScaleTangentStencil(_bsplineFace, GetStencilSize(), deriv1, deriv2);
} }
} }
@ -1471,6 +1479,19 @@ FarStencilTablesFactory<T>::Patch::_GetLimitStencils( HbrVertex<T> * v,
} }
} }
// Scale tangent stencils so that magnitudes are consistent across
// isolation levels.
template <class T> void
FarStencilTablesFactory<T>::Patch::_ScaleTangentStencil( HbrFace<T> const * f,
int stencilsize,
float *uderiv,
float *vderiv ) {
float scale = float (1 << f->GetDepth());
FarVertexStencil::Scale(uderiv, scale, stencilsize);
FarVertexStencil::Scale(vderiv, scale, stencilsize);
}
// Computes derivative limit stencils // Computes derivative limit stencils
template <class T> void template <class T> void
@ -1689,10 +1710,7 @@ FarStencilTablesFactory<T>::Patch::_GetTangentLimitStencils( HbrHalfedge<T> * e,
} break; } break;
} }
// Scale tangent stencils so that magnitudes are consistent across levels. _ScaleTangentStencil(e->GetFace(), GetStencilSize(), uderiv, vderiv);
float scale = float (1 << e->GetLeftFace()->GetDepth());
FarVertexStencil::Scale(uderiv, scale, GetStencilSize());
FarVertexStencil::Scale(vderiv, scale, GetStencilSize());
} }
} // end namespace OPENSUBDIV_VERSION } // end namespace OPENSUBDIV_VERSION