GLSL -- models invisible in latest dev builds

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