Beispiel #1
0
void GLSLProgram<real>::SetupLights()
{
	const std::vector<Light<real>*>* lights = RenderState<real>::Get()->GetLights();

	// Setup enabled lights
	for ( uint i=0 ; i<lights->size() && i<mLightLocations.size() ; ++i )
	{
		Light<real>* light = (*lights)[i];
		glUniform1i( mLightLocations[i].enabled, true );
		glUniform1i( mLightLocations[i].type, light->GetLightType() );
		Vector3<float> position = light->GetLocalToGlobal() * Vector3<real>( 0, 0, 0 );
		glUniform3fv( mLightLocations[i].position, 1, (float*)&position );
		Color<float> intensity = light->GetIntensity();
		glUniform4fv( mLightLocations[i].intensity, 1, (float*)&intensity );
		Color<float> ambient = light->GetAmbient();
		glUniform4fv( mLightLocations[i].ambient, 1, (float*)&ambient );

		// Setup sub-parameters
		switch( light->GetLightType() )
		{
			case Light<real>::TypeDirectional: SetupDirectionalLight( i, light ); break;
			case Light<real>::TypePoint: SetupPointLight( i, light ); break;
			case Light<real>::TypeSpot: SetupSpotLight( i, light ); break;
		}
	}

	// Disabled lights
	for ( uint i=lights->size() ; i<mLightLocations.size() ; ++i )
		glUniform1i( mLightLocations[i].enabled, false );

	// Nb of lights
	glUniform1i( mNbLightsLocation, lights->size() );
}
Color<real> BlinnPhongShader<real>::GetAmbient( const Light<real>& light )
{
    Color<real> ambientColor( 0, 0, 0, 1 );

    ////////////////////////////////////////////
    //////////////////IFT 3355//////////////////
    ////////////////////////////////////////////
    //Ici, vous calculerez la composante
    //ambiante.
    ////////////////////////////////////////////
    //////////////////IFT 3355//////////////////
    ////////////////////////////////////////////

    ambientColor += light.GetAmbient() *
        GetMaterialSurfaceColor() *
      mMaterial.GetAmbient() *
      GetAmbientOcclusion(mRayTracer.GetNbAmbientOcclusionSamples(),
			  mRayTracer.GetAmbientOcclusionRadius());
    return ambientColor;
}