コード例 #1
0
IECore::ObjectVectorPtr AppleseedLight::computeLight( const Gaffer::Context *context ) const
{
	IECoreScene::ShaderPtr result = new IECoreScene::Shader( modelPlug()->getValue(), "as:light" );
	for( InputValuePlugIterator it( parametersPlug() ); !it.done(); ++it )
	{
		result->parameters()[(*it)->getName()] = CompoundDataPlug::extractDataFromPlug( it->get() );
	}

	IECore::ObjectVectorPtr resultVector = new IECore::ObjectVector();
	resultVector->members().push_back( result );
	return resultVector;
}
コード例 #2
0
ファイル: Shader.cpp プロジェクト: appleseedhq/gaffer
		IECore::InternedString handle( const Shader *shaderNode )
		{
			assert( shaderNode );
			assert( shaderNode->enabledPlug()->getValue() );

			CycleDetector cycleDetector( m_downstreamShaders, shaderNode );

			HandleAndHash &handleAndHash = m_shaders[shaderNode];
			if( !handleAndHash.handle.string().empty() )
			{
				return handleAndHash.handle;
			}

			std::string type = shaderNode->typePlug()->getValue();
			if( shaderNode != m_output->node() && !boost::ends_with( type, "shader" ) )
			{
				// Some renderers (Arnold for one) allow surface shaders to be connected
				// as inputs to other shaders, so we may need to change the shader type to
				// convert it into a standard shader. We must take care to preserve any
				// renderer specific prefix when doing this.
				size_t i = type.find_first_of( ":" );
				if( i != std::string::npos )
				{
					type = type.substr( 0, i + 1 ) + "shader";
				}
				else
				{
					type = "shader";
				}
			}

			IECoreScene::ShaderPtr shader = new IECoreScene::Shader( shaderNode->namePlug()->getValue(), type );

			const std::string nodeName = shaderNode->nodeNamePlug()->getValue();
			shader->blindData()->writable()["gaffer:nodeName"] = new IECore::StringData( nodeName );
			shader->blindData()->writable()["gaffer:nodeColor"] = new IECore::Color3fData( shaderNode->nodeColorPlug()->getValue() );

			vector<IECoreScene::ShaderNetwork::Connection> inputConnections;
			addParameterWalk( shaderNode->parametersPlug(), IECore::InternedString(), shader.get(), inputConnections );

			handleAndHash.handle = m_network->addShader( nodeName, std::move( shader ) );
			for( const auto &c : inputConnections )
			{
				m_network->addConnection( { c.source, { handleAndHash.handle, c.destination.name } } );
			}

			return handleAndHash.handle;
		}
コード例 #3
0
ファイル: ArnoldLight.cpp プロジェクト: ivanimanishi/gaffer
IECore::ObjectVectorPtr ArnoldLight::computeLight( const Gaffer::Context *context ) const
{
	IECore::ObjectVectorPtr result = new IECore::ObjectVector;
	IECoreScene::ShaderPtr lightShader = new IECoreScene::Shader( shaderNamePlug()->getValue(), "ai:light" );
	for( InputPlugIterator it( parametersPlug() ); !it.done(); ++it )
	{
		if( const Shader *shader = (*it)->source<Plug>()->ancestor<Shader>() )
		{
			/// \todo We should generalise Shader::NetworkBuilder so we can
			/// use it directly to do the whole of the light generation, instead
			/// of dealing with input networks manually one by one here. Alternatively
			/// we could take the approach that OSLLight takes, and use an internal
			/// ArnoldShader to do all the shader loading and network generation.
			/// This would avoid exposing any Shader internals, and would generalise
			/// nicely to the other Light subclasses too.
			IECore::ConstCompoundObjectPtr inputAttributes = shader->attributes();
			const IECore::ObjectVector *inputNetwork = inputAttributes->member<const IECore::ObjectVector>( "ai:surface" );
			if( !inputNetwork || inputNetwork->members().empty() )
			{
				continue;
			}

			// Add input network into our result.
			result->members().insert( result->members().end(), inputNetwork->members().begin(), inputNetwork->members().end() );
			// Update endpoint of network with a handle we can refer to it with.
			result->members().back() = result->members().back()->copy();
			IECoreScene::Shader *endpoint = static_cast<IECoreScene::Shader *>( result->members().back().get() );
			endpoint->parameters()["__handle"] = new IECore::StringData( (*it)->getName() );
			// Add a parameter value linking to the input network.
			lightShader->parameters()[(*it)->getName()] = new IECore::StringData( "link:" + (*it)->getName().string() );
		}
		else if( ValuePlug *valuePlug = IECore::runTimeCast<ValuePlug>( it->get() ) )
		{
			lightShader->parameters()[valuePlug->getName()] = CompoundDataPlug::extractDataFromPlug( valuePlug );
		}
	}

	result->members().push_back( lightShader );
	return result;
}