PixarAnimationStudios / OpenSubdiv

An Open-Source subdivision surface library.
graphics.pixar.com/opensubdiv
Other
2.89k stars 561 forks source link

Faceted normal from stencil evaluator #389

Closed nyue closed 9 years ago

nyue commented 9 years ago

Hi,

Using the glStencilViewer as a starting point, I modified it to printout the limit surface position and it's normal.

            float * p      = ptr,
                * utan   = ptr + 3,
                * vtan   = ptr + 9,
                * normal = ptr + 15;

            // copy P as starting point for each line
            memcpy( ptr +  6, p, 3*sizeof(float) );
            memcpy( ptr + 12, p, 3*sizeof(float) );

            normalize( utan );
            normalize( vtan );
            cross( normal, utan, vtan );

            normalize(normal);
            printf("%f,%f,%f,%f,%f,%f\n",p[0],p[1],p[2],normal[0],normal[1],normal[2]);

When I visualize them, the look faceted.

Is that to be expected or have I missed out implementing normal handling in the Vertex struct ?

facetednormals

Cheers

manuelk commented 9 years ago

The vertex struct doesn't require anything special for normals - couple of questions:

nyue commented 9 years ago

The normals are not identical but visually the seems more 'aligned' in groups so I thought it might be related to normals not being interpolated within each ptex face.

Here is the raw csv file I dump out, you can use Houdini table import on the file

https://dl.dropboxusercontent.com/u/21295005/PixarOpenSubdiv/default.csv

The refiner is uniform (I adapted the code from glStencilViewer)

            // Instantiate a FarTopologyRefiner from the descriptor
            this->_refiner =
                OpenSubdiv::Far::TopologyRefinerFactory<Descriptor>::Create(desc,
                                                                            OpenSubdiv::Far::TopologyRefinerFactory<Descriptor>::Options(i_type, options));

            // Uniformly refine the topolgy up to 'maxlevel'
            // note: fullTopologyInLastLevel must be true to work with face-varying data
            {
                OpenSubdiv::Far::TopologyRefiner::UniformOptions options(i_maxlevel);
                options.fullTopologyInLastLevel = true;
                this->_refiner->RefineUniform(options);
            }

How do I enable bi-cubic stencil ? or how do I enable or ensure there are patch-tables ?

Meanwhile, I'll poke around for the information.

Cheers

nyue commented 9 years ago

Answering my own question, I have now implemented the code closer to the glStencilViewer example and the visual faceting is not there anymore

            // note: fullTopologyInLastLevel must be true to work with face-varying data
            if (this->_bilinear)
            {
                OpenSubdiv::Far::TopologyRefiner::UniformOptions options(i_maxlevel);
                options.fullTopologyInLastLevel = true;
                this->_refiner->RefineUniform(options);
            }
            else
            {
                OpenSubdiv::Far::TopologyRefiner::AdaptiveOptions options(i_maxlevel);
                options.fullTopologyInLastLevel = true;
                options.useSingleCreasePatch = false;
                this->_refiner->RefineAdaptive(options);
            }

Thanks for the observation Manuel.

Cheers

manuelk commented 9 years ago

So the stencils were in "bilinear" mode then - glad you were able to figure this out. I just looked at the stencil tutorial, which does the same uniform refinement. I'll try to add a few comments in there or spin an adaptive tutorial to show how to get proper limit stencils. We really need to flesh out this documentation...

Otherwise : ok to close this as resolved ?

nyue commented 9 years ago

Yes, please close as resolved.