Ejemplo n.º 1
0
void AppleseedLight::setupPlugs( const std::string &shaderName, const asf::DictionaryArray &metadata )
{
	bool needsRadianceTexture = shaderName.find( "map" ) != std::string::npos;

	for( size_t i = 0, e = metadata.size(); i < e; ++i )
	{
		const asf::Dictionary &inputMetadata = metadata[i];
		std::string inputName = inputMetadata.get( "name" );
		std::string inputType = inputMetadata.get( "type" );

		Gaffer::Plug *plug = nullptr;

		// some environment lights need their radiance color input
		// replaced by a texture input: latlong map and mirrorball map.
		if( needsRadianceTexture && inputName == "radiance" )
		{
			plug = new Gaffer::StringPlug( "radiance_map", Gaffer::Plug::In );
		}
		else
		{
			if( inputType == "numeric" )
			{
				float defaultValue = inputMetadata.get<float>( "default" );
				float minValue = get_min_max_value( inputMetadata, "min" );
				float maxValue = get_min_max_value( inputMetadata, "max" );
				plug = new Gaffer::FloatPlug( inputName, Gaffer::Plug::In, defaultValue, minValue, maxValue );
			}
			else if( inputType == "colormap" )
			{
				// override the plug type for the exposure param (usually it's a color in appleseed).
				if ( inputName == "exposure" )
				{
					plug = new Gaffer::FloatPlug( inputName, Gaffer::Plug::In, 0.0f );
				}
				// multiplier inputs make more sense in Gaffer as float plugs.
				else if( inputName.find( "multiplier" ) != std::string::npos )
				{
					plug = new Gaffer::FloatPlug( inputName, Gaffer::Plug::In, 1.0f, 0.0f );
				}
				else
				{
					plug = new Gaffer::Color3fPlug( inputName, Gaffer::Plug::In, Imath::Color3f( 1.0f ) );
				}
			}
			else if( inputType == "boolean" )
			{
				bool defaultValue = strcmp( inputMetadata.get( "default" ), "true" ) == 0;
				plug = new Gaffer::BoolPlug( inputName, Gaffer::Plug::In, defaultValue );
			}
			// text are non-texturable float inputs.
			else if( inputType == "text" )
			{
				float defaultValue = inputMetadata.get<float>( "default" );
				plug = new Gaffer::FloatPlug( inputName, Gaffer::Plug::In, defaultValue );
			}
		}

		if( plug )
		{
			plug->setFlags( Gaffer::Plug::Dynamic, true );
			parametersPlug()->addChild( plug );
		}
	}
}
Ejemplo n.º 2
0
void AppleseedLight::setupPlugs( const std::string &shaderName, const asf::DictionaryArray &metadata )
{
	bool needsRadianceTexture = shaderName.find( "map" ) != std::string::npos;

	for( size_t i = 0, e = metadata.size(); i < e; ++i )
	{
		const asf::Dictionary &inputMetadata = metadata[i];
		std::string inputName = inputMetadata.get( "name" );
		std::string inputType = inputMetadata.get( "type" );

		Gaffer::Plug *plug = 0;

		// some environment lights need their radiance color input
		// replaced by a texture input: latlong map and mirrorball map.
		if( needsRadianceTexture && inputName == "radiance" )
		{
			plug = new Gaffer::StringPlug( "radiance_map", Gaffer::Plug::In );
		}
		else
		{
			if( inputType == "numeric" )
			{
				float defaultValue = boost::lexical_cast<float>( inputMetadata.get( "default" ) );
				float minValue = boost::lexical_cast<float>( inputMetadata.get( "min_value" ) );
				float maxValue = boost::lexical_cast<float>( inputMetadata.get( "max_value" ) );
				plug = new Gaffer::FloatPlug( inputName, Gaffer::Plug::In, defaultValue, minValue, maxValue );
			}
			else if( inputType == "colormap" )
			{
				// multiplier inputs make more sense is Gaffer as float plugs.
				if( inputName.find( "multiplier" ) != std::string::npos )
				{
					plug = new Gaffer::FloatPlug( inputName, Gaffer::Plug::In, 1.0f, 0.0f );
				}
				else
				{
					plug = new Gaffer::Color3fPlug( inputName, Gaffer::Plug::In, Imath::Color3f( 1.0f ) );
				}
			}
			else if( inputType == "boolean" )
			{
				bool defaultValue = strcmp( inputMetadata.get( "default" ), "true" ) == 0;
				plug = new Gaffer::BoolPlug( inputName, Gaffer::Plug::In, defaultValue );
			}
			// text are non-texturable float inputs.
			else if( inputType == "text" )
			{
				float defaultValue = boost::lexical_cast<float>( inputMetadata.get( "default" ) );
				plug = new Gaffer::FloatPlug( inputName, Gaffer::Plug::In, defaultValue );
			}
			// entity represent connections between entities that can work together,
			// like the sky environments and the sun light.
			else if( inputType == "entity" )
			{
				plug = new Gaffer::StringPlug( inputName, Gaffer::Plug::In );
			}
		}

		if( plug )
		{
			plug->setFlags( Gaffer::Plug::Dynamic, true );
			parametersPlug()->addChild( plug );
		}
	}
}