Loading...
Logo
Processing Forum

GLSL help

in Integration and Hardware  •  3 years ago  
I'm trying to troubleshoot some issues between nVidia and ATI.  nVidia is currently working fine, but my test ATI card (x1300) is having issues with point sprites.  I've updated to the latest driver and made many changes... perhaps someone could help and take a look.

Windows / ATI card is rendering the colors wrong and the texture is upside down.  Again, works fine on my MacBook (nVidia).

Vertex Shader
Copy code
  1. uniform float pointSize;
  2. uniform float gui;
  3. varying vec4 vFragColor;
  4. void main(void) {
  5.     gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
  6.     vec4 modv = vec4( gl_ModelViewMatrix * gl_Vertex );
  7.     if(gui == 0.0) {
  8.         gl_PointSize = 200.0 * pointSize/ -modv.z ;
  9.     } else {
  10.         gl_PointSize = pointSize;
  11.     }
  12.     float fog = 8000.0/ -modv.z;
  13.     if (fog < 8.0 && gui == 0.0) {
  14.          vFragColor = smoothstep(0.0, 8.0, fog) * gl_Color;
  15.     } else {
  16.         vFragColor = gl_Color;
  17.     }
  18.     gl_FrontColor = gl_Color;
  19.     gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
  20. }
Fragment Shader
Copy code
  1. uniform sampler2D tex;
  2. varying vec4 vFragColor;
  3. void main() {
  4.     vec4 color = texture2D(tex, gl_TexCoord[0].st);
  5.     gl_FragColor = color * vFragColor;
  6. }
Processing Code
Copy code
  1.  try {
        ringImg = TextureIO.newTexture(new File(dataPath("images" + File.separator + "ring2.png")), true);
      }
      catch (IOException e) {   
        showMessage(e);
      }
  2. ...
  3.       pshader.startShader();
  4.         gl.glUniform1f(pshader.getUniformLocation("gui"), 0.0);
  5.         gl.glDisable(GL.GL_POINT_SMOOTH);
  6.         gl.glEnable(GL.GL_POINT_SPRITE_ARB);
  7.         gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
  8.         gl.glEnableClientState(GL.GL_COLOR_ARRAY);
  9.         gl.glEnable(GL.GL_VERTEX_PROGRAM_POINT_SIZE_ARB);
  10.         gl.glPointParameterfARB( GL.GL_POINT_SIZE_MIN_ARB, 0.0 );
  11.         gl.glTexEnvi(GL.GL_POINT_SPRITE_ARB, GL.GL_COORD_REPLACE_ARB, GL.GL_TRUE);
  12.           gl.glBlendFunc(GL.GL_ONE,GL.GL_ONE_MINUS_SRC_ALPHA);
  13.           ringImg.enable();
  14.           ringImg.bind();
  15.           gl.glUniform1f(pshader.getUniformLocation("pointSize"), 114.0);
  16.           gl.glBindBuffer( GL.GL_ARRAY_BUFFER,  nodes_vbo[0]);
  17.           gl.glVertexPointer(3,GL.GL_FLOAT,0,0);
  18.           gl.glBindBuffer( GL.GL_ARRAY_BUFFER, nodes_vbo[1] );
  19.           gl.glColorPointer(3,GL.GL_FLOAT,0,0);
  20.           gl.glBindBuffer( GL.GL_ELEMENT_ARRAY_BUFFER, nelements_vbo[0] );
  21.           gl.glDrawElements( GL.GL_POINTS, vnodelength, GL.GL_UNSIGNED_INT, 0 );
  22.           gl.glDisableClientState(GL.GL_COLOR_ARRAY);
  23.           ringImg.disable();
  24.         gl.glDisable(GL.GL_POINT_SPRITE_ARB);
  25.         gl.glUniform1f(pshader.getUniformLocation("gui"), 1.0);
  26.         pshader.endShader();
  27. ...

Replies(9)

Re: GLSL help

3 years ago
It may not be the brand of GPU, but the brand of OS.

Consider glPixelZoom()?

kb, http://www.riftgame.com/

Re: GLSL help

3 years ago
Tested it on another Windows machine and it works fine.  It had a Nvidia Quadro card.  Tried setting gl.glPixelZoom(1.0, -1.0); but it didn't change anything.

Re: GLSL help

3 years ago
try moving the GL.GL_POINT_SPRITE_ARB declarations (or other enable/disable pairs) outside the startShader/endShader scope -- that is, to enclose it.

Just guessing, they should all be part of the same state block, but I suspect keeping the shader/end shader close to the actual emitted geometry would be a good idea.

kb, http://www.riftgame.com/

