Skip to content

Commit

Permalink
Fixes for adaptive subdivision. Looks like normal maps on adaptive su…
Browse files Browse the repository at this point in the history
…bdivided meshes doesn't work: https://developer.blender.org/T49159
  • Loading branch information
boberfly committed Mar 30, 2020
1 parent dbddb52 commit c60d2b8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/GafferCycles/CyclesAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ CyclesAttributes::CyclesAttributes( const std::string &name )
attributes->addChild( new Gaffer::NameValuePlug( "ccl:is_shadow_catcher", new IECore::BoolData( false ), false, "isShadowCatcher" ) );

// Subdivision parameters
attributes->addChild( new Gaffer::NameValuePlug( "ccl:max_level", new IECore::IntData( 12 ), false, "maxLevel" ) );
attributes->addChild( new Gaffer::NameValuePlug( "ccl:max_level", new IECore::IntData( 1 ), false, "maxLevel" ) );
attributes->addChild( new Gaffer::NameValuePlug( "ccl:dicing_rate", new IECore::FloatData( 1.0f ), false, "dicingScale" ) );

// Color
Expand Down
19 changes: 17 additions & 2 deletions src/GafferCycles/IECoreCyclesPreview/MeshAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,21 +609,36 @@ ccl::Mesh *convertCommon( const IECoreScene::MeshPrimitive *mesh )

// TODO: Maybe move this to attibutes so it can be shared between meshes?
if( ( subdivision ) && ( cmesh->subdivision_type != ccl::Mesh::SUBDIVISION_NONE ) && ( !cmesh->subd_params ) )
{
cmesh->subd_params = new ccl::SubdParams( cmesh );
cmesh->subd_params->test_steps = 1;
cmesh->subd_params->split_threshold = 1;
cmesh->subd_params->dicing_rate = 1.0f;
cmesh->subd_params->max_level = 1;
cmesh->subd_params->camera = NULL;
}

// Primitive Variables are Attributes in Cycles
ccl::AttributeSet& attributes = (subdivision) ? cmesh->subd_attributes : cmesh->attributes;

// Convert Normals
PrimitiveVariable::Interpolation nInterpolation = PrimitiveVariable::Invalid;
if( !triangles )
if( ( !triangles ) && ( mesh->interpolation() == "catmullClark" ) )
{
if( const V3fVectorData *normals = normal( mesh, nInterpolation ) )
{
ccl::Attribute *attr_N = attributes.add( nInterpolation == PrimitiveVariable::Uniform ? ccl::ATTR_STD_FACE_NORMAL : ccl::ATTR_STD_VERTEX_NORMAL, ccl::ustring("N") );
convertN( mesh, normals, attr_N, nInterpolation );
}
}
else if( !triangles )
{
if( const V3fVectorData *normals = normal( trimesh.get(), nInterpolation ) )
{
ccl::Attribute *attr_N = attributes.add( nInterpolation == PrimitiveVariable::Uniform ? ccl::ATTR_STD_FACE_NORMAL : ccl::ATTR_STD_VERTEX_NORMAL, ccl::ustring("N") );
convertN( trimesh.get(), normals, attr_N, nInterpolation );
}
else if( mesh->interpolation() != "catmullClark" )
else
{
IECoreScene::MeshNormalsOpPtr normalOp = new IECoreScene::MeshNormalsOp();
normalOp->inputParameter()->setValue( trimesh );
Expand Down
2 changes: 1 addition & 1 deletion src/GafferCycles/IECoreCyclesPreview/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ class CyclesAttributes : public IECoreScenePreview::Renderer::AttributesInterfac
m_visibility( ~0 ),
m_useHoldout( false ),
m_isShadowCatcher( false ),
m_maxLevel( 12 ),
m_maxLevel( 1 ),
m_dicingRate( 1.0f ),
m_color( Color3f( 0.0f ) ),
m_dupliGenerated( V3f( 0.0f ) ),
Expand Down

0 comments on commit c60d2b8

Please sign in to comment.