Code: Select all
struct Light
{
float4 DiffuseColor;
float4 SpecularColor;
float4 AmbientColor;
float4 Attenuation;
float OuterCone;
float InnerCone;
float Falloff;
float4 Position;
float4 Direction;
float Radius;
int LightType;
};
Code: Select all
#define MaxLights 8
static int POINT = 0;
static int SPOT = 1;
static int DIRECTIONAL = 2;
Light lights[MaxLights];
Code: Select all
struct Light
{
irr::video::SColorf DiffuseColor;
irr::video::SColorf SpecularColor;
irr::video::SColorf AmbientColor;
irr::core::vector3df Attenuation;
float pad0;
float OuterCone;
float InnerCone;
float Falloff;
irr::core::vector3df Position;
float pad1;
irr::core::vector3df Direction;
float pad2;
float Radius;
irr::u32 LightType;
};
Code: Select all
if ( UseLights && MaxLights > 0 )
{
irr::u32 numLights = driver->getDynamicLightCount();
for (irr::u32 i=0; i<numLights; ++i)
{
if ( i > MaxLights )
break;
//Light structure to be passed to shader
Light light;
//Irrlicht light structure (can't be directly passed because it contains no padding).
irr::video::SLight irrLight = driver->getDynamicLight(i);
//Copy to the padded light struct
light.DiffuseColor = irrLight.DiffuseColor;
light.SpecularColor = irrLight.SpecularColor;
light.AmbientColor = irrLight.AmbientColor;
light.Attenuation = irrLight.Attenuation;
light.OuterCone = irrLight.OuterCone;
light.InnerCone = irrLight.InnerCone;
light.Falloff = irrLight.Falloff;
light.Position = irrLight.Position;
light.Direction = irrLight.Direction;
light.Radius = irrLight.Radius;
light.LightType = (irr::u32)irrLight.Type;
services->setPixelShaderConstant("lights", reinterpret_cast<irr::f32*>(&light), 1);
}
}