1

It's really strange:

here are some log:

OpenGL Version = 4.1 INTEL-10.2.40
vs shaderid = 1, file = shaders/pointlight_shadow.vert
- Shader 1 (shaders/pointlight_shadow.vert) compile error: ERROR: 0:39: Use of undeclared identifier 'gl_LightSource'

BTW, I'm using C++/OpenGL/GLFW/GLEW on Mac OS X 10.10. Is there a way to check all the versions or attributes required to use "gl_LightSource" in the shader language?

Shader file:

#version 330

// Input vertex data, different for all executions of this shader.
layout(location = 0) in vec3 vertexPosition_modelspace;
layout(location = 1) in vec2 vertexUV;
layout(location = 2) in vec3 vertexNormal_modelspace;
layout(location = 3) in vec3 vertexTangent_modelspace;
layout(location = 4) in vec3 vertexBitangent_modelspace;


out vec4 diffuse,ambientGlobal, ambient;
out vec3 normal,lightDir,halfVector;
out float dist;
out vec3 fragmentcolor;
out vec4 ShadowCoord;

//Model, view, projection matrices
uniform mat4 MVP;
uniform mat4 V;
uniform mat4 M;
uniform mat3 MV3x3;
uniform mat4 DepthBiasMVP;

void main()
{   
    //shadow coordinate in light space...
    ShadowCoord = DepthBiasMVP * vec4(vertexPosition_modelspace,1);

    // first transform the normal into camera space and normalize the result
    normal = normalize(MV3x3 * vertexNormal_modelspace);

    // now normalize the light's direction. Note that according to the
    // OpenGL specification, the light is stored in eye space.
    gl_Position = MVP * vec4(vertexPosition_modelspace,1);
    vec3 vertexPosition_worldspace = (M * vec4(vertexPosition_modelspace,1)).xyz;
    vec3 vertexPosition_cameraspace = ( V * M * vec4(vertexPosition_modelspace,1)).xyz; 

    //light
    vec3 light0_camerapace = (V* vec4(gl_LightSource[0].position.xyz,1) ).xyz;
    vec3 L_cameraspace= light0_camerapace-vertexPosition_cameraspace;
    lightDir = normalize(L_cameraspace);


    // compute the distance to the light source to a varying variable
    dist = length(L_cameraspace);

    // Normalize the halfVector to pass it to the fragment shader 
    {

        // compute eye vector and normalize it 
        vec3 eye = normalize(-vertexPosition_cameraspace);

        // compute the half vector
        halfVector = normalize(lightDir + eye);
    }

    // Compute the diffuse, ambient and globalAmbient terms
    diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
    ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
    ambientGlobal = gl_LightModel.ambient * gl_FrontMaterial.ambient;
} 
Zhonghua Xi
  • 58
  • 1
  • 6

1 Answers1

5

You're not specifying a profile in your shader version:

#version 330

The default in this case is core, corresponding to the OpenGL core profile. On some platforms, you could change this to using the compatibility profile:

#version 330 compatibility

But since you say that you're working on Mac OS, that's not an option for you. Mac OS only supports the core profile for OpenGL 3.x and later.

The reason your shader does not compile with the core profile is that you're using a bunch of deprecated pre-defined variables. For example:

gl_FrontMaterial
gl_LightSource
gl_LightModel

All of these go along with the old style fixed function pipeline, which is not available anymore in the core profile. You will have to define your own uniform variables for these values, and pass the values into the shader with glUniform*() calls.

I wrote a more detailed description of what happened to built-in GLSL variables in the transition to the core profile in an answer here: GLSL - Using custom output attribute instead of gl_Position.

Community
  • 1
  • 1
Reto Koradi
  • 53,228
  • 8
  • 93
  • 133