Search code examples
openglvertex-shadergameplay3d

GLSL shader syntax error unexpected tokens following the preprocessor directive - expected a newline


I'm trying to modify the shader 'textured.vert' taken from samples of GamePlay3d, but get following error:

ERROR: 0:108: '' : syntax error incorrect preprocessor directive
ERROR: 0:108: '' : syntax error unexpected tokens following the preprocessor directive - expected a newline
ERROR: 0:112: '' : syntax error incorrect preprocessor directive
ERROR: 0:112: '' : syntax error unexpected tokens following the preprocessor directive - expected a newline
ERROR: 0:120: '' : syntax error incorrect preprocessor directive
ERROR: 0:120: '' : syntax error unexpected tokens following the preprocessor directive - expected a newline

EDIT: if revert the first 12 lines, it works!:

#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

The code of shader which modified:

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

Solution

  • The problem is, that you use the constants SPOT_LIGHT_COUNT and POINT_LIGHT_COUNT in lighting.vert

    For example lighting.vert:46

    #if (POINT_LIGHT_COUNT > 0)
    

    will not compile when POINT_LIGHT_COUNT cannot be replaced.

    You can either define the two constants as already done in the original file, or you cleanup the references to them in lighting.vert