Uniform blocks


I’m trying to do some uniform blocks for matricies. Finally made them work, but why is it necessary to declare same uniform block in all shaders, even if only one shader use it? This fragment shader has no use for transformation matricies, but if the block isn’t declared, shader can’t see named uniforms (they get 0.0 no matter how i initialize them).

#version 330
uniform MatrixBlock
	uniform mat4 MVmatrix;
	uniform mat4 MVPmatrix;
uniform vec3  BrickColor;
uniform vec3  MortarColor;
uniform vec2  BrickSize;
uniform vec2  BrickPct;

in vec3       MCposition;
in float      LightIntensity;

out vec4      FragColor;

void main()
    vec3  color;
    vec3  position, useBrick;
    position = MCposition / BrickSize.xyx;
    if (fract(position.y * 0.5) > 0.5)
        position.x += 0.5;
	position.z += 0.5;
    position = fract(position);
    useBrick = step(position, BrickPct.xyx);
    color  = mix(MortarColor, BrickColor, useBrick.x * useBrick.y * useBrick.z);
    color *= LightIntensity;
    FragColor = vec4(color, 1.0);

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.