1

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
}
3
  • 1
    Are you sure that this is the shader you're trying to compile? It has 102 lines, and the reported errors are on lines 108, 112, and 120. Commented Oct 19, 2014 at 18:55
  • You have this #include "lighting.vert", so what is in there? And how do you handle the shader includes (and the whole shader loading)? Commented Oct 19, 2014 at 19:28
  • #includes are handled by Gameplay3Ds shader utilities. Commented Oct 19, 2014 at 19:35

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! Have commented out //#include "lighting.vert" before, but got the same error. Replacing this line with content of "lighting.vert" fix it. Why comment not works?
#include is not part of the glsl standard. Why commenting out is not working depends on how your shader-loader searches and replaces them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.