For example (code from my Irrlicht project):
Code: Select all
s32 lights_count = 2;
services->setPixelShaderConstant("mLightsCount", &lights_count, 1);
services->setPixelShaderConstant("mLightsPositions", reinterpret_cast<f32*>(&lights_positions), 3 * lights_count);
services->setPixelShaderConstant("mLightsColors", reinterpret_cast<f32*>(&lights_colors), 4 * lights_count);
services->setPixelShaderConstant("mLightsIntensities", lights_intensities.data(), lights_count);
Code: Select all
#version 130
#define MAX_LIGHTS_COUNT 10
uniform int mLightsCount;
uniform vec3 mLightsPositions[MAX_LIGHTS_COUNT];
uniform vec4 mLightsColors[MAX_LIGHTS_COUNT];
uniform float mLightsIntensities[MAX_LIGHTS_COUNT];
Code: Select all
std::array<core::vector3df, MAX_LIGHTS_COUNT> lights_positions;
std::array<video::SColorf, MAX_LIGHTS_COUNT> lights_colors;
std::array<f32, MAX_LIGHTS_COUNT> lights_intensities;
for (int i = 0; i < lights_count; i++)
{
lights_positions[i] = lights[i]->pos;
lights_colors[i] = lights[i]->color;
lights_intensities[i] = lights[i]->intensity;
}
Code: Select all
for (int i = 0; i < mLightsCount; i++)
// Note that function below works properly independing on the current code, it calculates a PBR color based on the reflection equation
r += calcReflectCapability(mapNormal, mLightsPositions[i], viewDir, mRoughness, f0, vec3(mLightsColors[i]), mLightsIntensities[i]);
.......................................................
// 'color' is somewhy always actually equal to vec3(0.0, 0.0, 0.0), so outputing a black color
gl_FragColor = vec4(color, 1.0);