我只在GLSL-ES 2.0(android)中使用我的着色器得到一个解析错误,它们在桌面上编译并运行良好。错误如下:
SGR(12584): Vertex shader compilation failed.
SGR(12584): ERROR: 0:397: '(' : Syntax error: syntax error
SGR(12584): ERROR: 1 compilation errors. No code generated.
SGR(12584): Fragment shader compilation failed.
SGR(12584): ERROR: 0:211: '(' : Syntax error: syntax error
SGR(12584): ERROR: 1 compilation errors. No code generated.
崩溃的行(在顶点和片段中)是main()方法之后的行。这是片段着色器:
////////////////////////////////////////////////////////////////////////////////////
////////// POSITION ATTRIBUTE - FRAGMENT
////////////////////////////////////////////////////////////////////////////////////
#define nop() {}
varying vec4 v_position;
vec4 g_position = vec4(0.0, 0.0, 0.0, 1.0);
#define pullPosition() (g_position = v_position)
////////////////////////////////////////////////////////////////////////////////////
////////// COLOR ATTRIBUTE - FRAGMENT
///////////////////////////////////////////////////////////////////////////////////
varying vec4 v_color;
vec4 g_color = vec4(1.0, 1.0, 1.0, 1.0);
#define pullColor() (g_color = v_color)
////////////////////////////////////////////////////////////////////////////////////
////////// NORMAL ATTRIBUTE - FRAGMENT
///////////////////////////////////////////////////////////////////////////////////
varying vec3 v_normal;
vec3 g_normal = vec3(0.0, 0.0, 1.0);
#define pullNormal() (g_normal = v_normal)
////////////////////////////////////////////////////////////////////////////////////
////////// BINORMAL ATTRIBUTE - FRAGMENT
///////////////////////////////////////////////////////////////////////////////////
varying vec3 v_binormal;
vec3 g_binormal = vec3(0.0, 0.0, 1.0);
#define pullBinormal() (g_binormal = v_binormal)
////////////////////////////////////////////////////////////////////////////////////
////////// TANGENT ATTRIBUTE - FRAGMENT
///////////////////////////////////////////////////////////////////////////////////
varying vec3 v_tangent;
vec3 g_tangent = vec3(1.0, 0.0, 0.0);
#define pullTangent() (g_tangent = v_tangent)
////////////////////////////////////////////////////////////////////////////////////
////////// TEXCOORD0 ATTRIBUTE - FRAGMENT
///////////////////////////////////////////////////////////////////////////////////
varying vec2 v_texCoord0;
vec2 g_texCoord0 = vec2(0.0, 0.0);
#define pullTexCoord0() (g_texCoord0 = v_texCoord0)
// Uniforms which are always available
uniform mat4 u_projViewTrans;
uniform mat4 u_worldTrans;
uniform vec4 u_cameraPosition;
uniform mat3 u_normalMatrix;
// Varyings computed in the vertex shader
varying float v_opacity;
varying float v_alphaTest;
// Other uniforms
#ifdef shininessFlag
uniform float u_shininess;
#else
const float u_shininess = 20.0;
#endif
#ifdef diffuseColorFlag
uniform vec4 u_diffuseColor;
#endif
#ifdef diffuseTextureFlag
uniform sampler2D u_diffuseTexture;
#endif
#ifdef specularColorFlag
uniform vec4 u_specularColor;
#endif
#ifdef specularTextureFlag
uniform sampler2D u_specularTexture;
#endif
#ifdef normalTextureFlag
uniform sampler2D u_normalTexture;
#endif
#ifdef emissiveTextureFlag
uniform sampler2D u_emissiveTexture;
#endif
#if defined(diffuseTextureFlag) || defined(specularTextureFlag)
#define textureFlag
#endif
#if defined(specularTextureFlag) || defined(specularColorFlag)
#define specularFlag
#endif
#if defined(specularFlag) || defined(fogFlag)
#define cameraPositionFlag
#endif
#if defined(ambientLightFlag) || defined(ambientCubemapFlag) || defined(sphericalHarmonicsFlag)
#define ambientFlag
#endif //ambientFlag
#ifdef shadowMapFlag
uniform sampler2D u_shadowTexture;
uniform float u_shadowPCFOffset;
varying vec3 v_shadowMapUv;
#define separateAmbientFlag
float getShadowness(vec2 offset)
{
const vec4 bitShifts = vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 160581375.0);
return step(v_shadowMapUv.z, dot(texture2D(u_shadowTexture, v_shadowMapUv.xy + offset), bitShifts)); //+(1.0/255.0));
}
float getShadow()
{
return (//getShadowness(vec2(0,0)) +
getShadowness(vec2(u_shadowPCFOffset, u_shadowPCFOffset)) +
getShadowness(vec2(-u_shadowPCFOffset, u_shadowPCFOffset)) +
getShadowness(vec2(u_shadowPCFOffset, -u_shadowPCFOffset)) +
getShadowness(vec2(-u_shadowPCFOffset, -u_shadowPCFOffset))) * 0.25;
}
#endif //shadowMapFlag
// AMBIENT LIGHT
varying vec3 v_ambientLight;
#define getAmbientLight() (v_ambientLight)
// COLOR DIFFUSE
#if defined(diffuseTextureFlag) && defined(diffuseColorFlag)
#define fetchColorDiffuseTD(texCoord, defaultValue) texture2D(u_diffuseTexture, texCoord) * u_diffuseColor
#elif defined(diffuseTextureFlag)
#define fetchColorDiffuseTD(texCoord, defaultValue) texture2D(u_diffuseTexture, texCoord)
#elif defined(diffuseColorFlag)
#define fetchColorDiffuseTD(texCoord, defaultValue) u_diffuseColor
#else
#define fetchColorDiffuseTD(texCoord, defaultValue) (defaultValue)
#endif // defined(diffuseTextureFlag) && defined(diffuseColorFlag)
#define fetchColorDiffuseD(defaultValue) fetchColorDiffuseTD(g_texCoord0, defaultValue)
#define fetchColorDiffuse() fetchColorDiffuseD(vec4(1.0))
#if defined(diffuseTextureFlag) || defined(diffuseColorFlag)
#define applyColorDiffuse(baseColor) ((baseColor) * fetchColorDiffuse())
#else
#define applyColorDiffuse(baseColor) (baseColor)
#endif // defined(diffuseTextureFlag) || defined(diffuseColorFlag)
// COLOR NIGHT
#if defined(emissiveTextureFlag)
#define fetchColorNightTD(texCoord, defaultValue) texture2D(u_emissiveTexture, texCoord)
#else
#define fetchColorNightTD(texCoord, defaultValue) (defaultValue)
#endif // defined(emissiveTextureFlag)
#define fetchColorNightD(defaultValue) fetchColorNightTD(g_texCoord0, defaultValue)
#define fetchColorNight() fetchColorNightD(vec4(0.0))
#if defined(emissiveTextureFlag)
#define applyColorNight() fetchColorNight()
#else
#define applyColorNight() vec4(0.0)
#endif // defined(emissiveTextureFlag)
// COLOR SPECULAR
#if defined(specularTextureFlag) && defined(specularColorFlag)
#define fetchColorSpecularTD(texCoord, defaultValue) (texture2D(u_specularTexture, texCoord).rgb * u_specularColor.rgb)
#elif defined(specularTextureFlag)
#define fetchColorSpecularTD(texCoord, defaultValue) texture2D(u_specularTexture, texCoord).rgb
#elif defined(specularColorFlag)
#define fetchColorSpecularTD(texCoord, defaultValue) u_specularColor.rgb
#else
#define fetchColorSpecularTD(texCoord, defaultValue) (defaultValue)
#endif // defined(specularTextureFlag) && defined(specularColorFlag)
#define fetchColorSpecularD(defaultValue) fetchColorSpecularTD(g_texCoord0, defaultValue)
#define fetchColorSpecular() fetchColorSpecularD(vec3(0.0))
#if defined(specularTextureFlag) || defined(specularColorFlag)
#define applyColorSpecular(intensity) ((intensity) * fetchColorSpecular())
#define addColorSpecular(baseColor, intensity) ((baseColor) + applyColorSpecular(intensity))
#else
#define applyColorSpecular(intensity) (vec3(0.0))
#define addColorSpecular(baseColor, intensity) (baseColor)
#endif // defined(specularTextureFlag) || defined(specularColorFlag)
varying vec3 v_lightDir;
varying vec3 v_lightCol;
varying vec3 v_viewDir;
#ifdef environmentCubemapFlag
varying vec3 v_reflect;
#endif
#ifdef environmentCubemapFlag
uniform samplerCube u_environmentCubemap;
#endif
#ifdef reflectionColorFlag
uniform vec4 u_reflectionColor;
#endif
#define saturate(x) clamp(x, 0.0, 1.0)
void main() {
pullColor();
pullTexCoord0();
vec4 diffuse = applyColorDiffuse(g_color);
vec4 night = applyColorNight();
vec3 specular = fetchColorSpecular();
vec3 ambient = getAmbientLight();
#ifdef normalTextureFlag
vec4 N = vec4(normalize(texture2D(u_normalTexture, g_texCoord0).xyz * 2.0 - 1.0), 1.0);
#ifdef environmentCubemapFlag
vec3 reflectDir = normalize(v_reflect + (vec3(0.0, 0.0, 1.0) - N.xyz));
#endif // environmentCubemapFlag
#else
vec4 N = vec4(0.0, 0.0, 1.0, 1.0);
#ifdef environmentCubemapFlag
vec3 reflectDir = normalize(v_reflect);
#endif // environmentCubemapFlag
#endif // normalTextureFlag
// see http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter05.html
vec3 L = normalize(v_lightDir);
vec3 V = normalize(v_viewDir);
vec3 H = normalize(L + V);
float NL = dot(N.xyz, L);
float NH = max(0.0, dot(N.xyz, H));
float specOpacity = 1.0; //(1.0 - diffuse.w);
float spec = min(1.0, pow(NH, 10.0) * specOpacity);
float selfShadow = saturate(4.0 * NL);
#ifdef environmentCubemapFlag
vec3 environment = textureCube(u_environmentCubemap, reflectDir).rgb;
specular *= environment;
#ifdef reflectionColorFlag
diffuse.rgb = saturate(vec3(1.0) - u_reflectionColor.rgb) * diffuse.rgb + environment * u_reflectionColor.rgb;
#endif // reflectionColorFlag
#endif // environmentCubemapFlag
#ifdef shadowMapFlag
vec3 dayColor = (v_lightCol * diffuse.rgb) * NL * getShadow() + (ambient * diffuse.rgb) * (1.0 - NL);
vec3 nightColor = (v_lightCol * night.rgb) * (0.7 - NL) * getShadow();
gl_FragColor = vec4(dayColor + nightColor, diffuse.a * v_opacity);
#else
vec3 dayColor = (v_lightCol * diffuse.rgb) * NL
+ (ambient * diffuse.rgb) * (1.0 - NL);
vec3 nightColor = (v_lightCol * night.rgb) * (0.7 - NL);
gl_FragColor = vec4(dayColor + nightColor, diffuse.a * v_opacity);
#endif // shadowMapFlag
gl_FragColor.rgb += (selfShadow * spec) * specular;
}
我看不出任何坏事。我发现了很多Syntax error: syntax error
个帖子但到目前为止没有运气。
答案 0 :(得分:2)
您#defined pullColor()
为(g_color = v_color)
,因此在预处理器完成后,您的代码如下所示:
void main() {
(g_color = v_color);
//...
所以你开始用括号括起来,这是一个错误。