I am a beginner in developing games. I started some time ago with OpenGL and the glsl language. These days I am having so many problems and for me it is too difficult to solve, because the shaders are not behaving logically, and there are sometimes absurd compilation errors, it is driving me crazy.

I was learning how to use the geometry shaders to improve the details of the 3d models by amplification the primitives. Once I had my program running, I saw that it worked well with a few primitives (I amplify all the triangles), but when I increased the number of them to a certain amount, it started to be glitchy. I have understood that the vertex output limits of the geometry shader are for each primitive, and not for the total vertex output of all the primitives together, but the maximum amount of primitives that the program could manage well, depends on how much I amplify with the geometry shader, for example if I output 75 vertex per primitive, the limit is 40 triangles, but for 300 vertex, it is 10 (75*40 = 300*10 = 3000). I was far below the geometry output limits, so I do not know what the problem is. But then I realized that if I did just a pass through the geometry shader, with a large amount of primitives it got glitchy as well, I couldn't know the exact limit of primitives that it could manage well in this case.

For that reason I tried to not use the geometry shader, but the situation got worse, because there is very strange behavior with variables and compilation. Here there are the shaders.

#version 330 core

attribute vec3  aPos;
attribute vec2  tex_coord;
attribute float tipo;
attribute float P2;
attribute vec3  fixed_pos2;

out vec4  color;
out float P_min;
out vec3  aPos3;

void main(){
    vec2  asdf1 = tex_coord;
    float tippy = tipo;
    float pepe  = P2;
    color = vec4(pepe, 0.0, 0.0, 1.);
    P_min = P2;
    aPos3 = aPos;

    vec3 aPos4 = aPos;

    float w = -aPos4.z;
    gl_Position    = vec4(aPos4.xyz, w);
    gl_Position.z *= -w;

and the fragment shader

#version 330 core

in vec4 color;
in float P_min;
in vec3 aPos3;
out vec4 FragColor;

uniform sampler2D ourTexture;
uniform vec4 posicion;

void main(){
    float coseno, angulo, modulo, P;
    vec3 aPos;
    FragColor = color;

    FragColor.x = abs(P_min)/5.;
    FragColor.y = abs(P_min)/5.;
    FragColor.z = abs(P_min)/5.;

As you can see, the code is very simple and there are ridiculous things, but sincerely I don't know what more to do, because it matters if I put "*0.2" instead of "/5." for example, that it could be not compiled. Now for example with this code, the value for "P2" in the vertex shader is always 5. for all the vertex. So, P_min = P2 (vertex shader), and then in the fragment shader the color should be vec4(1., 1., 1., 1.) white. But it is not, the color even depends on the value that I put in the vertex shader in the line 17, if I change "pepe". And it shouldn't depend on that, since it only depends on the value of P_min. Sincerely I do not know what to do, because of all this illogical behaviour the experiments that I do to find out what is happening have no sense, and I cannot deduce anything. Sorry for my English, and thank you in advance, your help is very appreciated.

  • \$\begingroup\$ Apparently it was solved thanks to a driver update. Thank you anyway! \$\endgroup\$ – Agustín Oct 17 '18 at 14:09

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.