GLSL -- models invisible in latest dev builds

Hi,

There seems to be a problem with GLSL in the new buildbot builds or the way I wrote my GLSL shaders to work with 1.8 and older dev builds simply no longer works – which is a possibility, since for all I know, I’ve unknowingly used a workaround (p3d_ instead of gl_).

Anyway, the test program below works perfectly fine in 1.8, but when run with a recent dev build, the meshes are just not shown at all.

The bad news is that there’s not a single error message, so I’m kind of lost as to how to debug it… It’s as if the shader was loaded and executed properly, but worked in a different way than in 1.8.

dl.dropbox.com/u/196274/glslshaders.zip

For the record, I tested that on both Linux (Ubuntu 12.04 64bit) and Windows (7 64bit) with the same result.

GLSL shaders in CVS are currently broken. First off you need this patch, which hasn’t yet made it into the sourceforge repository: panda3d.org/forums/viewtopic … ght=#90190

Running your sample I get the same results with either the stock 1.8.0 build or a build of the latest from CVS w/the above patch: no errors or warnings, and a black sphere in the middle of the window.

Digging deeper:

  1. editor_shade_f.glsl(line 33):
FragCoord = vec4(tangentEyeVector, 1.0);

This is “masking” all of the other FragCoord computations above. Since this one line computes the final value for FragCoord, everything else – including “selectedColor” and “albedo” – are optimized away because they’re not needed.

  1. Removing line 33 causes the GLSL compiler to generate errors. The cause of this is line 9:
uniform in sampler2D p3d_Texture0;

The “in” is breaking this. Removing it (and three more instances) so that it’s just “uniform sampler …” fixes the GLSL compiler warning. At this point I get a solid white sphere instead of a solid black one.

  1. In main.py(line 11):
render.setShaderInput("selectedColor", Vec4())

This is passing an all-zero vector to the shader, causing it to execute the “selectedColor.a == 0.0” code path. Replacing with Vec4(0.0, 1.0, 0.0, 1.0) gets me an all-green sphere, as I’d expect.

  1. There’s a similar problem going on with setMaterial(Material()), i.e. initializing to a default null-value. In editor_shade_f.glsl I changed this:
if (selectedColor.a == 0.0) {
    FragCoord = albedo * gl_FrontMaterial.diffuse;
    FragCoord += gl_FrontMaterial.emission;
}

to this:

if (selectedColor.a == 0.0) {
    FragCoord = mapNormal;
}

I also changed my initialization of selectedColor to Vec4(0.0, 1.0, 0.0, 0.0) (note alpha is 0.0). I’d expect to see some kind of texture, but instead now get a blue sphere.

  1. In editor_shade_v.glsl(line 23):
    vec2 texcoordDefault = p3d_MultiTexCoord0.xy;

The “vec2” in this line is causing it to declare a new variable, hiding the output variable declared above. Removing the vec2 from this line gets me a sphere with what looks like a jigsaw-puzzle normal map. Note there there are several more instances of local variables hiding output variables (tangentNormal, etc.).

Note that all of these changes apply to both the stock 1.8.0 build and the patched CVS build, so even though the current CVS is broken it would have been possible to locate these additional issues with stock 1.8.0.

In any event, at this point, seeing a texture, I declared it to be “working” and leave further debugging and enhancement up to you. :wink:

–jonah

Thanks for the reply, 11thPenguin

@1 – Crap, it should be *=, but I was trying to figure out if I can at least display this vector
value… and then I forgot to change it back. And I have no idea why I called that FragCoord instead of FragColor, but that’s less important :stuck_out_tongue:.

@2 – Another case of the above. I should really quadruple-check stuff before I post it…

@3 – Actually, this is correct. The color should only be displayed when this is non-zero, otherwise the mesh should be displayed with a kind of normal mapping (looking more or less as if you had a light attached to the camera).

@4 – this is also correct.

@5 – while this is, again, me checking stuff and forgetting to change it back… Sorry. I’ll revert all those changes and update the zip to what it should’ve contained.

Anyway, I know that this shader worked in earlier dev builds, I even sent it to rdb and he confirmed. I don’t really feel like building Panda myself, so I’ll just wait for the patch to make it into a dev build.

Thanks again!

EDIT: Updated the download.