Results 1 to 4 of 4

Thread: GLSL fragment shader problem

  1. #1
    Junior Member
    Join Date
    Apr 2009

    Default GLSL fragment shader problem

    I am using a fragment shader (below) to create a greyscale earth, but it's causing a problem with some tiles (see screenshot).

    Looks like the its sometimes using the texture coordinates from the neighbouring tile for some reason. Anyone had this problem or know how to solve it?

    Note the tiles are rendered correctly if I disable the shader.


    uniform sampler2D testTexture;
    void main( void )
    	vec4 texelColor = texture2D( testTexture, gl_TexCoord[0].xy );
    	vec4 greyWeights = vec4(0.3, 0.59, 0.11, 1.0);
    	vec4 scaledColor = texelColor * greyWeights;
    	float luminance = scaledColor.r + scaledColor.g + scaledColor.b;
    	gl_FragColor = vec4( luminance, luminance, luminance, texelColor.a );
    Attached Images Attached Images
    Last edited by jwheeler; 08-16-2010 at 02:37 PM. Reason: Clarification

  2. #2
    weekend warrior
    Join Date
    May 2008


    I'm not saying that this is your problem, but I have seen similar behavior on 'vanilla world' wind setups where the terrain data has become corrupted or when graphics driver updates are needed. You might trying deleting all of your elevation data and/or updating graphics drivers. It might just help

  3. #3
    Senior Member
    Join Date
    Jun 2007


    "Normal" World Wind rendering uses an alpha mask texture (through multi-texture rendering) so that it only renders the portion of the surface tile which is covered by the texture. That's how it combines several different textures of various sizes together to cover a tile.

    Once you use a shader, you no longer necessarily benefit from the alpha masking which all takes place in the fixed-function pipeline. So in your fragment shader, you need to discard any pixes for texture coords less than 0 or greater than 1.

    Something like:

    if (gl_TexCoord[0].s < 0 || gl_TexCoord[0].s > 1) discard;
    if (gl_TexCoord[0].t < 0 || gl_TexCoord[0].t > 1) discard;

  4. #4
    Junior Member
    Join Date
    Jan 2008
    Huntsville, AL


    I just came across this posting and it fixed an issue have been having since upgrading WWJ this week.. I had been using the version of world wind java from about May 2010, and it worked fine with my shader. I upgraded this week to the newest world wind java and started getting the same incorrectly rendered tile. Adding those 2 lines to my shader fixed the issue. Thanks.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts