Arrays can not be passed to GLSL 1.3.
Posted: Mon Jul 24, 2023 4:34 pm
Before I always passed only non-array uniforms, i.e. just vectors, matrices, floats. However, when I tried to pass arrays of vectors and floats, they are just filled by nulls as if nothing got passed from CPU side.
For example (code from my Irrlicht project):
In GLSL fragment shader:
Here the arrays are std::arrays which are afterwards converted to the standard static ones:
In that fragment shader below I get access only to the first two elements from each array (since lights_count = 2):
I use Irrlicht 1.9 from master branch with the latest commit: https://github.com/zaki/irrlicht . What can I do wrong here?
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);