Re: Weird shader behavior: discard in one shader causes gl_Normal to be 0 in another

"Peter Dobrev" <[email protected]> Thu, 11 Dec 2008 07:05:26 -0800
Newsgroups gmane.games.devel.opengl
Organization Fat City Network Services, San Diego, California
Message-ID <[email protected]>
OK, the problem was the following.
"marked" is a varying variable that just transfers the value of the
marked attribute variable from the vertex shader to the fragment.
When the line with the "discard" is commented, the shader compiler
determines that "marked" is not used anywhere, hence there is no point
to transfer its value from the vertex shader, hence the attribute
value in the vertex shader also doesn't have any meaning. So, OpenGL
assigned an invalid handle to the attributeLocation and the attribute
wasn't used.

When the lines are not commented, the values for the attribute
variable are actually passed in an array, and since I forgot to
disable it afterwards, it got carried onto the rendering shader,
messing up the normal.

So, in fact, the problem was that i didn't disable the attribute array
after the shader had done its job.


Sorry for the bother!

Best regards,
Petar.

2008/12/11 Peter Dobrev <[email protected]>:
> Hello!
>
> I have a really strange (at least to me) problem with a bunch of glsl shaders.
> So, this is my workflow:
> - I'm rendering a point cloud (glPointSize=1) and first want to mark some points
> - I do a bunch of rendering passes marking the points and after each
> pass I discard the points that have been marked in previous runs. This
> I can do in two ways:
>    - manually remove the marked points from the dataset after each
> rendering (slow)
>    - pass a vertex array containing information about which point has
> already been marked and use a simple test in the shader like
>         if (marked == 1)
>              discard;
> - After the marking process, I do a completely different rendering
> with visualization purposes (and not marking), with a different pair
> or shaders and from a different viewpoint.
>
> The problem:
> If I use discard; in the marking fragment shader, I get that gl_Normal
> is always 0 in the rendering shader, even though I'm passing non-zero
> normals along the geometry.
>
> If I manually remove the marked points from the dataset, everything
> works out fine and the normals are non-zero.
>
> No GL errors, no shader warnings.
>
> Any clue would be highly appreciated!
>
> Petar.
> -----
> FAQ and OpenGL Resources at:
>  http://www.geocities.com/SiliconValley/Hills/9956/OpenGL
>
> --
> Author: Peter Dobrev
>  INET: [email protected]
>
> Fat City Hosting, San Diego, California -- http://www.fatcity.com
> ---------------------------------------------------------------------
> To REMOVE yourself from this mailing list, send an E-Mail message
> to: [email protected] (note EXACT spelling of 'ListGuru') and in
> the message BODY, include a line containing: UNSUB OPENGL-GAMEDEV-L
> (or the name of mailing list you want to be removed from).  You may
> also send the HELP command for other information (like subscribing).
>
----- 
FAQ and OpenGL Resources at:
  http://www.geocities.com/SiliconValley/Hills/9956/OpenGL

-- 
Author: Peter Dobrev
  INET: [email protected]

Fat City Hosting, San Diego, California -- http://www.fatcity.com
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: [email protected] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB OPENGL-GAMEDEV-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).