首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GLSL着色器语法错误--在预处理器指令之后出现意外标记--需要换行符。

GLSL着色器语法错误--在预处理器指令之后出现意外标记--需要换行符。
EN

Stack Overflow用户
提问于 2014-10-19 18:21:22
回答 1查看 2.9K关注 0票数 1

我试图修改从textured.vert样本中提取的着色器‘GamePlay3d’,但是得到了以下错误:

错误: 0:108:'‘:语法错误,不正确的预处理器指令 错误: 0:108:“‘:语法错误-在预处理器指令之后出现意外标记-需要换行符 错误: 0:112:'‘:语法错误,不正确的预处理器指令 错误: 0:112:“‘:语法错误--在预处理器指令之后出现意外标记--需要一个换行符 错误: 0:120:'‘:语法错误,不正确的预处理器指令 错误: 0:120:‘:语法错误--在预处理器指令之后出现意外标记--需要换行符

编辑:如果还原前12行,它可以工作!:

代码语言:javascript
复制
#ifndef DIRECTIONAL_LIGHT_COUNT
#define DIRECTIONAL_LIGHT_COUNT 0
#endif
#ifndef SPOT_LIGHT_COUNT
#define SPOT_LIGHT_COUNT 0
#endif
#ifndef POINT_LIGHT_COUNT
#define POINT_LIGHT_COUNT 0
#endif
#if (DIRECTIONAL_LIGHT_COUNT > 0) || (POINT_LIGHT_COUNT > 0) || (SPOT_LIGHT_COUNT > 0)
#define LIGHTING
#endif

修改后的着色代码:

代码语言:javascript
复制
#ifndef DIRECTIONAL_LIGHT_COUNT
#define DIRECTIONAL_LIGHT_COUNT 0
#endif
#if (DIRECTIONAL_LIGHT_COUNT > 0)
#define LIGHTING
#endif

///////////////////////////////////////////////////////////
// Atributes
attribute vec3 a_position;

#if defined(LIGHTING)

#if defined(BUMPED)
attribute vec3 a_tangent;
attribute vec3 a_binormal;
#endif

#endif

///////////////////////////////////////////////////////////
// Uniforms
uniform mat4 u_worldViewProjectionMatrix;

#if defined(LIGHTING)
uniform mat4 u_inverseTransposeWorldViewMatrix;

#if defined(SPECULAR)
uniform mat4 u_worldViewMatrix;
#endif

#if defined(BUMPED) && (DIRECTIONAL_LIGHT_COUNT > 0)
uniform vec3 u_directionalLightDirection[DIRECTIONAL_LIGHT_COUNT];
#endif

#if defined(SPECULAR)
uniform vec3 u_cameraPosition;
#endif

#endif

#if defined(TEXTURE_OFFSET)
uniform vec2 u_textureOffset;
#endif

///////////////////////////////////////////////////////////
// Varyings
varying vec3 v_texCoord;

#if defined(LIGHTING)

#if !defined(BUMPED)
varying vec3 v_normalVector;
#endif

#if defined(BUMPED) && (DIRECTIONAL_LIGHT_COUNT > 0)
varying vec3 v_directionalLightDirection[DIRECTIONAL_LIGHT_COUNT];
#endif

#if defined(SPECULAR)
varying vec3 v_cameraDirection;
#endif

#include "lighting.vert"

#endif

void main()
{
    vec4 position = vec4(a_position, 1.0);
    gl_Position = u_worldViewProjectionMatrix * position;

    #if defined(LIGHTING)
    vec3 normal = a_position;
    // Transform the normal, tangent and binormals to view space.
    mat3 inverseTransposeWorldViewMatrix = mat3(u_inverseTransposeWorldViewMatrix[0].xyz, u_inverseTransposeWorldViewMatrix[1].xyz, u_inverseTransposeWorldViewMatrix[2].xyz);
    vec3 normalVector = normalize(inverseTransposeWorldViewMatrix * normal);

    #if defined(BUMPED)

    vec3 tangent = a_tangent;
    vec3 binormal = a_binormal;
    vec3 tangentVector  = normalize(inverseTransposeWorldViewMatrix * tangent);
    vec3 binormalVector = normalize(inverseTransposeWorldViewMatrix * binormal);
    mat3 tangentSpaceTransformMatrix = mat3(tangentVector.x, binormalVector.x, normalVector.x, tangentVector.y, binormalVector.y, normalVector.y, tangentVector.z, binormalVector.z, normalVector.z);
    applyLight(position, tangentSpaceTransformMatrix);

    #else

    v_normalVector = normalVector;
    applyLight(position);

    #endif

    #endif

    v_texCoord = position;

    #if defined(TEXTURE_OFFSET)
    v_texCoord += u_textureOffset;
    #endif
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-19 19:33:45

问题是,您在SPOT_LIGHT_COUNT中使用了常量POINT_LIGHT_COUNT和lighting.vert

例如,lighting.vert:46

代码语言:javascript
复制
#if (POINT_LIGHT_COUNT > 0)

当POINT_LIGHT_COUNT无法替换时,将不会编译。

您可以像在原始文件中那样定义这两个常量,或者在lighting.vert中清除对它们的引用。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26453871

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档