簡體   English   中英

使用未聲明的標識符'gl_LightSource'

[英]Use of undeclared identifier 'gl_LightSource'

真的很奇怪:

這是一些日志:

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'

順便說一句,我在Mac OS X 10.10上使用C ++ / OpenGL / GLFW / GLEW。 有沒有辦法檢查着色器語言中使用“ gl_LightSource”所需的所有版本或屬性?

着色器文件:

#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;
} 

您未在着色器版本中指定配置文件:

#version 330

在這種情況下,默認值為core ,與OpenGL核心配置文件相對應。 在某些平台上,您可以將其更改為使用兼容性配置文件:

#version 330 compatibility

但是由於您說您正在Mac OS上工作,所以這不是您的選擇。 Mac OS僅支持OpenGL 3.x和更高版本的核心配置文件。

着色器無法與核心配置文件一起編譯的原因是,您使用了一堆不推薦使用的預定義變量。 例如:

gl_FrontMaterial
gl_LightSource
gl_LightModel

所有這些都與舊式的固定功能管道一起使用,該功能在核心配置文件中不再可用。 您將必須為這些值定義自己的統一變量,然后使用glUniform*()調用將這些值傳遞到着色器中。

我在以下答案中寫了更詳細的描述,其中介紹了內置GLSL變量在轉換為核心配置文件時發生了什么: GLSL-使用自定義輸出屬性代替gl_Position

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM