diff --git a/examples/dxPtexViewer/shader.hlsl b/examples/dxPtexViewer/shader.hlsl index 987cb212..a2983d00 100644 --- a/examples/dxPtexViewer/shader.hlsl +++ b/examples/dxPtexViewer/shader.hlsl @@ -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]; } diff --git a/examples/dxViewer/dxviewer.cpp b/examples/dxViewer/dxviewer.cpp index 2100984f..2a2cb4c3 100644 --- a/examples/dxViewer/dxviewer.cpp +++ b/examples/dxViewer/dxviewer.cpp @@ -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 && - (maxValence < e.maxValence || ((maxValence == e.maxValence) && - (effect < e.effect)))); + return + (desc < e.desc || ((desc == e.desc && + (maxValence < e.maxValence || ((maxValence == e.maxValence) && + (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]; diff --git a/examples/dxViewer/shader.hlsl b/examples/dxViewer/shader.hlsl index 38543b5d..bed51c93 100644 --- a/examples/dxViewer/shader.hlsl +++ b/examples/dxViewer/shader.hlsl @@ -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]; } diff --git a/examples/glPtexViewer/shader.glsl b/examples/glPtexViewer/shader.glsl index 9cec2d0c..c9fab571 100644 --- a/examples/glPtexViewer/shader.glsl +++ b/examples/glPtexViewer/shader.glsl @@ -467,7 +467,9 @@ GetOverrideColor(ivec3 patchParam) int patchType = 0; #if defined OSD_PATCH_SINGLE_CREASE - patchType = 1; + 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 diff --git a/examples/glViewer/glViewer.cpp b/examples/glViewer/glViewer.cpp index 14876b22..92af6cc7 100644 --- a/examples/glViewer/glViewer.cpp +++ b/examples/glViewer/glViewer.cpp @@ -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 && - (maxValence < e.maxValence || ((maxValence == e.maxValence) && - (effect < e.effect)))); + return + (desc < e.desc || ((desc == e.desc && + (maxValence < e.maxValence || ((maxValence == e.maxValence) && + (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) diff --git a/examples/glViewer/shader.glsl b/examples/glViewer/shader.glsl index 83fd90fa..fb1b27ee 100644 --- a/examples/glViewer/shader.glsl +++ b/examples/glViewer/shader.glsl @@ -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]; } diff --git a/opensubdiv/osd/glslPatchBSpline.glsl b/opensubdiv/osd/glslPatchBSpline.glsl index ccba7563..cdb84244 100644 --- a/opensubdiv/osd/glslPatchBSpline.glsl +++ b/opensubdiv/osd/glslPatchBSpline.glsl @@ -392,7 +392,7 @@ void main() OSD_DISPLACEMENT_CALLBACK; - gl_Position = (OsdProjectionMatrix() * vec4(WorldPos, 1.0f)); + gl_Position = OsdProjectionMatrix() * outpt.v.position; } #endif diff --git a/opensubdiv/osd/glslPatchGregory.glsl b/opensubdiv/osd/glslPatchGregory.glsl index cf60aae1..80439b8e 100644 --- a/opensubdiv/osd/glslPatchGregory.glsl +++ b/opensubdiv/osd/glslPatchGregory.glsl @@ -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); diff --git a/opensubdiv/osd/glslPatchGregoryBasis.glsl b/opensubdiv/osd/glslPatchGregoryBasis.glsl index bf68540c..92b81d5f 100644 --- a/opensubdiv/osd/glslPatchGregoryBasis.glsl +++ b/opensubdiv/osd/glslPatchGregoryBasis.glsl @@ -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);