Exemplo n.º 1
0
Color::Color( const Colorf& source )
{
	setRed( convertColorFloatToByte(source.red()) );
	setGreen( convertColorFloatToByte(source.green()) );
	setBlue( convertColorFloatToByte(source.blue()) );
	setAlpha( convertColorFloatToByte(source.alpha()) );
}
Exemplo n.º 2
0
void GameProjectile::setShaderParams( Primitive* /*prim*/, Shader* fx, Mesh* mesh, Camera* camera, Light* keylight )
{
	Vector3 cameraWPos = camera->worldTransform().translation();
	Matrix4x4 worldTm = mesh->cachedWorldTransform();
	Matrix4x4 worldTmInv = worldTm.inverse();

	for ( int i = 0 ; i < fx->parameters() ; ++i )
	{
		Shader::ParameterDesc desc;
		fx->getParameterDesc( i, &desc );
		
		if ( desc.name == "GROUND_COLOR" )
		{
			Vector4 groundColorMin4, groundColorMax4;
			fx->getVector4( "GROUND_COLOR_MIN", &groundColorMin4 );
			fx->getVector4( "GROUND_COLOR_MAX", &groundColorMax4 );
			Colorf groundColorMin( groundColorMin4.x, groundColorMin4.y, groundColorMin4.z, 1.f );
			Colorf groundColorMax( groundColorMax4.x, groundColorMax4.y, groundColorMax4.z, 1.f );
			Colorf c = ( (groundColorMax-groundColorMin) * m_groundLightmapColor + groundColorMin ).saturate();
			fx->setVector4( desc.name, Vector4(c.red(),c.green(),c.blue(),1.f) );
		}
		else if ( desc.name == "SKY_COLOR" )
		{
			Vector4 skyColorMin4, skyColorMax4;
			fx->getVector4( "SKY_COLOR_MIN", &skyColorMin4 );
			fx->getVector4( "SKY_COLOR_MAX", &skyColorMax4 );
			Colorf skyColorMin( skyColorMin4.x, skyColorMin4.y, skyColorMin4.z, 1.f );
			Colorf skyColorMax( skyColorMax4.x, skyColorMax4.y, skyColorMax4.z, 1.f );
			Colorf c = ( (skyColorMax-skyColorMin) * m_groundLightmapColor + skyColorMin ).saturate();
			fx->setVector4( desc.name, Vector4(c.red(),c.green(),c.blue(),1.f) );
		}
		else if ( desc.name == "SPECULAR_COLOR" )
		{
			Vector4 specularColorMin4, specularColorMax4;
			fx->getVector4( "SPECULAR_COLOR_MIN", &specularColorMin4 );
			fx->getVector4( "SPECULAR_COLOR_MAX", &specularColorMax4 );
			Colorf specularColorMin( specularColorMin4.x, specularColorMin4.y, specularColorMin4.z, 1.f );
			Colorf specularColorMax( specularColorMax4.x, specularColorMax4.y, specularColorMax4.z, 1.f );
			Colorf c = ( (specularColorMax-specularColorMin) * m_groundLightmapColor + specularColorMin ).saturate();
			fx->setVector4( desc.name, Vector4(c.red(),c.green(),c.blue(),1.f) );
		}
		else if ( desc.dataType == Shader::PT_FLOAT && desc.dataClass == Shader::PC_VECTOR4 && 
			desc.name.length() > 0 && Character::isLowerCase(desc.name.charAt(0)) &&
			desc.name.indexOf("Camera") == -1 )
		{
			bool paramResolved = false;
			bool objSpace = ( desc.name.length() > 2 && desc.name.charAt(1) == 'o' );
			int baseNameOffset = objSpace ? 2 : 1;

			Node* node = 0;
			String name = desc.name.substring( baseNameOffset );
			if ( keylight && name == "Light1" )
				node = keylight;

			if ( node )
			{
				Char ch = desc.name.charAt(0);
				if ( ch == 'd' )
				{
					Vector3 v = node->worldTransform().rotation().getColumn(2);
					if ( objSpace )
						v = worldTmInv.rotate(v);
					fx->setVector4( desc.name, Vector4(v.x, v.y, v.z, 0.f) );
					paramResolved = true;
				}
				if ( ch == 'p' )
				{
					Vector3 v = node->worldTransform().translation();
					if ( objSpace )
						v = worldTmInv.transform(v);
					fx->setVector4( desc.name, Vector4(v.x, v.y, v.z, 1.f) );
					paramResolved = true;
				}
			}

			if ( !paramResolved )
			{
				Debug::printlnError( "Mesh {2} shader {0} parameter {1} could not be resolved", fx->name(), desc.name, mesh->name() );
			}
		}
	}
}