I am trying to pass
out float texture_contribs[16]
from the vertex shader to the frament shader using glsl 3.3
However the values in the frament shader are always 0.0, no matter the value in the vertex shader.
Here is my vertex shader code:
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform mat4 modelMatrix;
uniform mat4 normalMatrix;
layout(location = 0) in vec4 in_position;
layout(location = 1) in vec4 in_colour;
layout(location = 2) in vec2 in_coord;
layout(location = 3) in vec3 in_normal;
layout(location = 4) in float texture_contributions[16];
out vec2 texcoord;
out vec4 pass_colour;
out float texture_contribs[16];
smooth out vec3 vNormal;
void main()
{
gl_Position = projectionMatrix * viewMatrix * modelMatrix * in_position;
texcoord = in_coord;
vec4 vRes = normalMatrix*vec4(in_normal, 0.0);
vNormal = vRes.xyz;
pass_colour = in_colour;
for (int i = 0; i < 16; i++)
{
texture_contribs[i] = texture_contributions[i];
}
}
and here is the fragment shader code:
uniform sampler2D texture[16];
in vec2 texcoord;
in vec4 pass_colour;
in float texture_contribs[16];
smooth in vec3 vNormal;
out vec4 out_colour;
struct SimpleDirectionalLight
{
vec3 vColor;
vec3 vDirection;
float fAmbientIntensity;
};
uniform SimpleDirectionalLight sunLight;
void main()
{
vec4 vTexColor = texture2D(texture[2], texcoord) * texture_contribs[2] + texture2D(texture[3], texcoord) * texture_contribs[3];
if(vTexColor.a < 0.1)
discard;
float fDiffuseIntensity = max(0.0, dot(normalize(vNormal), -sunLight.vDirection));
out_colour = vTexColor*pass_colour*vec4(sunLight.vColor*(sunLight.fAmbientIntensity+fDiffuseIntensity), 1.0);
}
I attempted splitting the array into individual variables and passing them separately and their values still disappear in the fragment shader.
layout(location = 4) in float texture_contributions[16];
strikes me as very unusual. That requires 16 attribute slots, and most implementations limit you to 16 total. You can uselayout(location = 4) in mat4 texture_contributions;
to do the same thing while only taking 4 attribute slots. It will be assigned to attribute slots 4,5,6,7. – Andon M. Colemanvec4
s, so when you aggregate them into an array like that instead of packing intovec4
ormat4
s you are playing with fire. – Andon M. Coleman