PDA

View Full Version : UV - Shader Problem



Halcom
09-17-2015, 05:35 AM
Hi,

i have a small simple shader that show me a Texture. Now i need the real texture coordinates. That should be calculated with x = uv.x * texturesize and y = uv.y * texturesize.
to visualize the uv coordinates better, i updated my shader to show them. But all i get is a black image.

here is my little shader.


#version 330 core

// Interpolated values from the vertex shaders
in vec2 UV;

// Output data
out vec4 color;

// texture to use
uniform sampler2D myTextureSampler;

void main(){
//color = texture2D( myTextureSampler, UV).rgba; // show texture correctly
//color = vec4(UV.xy, 1.0, 1.0); // gives blue image
//color = vec4(UV.x, UV.y, 0.0, 1.0); // gives black image
color = vec4(UV.xy, 0.0, 1.0); // gives black image
}


I am a little surprised. The UV coordinates should be ok, if not i would not see the correct texture if i use the first line.

What did i miss?

thx

GClements
09-17-2015, 06:43 AM
Did you check that the shader compiled and linked successfully? Did you check for OpenGL errors after rendering? If you call glUseProgram() with an invalid program object, no program will be installed and (assuming a compatibility profile) subsequent rendering operations will use the fixed-function pipeline.

Are you querying the uniform locations correctly? Changing the shader so that myTextureSampler isn't referenced will typically result in it being removed, which in turn may result in the locations of other uniforms changing.

Halcom
09-17-2015, 06:51 AM
Did you check that the shader compiled and linked successfully? Did you check for OpenGL errors after rendering? If you call glUseProgram() with an invalid program object, no program will be installed and (assuming a compatibility profile) subsequent rendering operations will use the fixed-function pipeline.

Are you querying the uniform locations correctly? Changing the shader so that myTextureSampler isn't referenced will typically result in it being removed, which in turn may result in the locations of other uniforms changing.

Removed the myTextureSampler Part, nothing changes.
Yes i check this, i got shader compile errors before. Set breakpoints to this methods no one breaks. It must compile because if i use the second row i got a blue image.



QOpenGLShader vertexShader(QOpenGLShader::Vertex);
const bool compiledVertex = vertexShader.compileSourceFile(":/ABSGUIBase/ShaderVertex.txt");
if(!compiledVertex)
{
qDebug("%s", qPrintable(vertexShader.log()));
return;
}
mProgram->addShader(&vertexShader);

QOpenGLShader fragmentShader(QOpenGLShader::Fragment);
const bool compiledFragment = fragmentShader.compileSourceFile(":/ABSGUIBase/ShaderFragment.txt");
if(!compiledFragment)
{
qDebug("%s", qPrintable(fragmentShader.log()));
return;
}
mProgram->addShader(&fragmentShader);

mProgram->bindAttributeLocation("vertexPosition_modelspace", PROGRAM_VERTEX_ATTRIBUTE);
mProgram->bindAttributeLocation("vertexNormal_modelspace", PROGRAM_VERTEX_NORMAL_ATTRIBUTE);
mProgram->bindAttributeLocation("vertexUV", PROGRAM_VERTEX_UV_ATTRIBUTE);
if(!mProgram->link())
{
qDebug("Program Link error!!!");
return;
}

Halcom
09-18-2015, 01:41 AM
That lillte thing wanna fool me. Give it a second try this morning and its work as expected.:confused: