PDA

View Full Version : Problem with layout std140 and binding



manuel_p
12-01-2016, 10:12 AM
Hi,

I'm trying to compile a fragment shader containing a uniform block with an explicit binding point and an std140 layout to handle lighting in my engine. However, I get the following errors :

0(38) : error C3008: unknown layout specifier 'binding = 0'
0(38) : error C7600: no value specified for layout qualifier 'std140'
0(44) : error C3008: unknown layout specifier 'binding = 1'
0(44) : error C7600: no value specified for layout qualifier 'std140'


Here's the code :

#version 440

layout(location = 0) in vec4 inWorldPosition;
layout(location = 1) in vec4 inNormal;
layout(location = 2) in vec2 inTexCoord;
layout(location = 3) in vec4 inTangent;
layout(location = 4) in vec4 inBiTangent;

layout(location = 0) out vec4 nu_outColor;

#define PREPASS void nu_PrePass(out vec4 outNormal, out vec4 outDiffuse, out vec4 outSpecular)

PREPASS
{
outDiffuse = vec4(1, 0, 0, 1) * dot(inNormal, vec4(0.5, 0.5, 0, 0));
}

#undef PREPASS

#define LIGHTPASS vec4 nu_LightPass(in vec4 inNormal, in vec4 inDiffuse, in vec4 inSpecular)

LIGHTPASS
{
return inDiffuse;
}

#undef LIGHTPASS

layout(location = 5) uniform int NumPointLights;
layout(location = 6) uniform int NumDirLights;

layout(std140, binding = 0) uniform struct PointLightData
{
vec4 position;
vec4 color;
float range;
int _padding[3];
} pointLights[200];

layout(std140, binding = 1) uniform struct DirectionalLightData
{
vec4 color;
vec4 direction;
} directionalLights[5];

void main()
{
vec4 normal, diffuse, specular;
nu_PrePass(normal, diffuse, specular);
nu_outColor = nu_LightPass(normal, diffuse, specular);
}

Am I making some silly mistakes ? Or is it maybe a driver bug (very unlikely) ?

Thank you for your help !

john_connor
12-01-2016, 12:20 PM
define your structs normally:
struct PointLight
{
// members + padding here
};

then use no instanced name for your blocks, just do:
layout (std140, binding = 0) uniform Block1
{
PointLight PointLiughts[MAX_POINTLIGHTS];
};

make sure that:
MAX_POINTLIGHTS * sizeof(PointLight including padding) < GL_MAX_UNIFORM_BLOCK_SIZE

manuel_p
12-01-2016, 03:28 PM
Thanks a lot, it fixed the issue ! It seems I completely misunderstood the syntax of uniform blocks. I also take note of what you said about making sure not to exceed the max size of UBO.