Exemplo n.º 1
0
void LightingDemo::SetHSPointLights( ShaderLightManager& shader_light_mgr, bool random_color )
{
	int x = m_NumLightsX;
	int z = m_NumLightsZ;
	float span_x = 32.0f;
	float span_z = 32.0f;
//	int num_point_lights = 4;
//	for( int i=0; i<num_point_lights; i++ )
	float interval_x = (2 <= x) ? span_x / (float)(x-1) : 0.0f;
	float interval_z = (2 <= z) ? span_z / (float)(z-1) : 0.0f;
	int num_point_lights = z * x;
	int light_index = 0;
	m_HSPointLights.resize(0);
	m_HSPointLights.reserve(x * z);

	for( int i=0; i<z; i++ )
	{
		for( int j=0; j<x; j++ )
		{
			HemisphericPointLight light;
//			light.Attribute.UpperDiffuseColor.SetRGBA( 1.0f, 1.0f, 1.0f, 1.0f );
			int color_index = light_index % numof(s_rand_colors);
			light_index++;
			light.Attribute.UpperDiffuseColor = random_color ? s_rand_colors[color_index] : SFloatRGBAColor::White();
			light.Attribute.LowerDiffuseColor.SetRGBA( 0.0f, 0.0f, 0.0f, 1.0f );
			light.vPosition = Vector3(
				(float)j * interval_x - span_x * 0.5f,
				1.0f,
				(float)i * interval_z - span_z * 0.5f );
			light.fAttenuation[0] = 0.2f;
			light.fAttenuation[1] = 0.1f;
			light.fAttenuation[2] = 0.1f;
			m_HSPointLights.push_back(light);
			shader_light_mgr.SetHemisphericPointLight( light );
		}
	}
}