PDA

View Full Version : Shader making textured quad, equal to uv coords. Help!



ParagonArcade
01-03-2015, 09:30 PM
So I have been working on this engine for awhile and I have a whole 3D world now with a working camera, shader with textures and lighting. Now I am trying to do a GUI. I am disabling DEPTH_TEST, switching to orthographic view, and turning off the lightning, or trying. Now whenever I try to render these two "interfaces", it always renders them as if the vertex color is the UV coordinates, even tho I am setting the vertex color to white. Now I am using the same shader as all my other stuff. Here are some photos:

With the frag color in the fragment shader set equal to the texture color:


frag_color = texture2D(sampler, vTexture.st);

1579

With the frag color equal to the vertex color:


frag_color = vColor;

1580


Here is the setup for the quad:


mesh->addVertex(Vertex(Vector3f(Position.getX() + half_width, Position.getY() + half_height, 0.0f), Vector3f(1.0f), Vector3f(0.0f, 0.0f, 1.0f), Vector2f(1.0f, 1.0f)));
mesh->addVertex(Vertex(Vector3f(Position.getX() - half_width, Position.getY() + half_height, 0.0f), Vector3f(1.0f), Vector3f(0.0f, 0.0f, 1.0f), Vector2f(0.0f, 1.0f)));
mesh->addVertex(Vertex(Vector3f(Position.getX() - half_width, Position.getY() - half_height, 0.0f), Vector3f(1.0f), Vector3f(0.0f, 0.0f, 1.0f), Vector2f(0.0f, 0.0f)));
mesh->addVertex(Vertex(Vector3f(Position.getX() + half_width, Position.getY() - half_height, 0.0f), Vector3f(1.0f), Vector3f(0.0f, 0.0f, 1.0f), Vector2f(1.0f, 0.0f)));


I don't understand what could be wrong. Really stumped. I traced through all the initilizations but its all the same shader, mesh class, etc. It just with the 2D interface, it makes it the UV coords.

Alfonse Reinheart
01-04-2015, 08:06 AM
I don't understand what could be wrong.

Neither do we. It could be any number of things. The code you posted isn't OpenGL code, and you haven't posted enough of your shaders for us to even begin to guess at your problem.

ParagonArcade
01-04-2015, 12:44 PM
I'm using the shader to draw everything in the scene, and the pictures shows it all working as intended except for the quads.

Fragment Shader:


#version 440

in vec3 vPosition;
in vec4 vColor;
in vec3 vNormal;
in vec2 vTexture;

uniform sampler2D sampler;

out vec4 frag_color;

void main()
{
vec4 tColor = texture2D(sampler, vTexture.st);
vec4 fColor = vColor;

//calculate totalLight

fColor = fColor * tColor * vec4(totalLight, 1.0f);

frag_color = fColor;
}


I did notice on thing though. When I changed "frag_color = fColor" to "frag_color = tColor" like in the picture above, where uniforms aren't being used and optimized out, my shader is not displaying the uniform names right? It's like corrupted all the sudden?

1581

Never had this problem before, and if I change it back to "frag_color = fColor" so all the uniforms are used. It doens't spit out any errors or nothing. But as stated earlier, this all worked fine before I started trying to add the 2D quads. The shader validated and compiles with no errors and if I didn't include a uniform, it would print out the error codes properly. Haven't change anything from below.



static void validateShader(GLuint shader, const char* file = 0)
{
const unsigned int BUFFER_SIZE = 512;
char buffer[BUFFER_SIZE];
memset(buffer, 0, BUFFER_SIZE);
GLsizei length = 0;

glGetShaderInfoLog(shader, BUFFER_SIZE, &length, buffer);
if (length > 0) {
std::cerr << "Shader" << shader << "(" << (file ? file : "") << ") compile error :" << buffer << std::endl;
}
}
static void validateProgram(GLuint program)
{
const unsigned int BUFFER_SIZE = 512;
char buffer[BUFFER_SIZE];
memset(buffer, 0, BUFFER_SIZE);
GLsizei length = 0;

memset(buffer, 0, BUFFER_SIZE);
glGetProgramInfoLog(program, BUFFER_SIZE, &length, buffer);
if (length > 0)
std::cerr << "Program " << program << " link error : " << buffer << std::endl;

glValidateProgram(program);
GLint status;
glGetProgramiv(program, GL_VALIDATE_STATUS, &status);
if (status == GL_FALSE)
std::cerr << "Error validating shader " << program << std::endl;
}


Also, some warning regarding the image loader, SOIL, just now popping up when compiling?



1>SOIL.lib(image_DXT.obj) : warning LNK4099: PDB 'vc120.pdb' was not found with 'SOIL.lib(image_DXT.obj)'
1>SOIL.lib(image_helper.obj) : warning LNK4099: PDB 'vc120.pdb' was not found with 'SOIL.lib(image_helper.obj)'
1>SOIL.lib(SOIL.obj) : warning LNK4099: PDB 'vc120.pdb' was not found with 'SOIL.lib(SOIL.obj)'
1>SOIL.lib(stb_image_aug.obj) : warning LNK4099: PDB 'vc120.pdb' was not found with 'SOIL.lib(stb_image_aug.obj)'

GClements
01-04-2015, 03:34 PM
it always renders them as if the vertex color is the UV coordinates
Are you trying to use the attribute indices from one program with a different program?

Unless you force the attributes to have specific indices (whether with layout qualifiers or glBindAttribLocation), the index used for a particular attribute variable is likely to vary from one program to another. So you need to query the location for each program, and re-bind the attribute arrays for each program.


I did notice on thing though. When I changed "frag_color = fColor" to "frag_color = tColor" like in the picture above, where uniforms aren't being used and optimized out, my shader is not displaying the uniform names right? It's like corrupted all the sudden?
If a uniform isn't used, it will be optimised out, which means that it won't appear in the list of active uniforms for that program. glGetUniformLocation() will return -1 if the argument isn't the name of an active uniform (i.e. one which is actually used).