Hi there,
Corrected the GL_ALPHA faux pas, i now no longer get a blank screen, i just get an unlit scene. This is some code, I think I’ve narrowed it down to being the LightMatricesBlock uniform buffer object, but it may be when I’m setting the vertex attributes. I’ve posted my vertex shader for my uberlight shader at the bottom. It runs fine on my nvidia 3.3 machine and on the ati 3.3 machines in the labs but on the machines with the ATI 5700 series 4.1 cards (which i have to demo on) i get this lack of lighting.
glGetProgramInfoLog returns:
Fragment shader(s) linked, vertex shader(s) linked
although the uberlight shader does not light the scene, the geometry shader for the normals works fine. As in can see the box but it’s black and unlit.
I use uniform buffer objects in the uberlight and geometry shaders, this is the code I use for setting up the uberlights LightMatricesBlock, both use another UBO called GlobalMatricesBlock which seems to work fine, so I’m guessing it must be this one that isn’t working…
/*
layout(std140) uniform LightMatricesBlock
{
vec4 Eye; //0
mat4 WorldMatrixIT; //16
mat4 WCtoLCMatrix[4]; //sizeof(GLfloat)*16 + 16
mat4 WCtoLCMatrixIT[4]; //sizeof(GLfloat)164 + 16
} LightMatrices;
*/
int NLights = 4; int vec4 = 16; int mat4 = 64;
GLuint _LightMatUBO; //Buffer objects
const int _LightMatBinding = 1; //Buffer binding point
glGenBuffers(1,& _LightMatUBO);
glBindBuffer(GL_UNIFORM_BUFFER, _LightMatUBO);
glBufferData(GL_UNIFORM_BUFFER, mat4*9 + vec4, NULL, GL_DYNAMIC_DRAW);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
//Bind this buffer to the ‘1’ binding point
glBindBufferBase(GL_UNIFORM_BUFFER, _LightMatBinding, _LightMatUBO);
// . . .
// later on I add the data
glBindBuffer(GL_UNIFORM_BUFFER, _LightMatUBO);
glBufferSubData(GL_UNIFORM_BUFFER,0, vec4, _Eye.GetPointer());
glBufferSubData(GL_UNIFORM_BUFFER,vec4, mat4, _WorldMatrixit.GetPointer());
for(int i = 0; i < NLights; ++i)
{
glBufferSubData(GL_UNIFORM_BUFFER,vec4 + mat4 + mat4i,mat4,_WCtoLCMatrix[i].GetPointer());
glBufferSubData(GL_UNIFORM_BUFFER,vec4 + mat4 + mat4NLights + mat4*i,mat4, _WCtoLCMatrixit[i].GetPointer() );
}
glBindBuffer(GL_UNIFORM_BUFFER, 0);
GLuint LightMatrices_Index = g->glGetUniformBlockIndex(_Program, “LightMatricesBlock”);
glUniformBlockBinding(_Program, LightMatrices_Index, _LightMatBinding);
…
In the construction of the shader, after attaching my shaders to the program and before linking the program I bind my vertex attributes:
//Vertex Attributes
g->glBindAttribLocation(_Program,0,“vVertex”);
g->glBindAttribLocation(_Program,1,“vNormal”);
g->glBindAttribLocation(_Program,2,“vTexCoords”);
this is what my uberlight vertex shader looks like:
#version 330
layout(std140) uniform GlobalMatricesBlock
{
mat4 PerspectiveMatrix; //0
mat4 ViewMatrix; //sizeof(GLfloat)*16
mat4 WorldMatrix; //sizeof(GLfloat)162
} GlobalMatrices;
layout(std140) uniform LightMatricesBlock
{
vec4 Eye; //0
mat4 WorldMatrixIT; //16
mat4 WCtoLCMatrix[4]; //sizeof(GLfloat)*16 + 16
mat4 WCtoLCMatrixIT[4]; //sizeof(GLfloat)164 + 16
} LightMatrices;
uniform mat4 ModelMatrix;
in vec4 vVertex;
in vec3 vNormal;
in vec2 vTexCoords;
out vec3 LCcamera[4];
out vec3 LCpos[4];
out vec3 LCnorm[4];
smooth out vec2 vVaryingTexCoords;
void main()
{
gl_PointSize = 5.0;
gl_Position = GlobalMatrices.PerspectiveMatrix *
GlobalMatrices.ViewMatrix *
GlobalMatrices.WorldMatrix *
ModelMatrix * vVertex;
//compute world space position and normal
vec4 wcPos = GlobalMatrices.WorldMatrix * ModelMatrix * vVertex;
vec3 wcNorm = (LightMatrices.WorldMatrixIT * ModelMatrix * vec4(vNormal,0.0)).xyz;
//For each light
//compute light coordinate system camera positions,
//vertex position and normal
for(int i = 0; i < 4; i++)
{
LCcamera[i] = (LightMatrices.WCtoLCMatrix[i] * LightMatrices.Eye).xyz;
LCpos[i] = (LightMatrices.WCtoLCMatrix[i] * wcPos).xyz;
LCnorm[i] = (LightMatrices.WCtoLCMatrixIT[i] * vec4(wcNorm,0.0)).xyz;
}
vVaryingTexCoords = vTexCoords;
}