mirror of
https://github.com/PixarAnimationStudios/OpenSubdiv
synced 2024-12-25 01:01:15 +00:00
Fix a bug of bad fvar splicing for loop surface.
This commit is contained in:
parent
c018aa1fc6
commit
d44724c5b7
@ -149,6 +149,9 @@ MyDrawDelegate::DrawElements(OpenSubdiv::OsdDrawContext::PatchArray const &patch
|
||||
if (patchArray.GetDescriptor().GetType() == OpenSubdiv::FarPatchTables::QUADS) {
|
||||
glDrawElements(GL_LINES_ADJACENCY, patchArray.GetNumIndices(), GL_UNSIGNED_INT,
|
||||
(void*)(patchArray.GetVertIndex()*sizeof(GLuint)));
|
||||
} else if (patchArray.GetDescriptor().GetType() == OpenSubdiv::FarPatchTables::TRIANGLES) {
|
||||
glDrawElements(GL_TRIANGLES, patchArray.GetNumIndices(), GL_UNSIGNED_INT,
|
||||
(void*)(patchArray.GetVertIndex()*sizeof(GLuint)));
|
||||
} else {
|
||||
#if defined(GL_ARB_tessellation_shader) || defined(GL_VERSION_4_0)
|
||||
glDrawElements(GL_PATCHES, patchArray.GetNumIndices(), GL_UNSIGNED_INT,
|
||||
|
@ -141,8 +141,13 @@ MyEffect::BindDrawConfig(MyDrawConfig *config, OpenSubdiv::OsdDrawContext::Patch
|
||||
GLint diffuseColor = config->diffuseColorUniform;
|
||||
|
||||
if (displayPatchColor) {
|
||||
float const * color = getAdaptivePatchColor( desc );
|
||||
glProgramUniform4f(program, diffuseColor, color[0], color[1], color[2], color[3]);
|
||||
if (desc.GetType() == OpenSubdiv::FarPatchTables::QUADS or
|
||||
desc.GetType() == OpenSubdiv::FarPatchTables::TRIANGLES) {
|
||||
glProgramUniform4f(program, diffuseColor, 0.4f, 0.4f, 0.8f, 1);
|
||||
} else {
|
||||
const float *color = getAdaptivePatchColor( desc );
|
||||
glProgramUniform4f(program, diffuseColor, color[0], color[1], color[2], color[3]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -51,7 +51,8 @@ MyEffectRegistry::_CreateDrawSourceConfig(DescType const & desc) {
|
||||
}
|
||||
|
||||
const char *glslVersion = "#version 400\n";
|
||||
if (desc.first.GetType() == OpenSubdiv::FarPatchTables::QUADS) {
|
||||
if (desc.first.GetType() == OpenSubdiv::FarPatchTables::QUADS or
|
||||
desc.first.GetType() == OpenSubdiv::FarPatchTables::TRIANGLES) {
|
||||
sconfig->vertexShader.source = shaderSource;
|
||||
sconfig->vertexShader.version = glslVersion;
|
||||
sconfig->vertexShader.AddDefine("VERTEX_SHADER");
|
||||
@ -76,6 +77,7 @@ MyEffectRegistry::_CreateDrawSourceConfig(DescType const & desc) {
|
||||
// uniform loop
|
||||
sconfig->geometryShader.AddDefine("PRIM_TRI");
|
||||
sconfig->fragmentShader.AddDefine("PRIM_TRI");
|
||||
sconfig->commonShader.AddDefine("LOOP");
|
||||
sconfig->commonShader.AddDefine("UNIFORM_SUBDIVISION");
|
||||
} else {
|
||||
// adaptive
|
||||
|
@ -126,6 +126,12 @@ void emit(int index, vec3 normal)
|
||||
#endif
|
||||
|
||||
#ifdef FACEVARYING_COLOR
|
||||
#ifdef LOOP // ----- scheme : LOOP
|
||||
vec2 uv;
|
||||
OSD_COMPUTE_FACE_VARYING_TRI_2(uv, /*fvarOffste=*/0, index);
|
||||
|
||||
#else // ----- scheme : CATMARK / BILINEAR
|
||||
|
||||
#ifdef UNIFORM_SUBDIVISION
|
||||
vec2 quadst[4] = vec2[](vec2(0,0), vec2(1,0), vec2(1,1), vec2(0,1));
|
||||
vec2 st = quadst[index];
|
||||
@ -134,6 +140,7 @@ void emit(int index, vec3 normal)
|
||||
#endif
|
||||
vec2 uv;
|
||||
OSD_COMPUTE_FACE_VARYING_2(uv, /*fvarOffset=*/0, st);
|
||||
#endif // ------ scheme
|
||||
outpt.color = vec3(uv.s, uv.t, 0);
|
||||
#endif
|
||||
|
||||
@ -283,7 +290,7 @@ lighting(vec4 diffuse, vec3 Peye, vec3 Neye)
|
||||
float d = max(0.0, dot(n, l));
|
||||
float s = pow(max(0.0, dot(n, h)), 500.0f);
|
||||
|
||||
color += lightSource[i].ambient * ambientColor
|
||||
color += lightSource[i].ambient * diffuse * ambientColor
|
||||
+ d * lightSource[i].diffuse * diffuse
|
||||
+ s * lightSource[i].specular;
|
||||
}
|
||||
|
@ -137,7 +137,6 @@ void initializeShapes( ) {
|
||||
g_defaultShapes.push_back(SimpleShape(bilinear_cube, "bilinear_cube", kBilinear));
|
||||
|
||||
|
||||
/*
|
||||
#include <shapes/loop_cube_creases0.h>
|
||||
g_defaultShapes.push_back(SimpleShape(loop_cube_creases0, "loop_cube_creases0", kLoop));
|
||||
|
||||
@ -161,5 +160,4 @@ void initializeShapes( ) {
|
||||
|
||||
#include <shapes/loop_triangle_edgeonly.h>
|
||||
g_defaultShapes.push_back(SimpleShape(loop_triangle_edgeonly, "loop_triangle_edgeonly", kLoop));
|
||||
*/
|
||||
}
|
||||
|
@ -418,12 +418,17 @@ rebuild()
|
||||
for (int i = 0; i < g_modelCount*g_modelCount; ++i) {
|
||||
g_vertexOffsets.push_back(vertexOffset);
|
||||
|
||||
while (g_defaultShapes[shape].scheme != scheme) {
|
||||
++shape;
|
||||
if (shape >= (int)g_defaultShapes.size()) shape = 0;
|
||||
}
|
||||
|
||||
OpenSubdiv::FarMesh<OpenSubdiv::OsdVertex> *farMesh = createFarMesh(
|
||||
g_defaultShapes[ shape ].data.c_str(), g_level, adaptive, scheme);
|
||||
farMeshes.push_back(farMesh);
|
||||
|
||||
vertexOffset += farMesh->GetNumVertices();
|
||||
shape++;
|
||||
++shape;
|
||||
if (shape >= (int)g_defaultShapes.size()) shape = 0;
|
||||
}
|
||||
|
||||
|
@ -89,6 +89,7 @@ private:
|
||||
|
||||
int _maxlevel;
|
||||
int _maxvalence;
|
||||
bool _isLoop;
|
||||
|
||||
// patch arrays for each mesh
|
||||
std::vector<FarPatchTables::PatchArrayVector> _multiPatchArrays;
|
||||
@ -104,6 +105,7 @@ FarMultiMeshFactory<T, U>::Create(std::vector<FarMesh<U> const *> const &meshes)
|
||||
const std::type_info &scheme = typeid(*(meshes[0]->GetSubdivisionTables()));
|
||||
_maxlevel = 0;
|
||||
_maxvalence = 0;
|
||||
_isLoop = false;
|
||||
|
||||
for (size_t i = 0; i < meshes.size(); ++i) {
|
||||
FarMesh<U> const *mesh = meshes[i];
|
||||
@ -244,10 +246,13 @@ FarMultiMeshFactory<T, U>::spliceSubdivisionTables(FarMesh<U> *farMesh, FarMeshV
|
||||
|
||||
if (scheme == typeid(FarCatmarkSubdivisionTables<U>) ) {
|
||||
result = new FarCatmarkSubdivisionTables<U>(farMesh, _maxlevel);
|
||||
_isLoop = false;
|
||||
} else if (scheme == typeid(FarBilinearSubdivisionTables<U>) ) {
|
||||
result = new FarBilinearSubdivisionTables<U>(farMesh, _maxlevel);
|
||||
_isLoop = false;
|
||||
} else if (scheme == typeid(FarLoopSubdivisionTables<U>) ) {
|
||||
result = new FarLoopSubdivisionTables<U>(farMesh, _maxlevel);
|
||||
_isLoop = true;
|
||||
}
|
||||
|
||||
result->_F_ITa.resize(total_F_ITa);
|
||||
@ -569,7 +574,8 @@ FarMultiMeshFactory<T, U>::splicePatchTables(FarMeshVector const &meshes, bool h
|
||||
FarPatchTables const *ptables = meshes[i]->GetPatchTables();
|
||||
FarPatchTables::PatchArray const *parray = ptables->GetPatchArray(*it);
|
||||
if (parray) {
|
||||
int width = meshes[i]->GetTotalFVarWidth() * 4; // for each quad
|
||||
int nv = _isLoop ? 3 : 4;
|
||||
int width = meshes[i]->GetTotalFVarWidth() * nv; // for each quads or tris
|
||||
FarPatchTables::FVarDataTable::const_iterator begin =
|
||||
ptables->_fvarTable.begin() + parray->GetPatchIndex() * width;
|
||||
FarPatchTables::FVarDataTable::const_iterator end =
|
||||
|
Loading…
Reference in New Issue
Block a user