OpenGL shader fill works with constant color, doesn't work with interpolation, how to debug?

Viewed 48

We have code that mostly works filling polygons on a map, though it draws convex hulls and fills in some areas (will require tessellation).

The shader is given a set of triangle fan operations, and draws using hardcoded color yellow (and it works).

picture of US map with yellow hardcoded fill

Then we try to interpolate based on the value, and it turns black (does not work). same us map, shading from blue to red does not work

Here is the fragment shader. Values coming in are all 0.0 to 1.0 With minVal = 0.0, maxVal = 1.0 and colors set to (0,0,1) and (1,0,0) While I would appreciate knowing the bug, I would much more like to know how I can debug it. I need to be able to get the values in the shader and see what is happening. In short, I need some kind of debugging facility for GLSL. I did find NVIDIA nsight: https://developer.nvidia.com/nsight-graphics but could not get it working on linux.

#version 330 core
out vec4 FragColor;

//in vec2 TexCoord;
in float val;
//uniform sampler2D ourTexture;
uniform vec3 minColor;
uniform vec3 maxColor;
uniform float minVal;
uniform float maxVal;

void main()
{
    float f = (val - minVal)/ (maxVal-minVal);
    //FragColor = vec4(1,1,0,1);//texture(ourTexture, f);
    FragColor = vec4(minColor*(1.0-f) + maxColor * f,1.0);
}
1 Answers

It turns out that we were using glUniform4fv to set a color with rgba. There was no compile or runtime error. These calls do not have an error return that I know of.

The shader also did not generate an error, but the variables minColor and maxColor were not correctly set.

Thus the interpolation was always black.

vec4(minColor*(1.0-f) + maxColor * f,1.0);

There should have been an error, attempting to set an RGBA color into a vec3 variable.

I have found printf functions on stackoverflow that would have allowed viewing this kind of information: Convert floating-point numbers to decimal digits in GLSL

Related