Merge pull request #479 from davidgyu/evalfix1

Fixed example code use of single crease patches
This commit is contained in:
Takahito Tejima 2015-05-15 15:45:04 -07:00
commit ffc7678e1c
9 changed files with 64 additions and 37 deletions

View File

@ -440,7 +440,11 @@ getAdaptivePatchColor(int3 patchParam, float sharpness)
};
int patchType = 0;
#if defined OSD_PATCH_GREGORY
#if defined OSD_PATCH_ENABLE_SINGLE_CREASE
if (sharpness > 0) {
pattern = 1;
}
#elif defined OSD_PATCH_GREGORY
patchType = 4;
#elif defined OSD_PATCH_GREGORY_BOUNDARY
patchType = 5;
@ -457,9 +461,6 @@ getAdaptivePatchColor(int3 patchParam, float sharpness)
}
int pattern = countbits(OsdGetPatchTransitionMask(patchParam));
#ifdef OSD_PATCH_ENABLE_SINGLE_CREASE
if (sharpness > 0) pattern += 6;
#endif
return patchColors[6*patchType + pattern];
}

View File

@ -421,11 +421,12 @@ fitFrame() {
//------------------------------------------------------------------------------
union Effect {
Effect(int displayStyle_, int screenSpaceTess_, int fractionalSpacing_, int patchCull_) : value(0) {
Effect(int displayStyle_, int screenSpaceTess_, int fractionalSpacing_, int patchCull_, int singleCreasePatch_) : value(0) {
displayStyle = displayStyle_;
screenSpaceTess = screenSpaceTess_;
fractionalSpacing = fractionalSpacing_;
patchCull = patchCull_;
singleCreasePatch = singleCreasePatch_;
}
struct {
@ -433,6 +434,7 @@ union Effect {
unsigned int screenSpaceTess:1;
unsigned int fractionalSpacing:1;
unsigned int patchCull:1;
unsigned int singleCreasePatch:1;
};
int value;
@ -452,9 +454,11 @@ struct EffectDesc {
int numElements;
bool operator < (const EffectDesc &e) const {
return desc < e.desc || (desc == e.desc &&
return
(desc < e.desc || ((desc == e.desc &&
(maxValence < e.maxValence || ((maxValence == e.maxValence) &&
(effect < e.effect))));
(numElements < e.numElements || ((numElements == e.numElements) &&
(effect < e.effect))))))));
}
};
@ -464,7 +468,8 @@ GetEffect()
return Effect(g_displayStyle,
g_screenSpaceTess,
g_fractionalSpacing,
g_patchCull);
g_patchCull,
g_singleCreasePatch);
}
// ---------------------------------------------------------------------------
@ -497,7 +502,7 @@ public:
if (effectDesc.effect.patchCull) {
ss << "#define OSD_ENABLE_PATCH_CULL\n";
}
if (g_singleCreasePatch) {
if (effectDesc.effect.singleCreasePatch) {
ss << "#define OSD_PATCH_ENABLE_SINGLE_CREASE\n";
}
// for legacy gregory
@ -610,14 +615,18 @@ bindProgram(Effect effect, OpenSubdiv::Osd::DrawContext::PatchArray const & patc
EffectDesc effectDesc(patch.GetDescriptor(), effect);
// only legacy gregory needs maxValence and numElements
int maxValence = g_mesh->GetDrawContext()->GetMaxValence();
int numElements = 6;
// neither legacy gregory nor gregory basis need single crease
typedef OpenSubdiv::Far::PatchDescriptor Descriptor;
if (patch.GetDescriptor().GetType() == Descriptor::GREGORY or
patch.GetDescriptor().GetType() == Descriptor::GREGORY_BOUNDARY) {
int maxValence = g_mesh->GetDrawContext()->GetMaxValence();
int numElements = 6;
effectDesc.maxValence = maxValence;
effectDesc.numElements = numElements;
effectDesc.effect.singleCreasePatch = 0;
}
if (patch.GetDescriptor().GetType() == Descriptor::GREGORY_BASIS) {
effectDesc.effect.singleCreasePatch = 0;
}
D3D11DrawConfig *config = g_shaderCache.GetDrawConfig(effectDesc);
@ -1141,7 +1150,7 @@ initHUD() {
g_hud->AddCheckBox("Frustum Patch Culling (B)", g_patchCull != 0, 10, 150, callbackCheckBox, kHUD_CB_PATCH_CULL, 'B');
g_hud->AddCheckBox("Adaptive (`)", true, 10, 190, callbackAdaptive, 0, '`');
g_hud->AddCheckBox("Single Crease Patch (S)", g_singleCreasePatch!=0, 10, 210, callbackSingleCreasePatch, 0, 's');
g_hud->AddCheckBox("Single Crease Patch (S)", g_singleCreasePatch!=0, 10, 210, callbackSingleCreasePatch, 0, 'S');
for (int i = 1; i < 11; ++i) {
char level[16];

View File

@ -402,7 +402,11 @@ getAdaptivePatchColor(int3 patchParam, float sharpness)
};
int patchType = 0;
#if defined OSD_PATCH_GREGORY
#if defined OSD_PATCH_ENABLE_SINGLE_CREASE
if (sharpness > 0) {
patchType = 1;
}
#elif defined OSD_PATCH_GREGORY
patchType = 4;
#elif defined OSD_PATCH_GREGORY_BOUNDARY
patchType = 5;
@ -419,9 +423,6 @@ getAdaptivePatchColor(int3 patchParam, float sharpness)
}
int pattern = countbits(OsdGetPatchTransitionMask(patchParam));
#ifdef OSD_PATCH_ENABLE_SINGLE_CREASE
if (sharpness > 0) pattern += 6;
#endif
return patchColors[6*patchType + pattern];
}

View File

@ -467,7 +467,9 @@ GetOverrideColor(ivec3 patchParam)
int patchType = 0;
#if defined OSD_PATCH_SINGLE_CREASE
if (inpt.sharpness > 0) {
patchType = 1;
}
#elif defined OSD_PATCH_GREGORY
patchType = 4;
#elif defined OSD_PATCH_GREGORY_BOUNDARY
@ -475,6 +477,7 @@ GetOverrideColor(ivec3 patchParam)
#elif defined OSD_PATCH_GREGORY_BASIS
patchType = 6;
#endif
int edgeCount = bitCount(OsdGetPatchBoundaryMask(patchParam));
if (edgeCount == 1) {
patchType = 2; // BOUNDARY
@ -482,9 +485,10 @@ GetOverrideColor(ivec3 patchParam)
if (edgeCount == 2) {
patchType = 3; // CORNER
}
int pattern = bitCount(OsdGetPatchTransitionMask(patchParam));
int offset = 6*patchType + pattern;
return patchColors[offset];
return patchColors[6*patchType + pattern];
}
#endif

View File

@ -783,11 +783,12 @@ drawCageVertices() {
//------------------------------------------------------------------------------
union Effect {
Effect(int displayStyle_, int screenSpaceTess_, int fractionalSpacing_, int patchCull_) : value(0) {
Effect(int displayStyle_, int screenSpaceTess_, int fractionalSpacing_, int patchCull_, int singleCreasePatch_) : value(0) {
displayStyle = displayStyle_;
screenSpaceTess = screenSpaceTess_;
fractionalSpacing = fractionalSpacing_;
patchCull = patchCull_;
singleCreasePatch = singleCreasePatch_;
}
struct {
@ -795,6 +796,7 @@ union Effect {
unsigned int screenSpaceTess:1;
unsigned int fractionalSpacing:1;
unsigned int patchCull:1;
unsigned int singleCreasePatch:1;
};
int value;
@ -809,7 +811,8 @@ GetEffect()
return Effect(g_displayStyle,
g_screenSpaceTess,
g_fractionalSpacing,
g_patchCull);
g_patchCull,
g_singleCreasePatch);
}
// ---------------------------------------------------------------------------
@ -825,9 +828,11 @@ struct EffectDesc {
int numElements;
bool operator < (const EffectDesc &e) const {
return desc < e.desc || (desc == e.desc &&
return
(desc < e.desc || ((desc == e.desc &&
(maxValence < e.maxValence || ((maxValence == e.maxValence) &&
(effect < e.effect))));
(numElements < e.numElements || ((numElements == e.numElements) &&
(effect < e.effect))))))));
}
};
@ -868,7 +873,7 @@ public:
if (effectDesc.effect.patchCull) {
ss << "#define OSD_ENABLE_PATCH_CULL\n";
}
if (g_singleCreasePatch) {
if (effectDesc.effect.singleCreasePatch) {
ss << "#define OSD_PATCH_ENABLE_SINGLE_CREASE\n";
}
// for legacy gregory
@ -1117,6 +1122,7 @@ bindProgram(Effect effect,
EffectDesc effectDesc(patch.GetDescriptor(), effect);
// only legacy gregory needs maxValence and numElements
// neither legacy gregory nor gregory basis need single crease
typedef OpenSubdiv::Far::PatchDescriptor Descriptor;
if (patch.GetDescriptor().GetType() == Descriptor::GREGORY or
patch.GetDescriptor().GetType() == Descriptor::GREGORY_BOUNDARY) {
@ -1124,6 +1130,10 @@ bindProgram(Effect effect,
int numElements = (g_displayStyle == kInterleavedVaryingColor ? 7 : 3);
effectDesc.maxValence = maxValence;
effectDesc.numElements = numElements;
effectDesc.effect.singleCreasePatch = 0;
}
if (patch.GetDescriptor().GetType() == Descriptor::GREGORY_BASIS) {
effectDesc.effect.singleCreasePatch = 0;
}
// lookup shader cache (compile the shader if needed)

View File

@ -442,7 +442,11 @@ getAdaptivePatchColor(ivec3 patchParam)
);
int patchType = 0;
#if defined OSD_PATCH_GREGORY
#if defined OSD_PATCH_ENABLE_SINGLE_CREASE
if (inpt.sharpness > 0) {
patchType = 1;
}
#elif defined OSD_PATCH_GREGORY
patchType = 4;
#elif defined OSD_PATCH_GREGORY_BOUNDARY
patchType = 5;
@ -459,9 +463,6 @@ getAdaptivePatchColor(ivec3 patchParam)
}
int pattern = bitCount(OsdGetPatchTransitionMask(patchParam));
#ifdef OSD_PATCH_ENABLE_SINGLE_CREASE
if (inpt.sharpness > 0) pattern += 6;
#endif
return patchColors[6*patchType + pattern];
}

View File

@ -392,7 +392,7 @@ void main()
OSD_DISPLACEMENT_CALLBACK;
gl_Position = (OsdProjectionMatrix() * vec4(WorldPos, 1.0f));
gl_Position = OsdProjectionMatrix() * outpt.v.position;
}
#endif

View File

@ -614,9 +614,10 @@ void main()
outpt.v.tangent = BiTangent;
outpt.v.bitangent = Tangent;
OSD_USER_VARYING_PER_EVAL_POINT(vec2(u,v), 0, 3, 1, 2);
vec2 UV = vec2(v, u);
OSD_USER_VARYING_PER_EVAL_POINT(UV, 0, 1, 3, 2);
outpt.v.tessCoord = UV;
outpt.v.patchCoord = OsdInterpolatePatchCoord(UV, inpt[0].v.patchCoord);

View File

@ -262,10 +262,10 @@ void main()
outpt.v.tangent = BiTangent;
outpt.v.bitangent = Tangent;
//OSD_USER_VARYING_PER_EVAL_POINT(vec2(u,v), 0, 3, 1, 2);
OSD_USER_VARYING_PER_EVAL_POINT(vec2(u,v), 0, 15, 5, 10);
vec2 UV = vec2(v, u);
OSD_USER_VARYING_PER_EVAL_POINT(UV, 0, 5, 15, 10);
outpt.v.tessCoord = UV;
outpt.v.patchCoord = OsdInterpolatePatchCoord(UV, inpt[0].v.patchCoord);