GLSL problem with hardware?

bernardo's picture

hey guys goodnight. i have these wicked black rectangles appearing randomly on models inside QC. the shader is a simple on with a point light moving around please check the attached jpeg. the vertex code:

varying vec4 diffuse,ambientGlobal,ambient;
varying vec3 normal,lightDir,halfVector;
varying float dist;
 
uniform vec3 LightPosition;
 
 
void main()
{
   vec4 ecPos;
   vec3 aux;
   normal = normalize(gl_NormalMatrix * gl_Normal);
 
        /* these are the new lines of code to compute the light's direction */
   vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Vertex);
   //aux = vec3(LightPosition - ecPos);
   lightDir = normalize(LightPosition - ecPosition);
   dist = length(aux);
   halfVector = normalize(gl_LightSource[0].halfVector.xyz);
 
        /* Compute the diffuse, ambient and globalAmbient terms */
   diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
   /* The ambient terms have been separated since one of them */
 
   /* suffers attenuation */
   ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
   ambientGlobal = gl_LightModel.ambient * gl_FrontMaterial.ambient;
   gl_Position = ftransform();
 
}

fragment

varying vec4 diffuse,ambientGlobal,ambient;
varying vec3 normal,lightDir,halfVector;
varying float dist;
 
void main()
{
   vec3 n,halfV,viewV,ldir;
   float NdotL,NdotHV;
   vec4 color = ambientGlobal;
   float att;
   /* a fragment shader can't write a varying variable, hence we need
 
   a new variable to store the normalized interpolated normal */
   n = normalize(normal);
   /* compute the dot product between normal and normalized lightdir */
 
   NdotL = max(dot(n,normalize(lightDir)),0.0);
   if (NdotL > 0.0) {
 
      att = 1.0 / (gl_LightSource[0].constantAttenuation +
            gl_LightSource[0].linearAttenuation * dist +
            gl_LightSource[0].quadraticAttenuation * dist * dist);
      color += att * (diffuse * NdotL + ambient);
      halfV = normalize(halfVector);
 
      NdotHV = max(dot(n,halfV),0.0);
      color += att * gl_FrontMaterial.specular * gl_LightSource[0].specular *
                  pow(NdotHV,gl_FrontMaterial.shininess);
   }
   gl_FragColor = color;
}
PreviewAttachmentSize
error_A.jpg
error_A.jpg1.38 MB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

bernardo's picture
Re: GLSL problem with hardware?

my hardware is macbook pro with Nvidia geforce 8600gt graphics...

bernardo's picture
TONEBURST can you helpRe: GLSL problem with hardware?

hey tb, can you help? i get some weird looking black faces in my geometry as if something was wrong with the shader? can you teach what it is thanks bern

cybero's picture
Re: GLSL problem with hardware?

I am unable to reproduce the problem you report. Do you get any Console messages? The code provided renders fairly well, although edges are generally jaggy. What are the Light Position factors you employed? When I replaced the Teapot patch with a GLSL Grid patch, I got some odd results. See attached movie, very short. :-)

PreviewAttachmentSize
oddshaderaction.mov1.22 MB

cybero's picture
Re: GLSL problem with hardware?

I am unable to reproduce the problem you report. Do you get any Console messages? The code provided renders fairly well, although edges are generally jaggy. What are the Light Position factors you employed? When I replaced the Teapot patch with a GLSL Grid patch, I got some odd results. See attached movie, very short. :-) I must admit, I'm liking the unintended glitching. The rotation of the Grid is set at -90 within a Trackball.

bernardo's picture
Re: GLSL problem with hardware?

YES! cybero thats it exactly!!!! if you like it please do keep it! i like it too but not for now. As for the console no message here. as for the "Light Position factors" i use x:1 y:1: z:1 for the light position is that what you meant for factors?

cybero's picture
Re: GLSL problem with hardware?

exactly on the factors

bernardo's picture
Re: GLSL problem with hardware?

ok so factors=light XYZ?

gtoledo3's picture
Re: GLSL problem with hardware?

Where's the sample composition?

This shader is reading gl light source, so you have to place it in a Lighting Environment, as a starting point, to see if it works correctly. Are you doing that?

bernardo's picture
Re: GLSL problem with hardware?

well i can't i define the light inside the GLSL shader without the lightning patch? the light source is define inside the shader. because sample patchs from the lyb don't use it.

bernardo's picture
Re: GLSL problem with hardware?

as for openGL shader builder gives the same error....

bernardo's picture
Re: GLSL problem with hardware?

ahhh the comp... sorry

PreviewAttachmentSize
broto_glsl_PointLightKineme.qtz15.78 KB

gtoledo3's picture
Re: GLSL problem with hardware?

A shader can read the values from a GL Light source, any number of which are able to be specified by GL spec (I think it's 8?).

So, some shaders are designed to do so, and do "other stuff", in the shader, when the contribution of a gl light source is present. Sure, some shaders do all of the lighting, etc., but that's not the case here.

For instance, in the vertex shader, where it says: halfVector = normalize(gl_LightSource[0].halfVector.xyz);

...it's "asking" for value from a gl light source, there, as well as other places in the vertex shader, and also in the fragment shader. In QC, that's supplied by the Lighting Environment stock patch.

By the way, two really good examples of shaders that take advantage of reading the light position from a Lighting environment, and doing some fancy shader stuff, are cwright's normal map demo I and II.

bernardo's picture
Re: GLSL problem with hardware?

ahhh mr. gt3 thank you very much. i am trying to learn from cwrights normals!! its a long path for me... hugs bernardo