I attempting to implement deferred rendering, and my test code has run into a problem I am unable to solve:
I use the following data for my fullscreen quad:
glm::vec3 verts[] = {
glm::vec3(-1.0f,-1.0f,0.0f), //0
glm::vec3( 1.0f,-1.0f,0.0f), //1
glm::vec3( 1.0f, 1.0f,0.0f), //2
glm::vec3(-1.0f, 1.0f,0.0f) }; //3
glm::vec2 texCoords[] = {
glm::vec2(0.0f,1.0f),
glm::vec2(1.0f,1.0f),
glm::vec2(1.0f,0.0f),
glm::vec2(0.0f,1.0f),
glm::vec2(1.0f,0.0f),
glm::vec2(0.0f,0.0f) };
unsigned int indices[] = { 0,1,2,0,2,3 };
Which renders like so:
As you can see, the vertices indexed by indices[3] and indices[5] appear to be using the same uv coordinate, causing the sampling in the second(top left) triangle of the quad to stretch, but as you can also see, the uv data is fine(albeit flipped vertically).
I've used Nsight to examine the data stored in the buffers in graphics memory to confirm the data is correct for the full screen quad, and that the error is definitely happening during the following shader execution:
Vertex shader:
#version 430
// Some drivers require the following
precision highp float;
layout (location = 0)in vec3 MSVertex;
layout (location = 4)in vec2 MSTexCoord;
out xferBlock
{
vec3 VSVertex;
vec2 VSTexCoord;
} outdata;
void main()
{
outdata.VSVertex = MSVertex;
outdata.VSTexCoord = MSTexCoord;
gl_Position = vec4(MSVertex,1.0);
}
Fragment shader:
#version 430
// Some drivers require the following
precision highp float;
layout (location = 2) uniform sampler2D colourMap;
layout (location = 4) uniform sampler2D glowMap;
out vec4 colour;
in xferBlock
{
vec3 VSVertex;
vec2 VSTexCoord;
} indata;
void main()
{
vec4 dcolour = texture(colourMap, indata.VSTexCoord).rgba;
vec4 gcolour = texture(glowMap, indata.VSTexCoord).rgba;
colour = dcolour*gcolour;
}
As you can see, there is nothing fancy about the shader which alters the texture coordinates, so I'm at a loss as to explain why this is happening.
Update:
I modified the shader to output R,G (blue is always zero) colours based on UV coordinates for the quad, and My initial impression was correct: The coordinate being referenced for the left corner of the quad is (0,0), which is incorrect:
What it should look like, is this:



glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);- Ian Young