Re: GLSL help

3 years ago
What is the best practice when doing many draws with the same shader?  I set many of these things at the beging and end of the shader, but I go through 10 different draws using different image bindings.    Is it better to enable/disable the shader around each draw?  I've been just rebinding a new image updating the vertex and color pointers and redrawing.

So it goes something like this..

pgl.beginGL();
enable opengl stuff..
start shader

bind image
bind buffers and pointers
draw
unbind image

bind new image
bind buffers and pointers
draw
unbind image

bind new image
bind buffers and pointers
draw
unbind image

stop shader
disable opengl stuff
pgl.endGL();

Re: GLSL help

3 years ago
One issue I seem to be having is that the ATI card does not like my blend.  When I try to change the blending after doing some draws, it blanks out all further textures.

 gl.glBlendFunc(GL.GL_SRC_ALPHA,GL.GL_ONE);

Re: GLSL help

3 years ago
I fixed the color and blending issues, but my texture is still upside down.

I've set "gl.glPointParameterfARB(GL.GL_POINT_SPRITE_COORD_ORIGIN, GL.GL_UPPER_LEFT);"

All machines are set to GL.GL_UPPER_LEFT, however, the ATI card, while set to UPPER_LEFT only looks correct if I set it to LOWER_LEFT.

Here are my revised shaders.

Vertex
Copy code
  1. #version 110
  2. uniform float pointSize;
  3. uniform float gui;
  4. varying vec4 vFragColor;
  5. void main(void) {
  6.     gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
  7.     vec4 modv = vec4( gl_ModelViewMatrix * gl_Vertex );
  8.     vFragColor = gl_Color;
  9.     if(gui == 0.0) {
  10.         gl_PointSize = 200.0 * pointSize/ -modv.z;
  11.         float fog = 8000.0/ -modv.z;
  12.         if (fog < 8.0) {
  13.             vFragColor = smoothstep(0.0, 8.0, fog) * vFragColor;
  14.         }
  15.     } else {
  16.         gl_PointSize = pointSize;
  17.     }
  18. }
Fragment
Copy code
  1. #version 110
  2. uniform sampler2D tex;
  3. varying vec4 vFragColor;
  4. void main() {
  5.     gl_FragColor = texture2D(tex,gl_TexCoord[0].st) * vFragColor;
  6. }

Re: GLSL help

3 years ago
Great!

As a former NVIDIA marketer it might be mean to say that ATI's OpenGL drivers bite cheese. But: they do.

kb, http://www.riftgame.com/

Re: GLSL help

3 years ago
Indeed..
I've checked the ".getMustFlipVertically()" and they are both true.  I've check the first pixel in a b/w texture and they both report the correct orientation.  So it must be something to do with the coords as it get's written as a point sprite.  At this point, I think I'm going to try and abandon the reason and just try and test for it maybe drawing it into a buffer or something?  I can correct it, if I can figure out how to check for it.  Perhaps some use of get();

Re: GLSL help

3 years ago
Ok.. here is the work around I rigged up.  Not the prettiest thing, but it works. (also updated my glsl code above)
Also note that updating the ATI driver fixed the upside down texture, but I didn't find that out until later and I still wanted a work around for such issues to broaden hardware support.
Copy code
  1.   pgl.beginGL();
  2.   pshader.startShader();
  3.   gl.glUniform1f(pshader.getUniformLocation("gui"), 1.0);
  4.   gl.glUniform1f(pshader.getUniformLocation("pointSize"), 2.0);
  5.   gl.glEnable(GL.GL_POINT_SPRITE_ARB);
  6.   gl.glTexEnvi(GL.GL_POINT_SPRITE_ARB, GL.GL_COORD_REPLACE_ARB, GL.GL_TRUE);
  7.   fliporder.enable();
  8.   fliporder.bind();
  9.   gl.glColor3f(1,1,1);
  10.   gl.glBegin(GL.GL_POINTS);
  11.   gl.glVertex2f(0,1);
  12.   gl.glEnd();
  13.   fliporder.disable();
  14.   pshader.endShader();
  15.   loadPixels();
  16.   color pick = pixels[1*width+0];
  17.   if (red(pick) > 0.0) {
  18.     gl.glPointParameterfARB(GL.GL_POINT_SPRITE_COORD_ORIGIN, GL.GL_UPPER_LEFT);
  19.   }
  20.   else {
  21.     gl.glPointParameterfARB(GL.GL_POINT_SPRITE_COORD_ORIGIN, GL.GL_LOWER_LEFT);
  22.   }
  23.   fliporder = null;
  24.   pgl.endGL();