shader问题

//
// --------- Custom Shaders ---------
// Particle System
//
#define STRINGIFY(A) #A

static const GLchar* _particleShaderVert = STRINGIFY(
attribute vec4 a_position;
uniform float u_size;

void main()
{
gl_Position = CC_PMatrix * CC_MVMatrix * a_position;
gl_PointSize = CC_MVMatrix[0][0] * u_size * 1.5;
}
);

// Fragment shader
static const GLchar* _particleShaderFrag = STRINGIFY(

#ifdef GL_ES
precision lowp float;
#endif

void main()
{
gl_FragColor = texture2D(CC_Texture0, gl_PointCoord);
}
);

//
// --------- Custom Shaders ---------
// Render Texture
//

// Vertex shader
static const GLchar* _renderTextureShaderVert = STRINGIFY(
attribute vec4 a_position;
attribute vec2 a_texCoord;
attribute vec4 a_color;

#ifdef GL_ES
varying lowp vec4 v_fragmentColor;
varying mediump vec2 v_texCoord;
#else
varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
#endif

void main()
{
gl_Position = CC_PMatrix * a_position;
v_fragmentColor = a_color;
v_texCoord = a_texCoord;
}
);

// Fragment shader
static const GLchar* _renderTextureShaderFrag = STRINGIFY(

#ifdef GL_ES
precision lowp float;
#endif

varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
uniform float u_threshold_discard;
uniform float u_threshold_border;

void main()
{
gl_FragColor = v_fragmentColor * texture2D(CC_Texture0, v_texCoord);
vec4 color = v_fragmentColor * texture2D(CC_Texture0, v_texCoord);
if( color.r < u_threshold_discard)
// black or discard
color = vec4(0,0,0,0);
else if( color.r < u_threshold_border)
// blue for the border
color = vec4(0.2,0.2,0.9,0);
else
// white for the center
color = vec4(1,1,1,1);
gl_FragColor = color;
});

以上shader在iOS上可以编译,但是切换到mac平台,则编译出错。
cocos2d: ERROR: Failed to compile shader:
uniform mat4 CC_PMatrix;
uniform mat4 CC_MultiViewPMatrix[4];
uniform mat4 CC_MVMatrix;
uniform mat4 CC_MVPMatrix;
uniform mat4 CC_MultiViewMVPMatrix[4];
uniform mat3 CC_NormalMatrix;
uniform vec4 CC_Time;
uniform vec4 CC_SinTime;
uniform vec4 CC_CosTime;
uniform vec4 CC_Random01;
uniform sampler2D CC_Texture0;
uniform sampler2D CC_Texture1;
uniform sampler2D CC_Texture2;
uniform sampler2D CC_Texture3;
//CC INCLUDES END

void main() { gl_FragColor = texture2D(CC_Texture0, gl_PointCoord); }

cocos2d: ERROR: 0:17: Use of undeclared identifier ‘gl_PointCoord’

cocos2d: ERROR: Failed to compile fragment shader
Assert failed: invalid shader
Assertion failed: (glprogram), function init, file /Users/xiaobei/Project/helloworld//cocos2d/cocos/renderer/CCGLProgramState.cpp, line 484.

cocos2d-x3.6和cocos2d-x3.16都不行

可以看下这个讨论:https://github.com/cocos2d/cocos2d-x-samples/issues/32

For windows

add \n for macro in shader content of LFParticleSystemNode.cpp,windows default line break is not \n but \r\n
add glEnable(GL_POINT_SPRITE) in AppDelegate.cpp. You have to enable GL_POINT_SPRITE in windows platform to let gl_PointCoord’s be right, otherwise, gl_PointCoord’s value will be zero.

For mac

Add code snippet in “GLProgram::compileShader” for compile shader in mac correctly.

#elif (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
#version 120\n”,
#endif

谢谢!!