-- 获得数据内容[VSH]
function M:getDefaultVSH()
return
" \n\
attribute vec4 a_position; \n\
attribute vec2 a_texCoord; \n\
attribute vec4 a_color; \n\
\n\
#ifdef GL_ES \n\
varying lowp vec4 v_fragmentColor; \n\
varying mediump vec2 v_texCoord; \n\
#else \n\
varying vec4 v_fragmentColor; \n\
varying vec2 v_texCoord; \n\
#endif \n\
\n\
void main() \n\
{ \n\
gl_Position = CC_MVPMatrix * a_position; \n\
v_fragmentColor = a_color; \n\
v_texCoord = a_texCoord; \n\
} \n\
"
end
-- 获得数据内容[FSH][默认]
function M:getDefaultFSH()
return
" \n\
precision mediump float; \n\
uniform sampler2D u_Texture; \n\
uniform vec2 u_TextureCoordOffset[25]; \n\
varying vec2 v_texCoord; \n\
varying vec4 v_fragmentColor; \n\
\n\
void main(void) \n\
{ \n\
gl_FragColor = texture2D(u_Texture, v_texCoord.st); \n\
} \n\
"
end
-- 获得数据内容[FSH][模糊]
function M:getBlurFSH()
return
" \n\
precision mediump float; \n\
uniform sampler2D u_Texture; \n\
uniform vec2 u_TextureCoordOffset[25]; \n\
varying vec2 v_texCoord; \n\
varying vec4 v_fragmentColor; \n\
\n\
void main(void) \n\
{ \n\
vec4 sample[25]; \n\
\n\
for (int i = 0; i < 25; i++) \n\
{ \n\
sample[i] = texture2D(u_Texture, \n\
v_texCoord.st + u_TextureCoordOffset[i]); \n\
} \n\
//-------------------------------------------------------- \n\
// 1 3 1 \n\
// 3 1 3 / 11 \n\
// 1 3 1 \n\
\n\
//gl_FragColor = (sample[0] + (3.0*sample[1]) + sample[2] + \n\
// (3.0*sample[3]) + sample[4] + (3.0*sample[5]) + \n\
// sample[6] + (3.0*sample[7]) + sample[8]) / 11.0; \n\
//-------------------------------------------------------- \n\
// Gaussian weighting: \n\
// 1 4 7 4 1 \n\
// 4 16 26 16 4 \n\
// 7 26 41 26 7 / 273 (i.e. divide by total of weightings) \n\
// 4 16 26 16 4 \n\
// 1 4 7 4 1 \n\
\n\
gl_FragColor = ( \n\
(1.0 * (sample[0] + sample[4] + sample[20] + sample[24])) + \n\
(4.0 * (sample[1] + sample[3] + sample[5] + sample[9] + \n\
sample[15] + sample[19] + sample[21] + sample[23])) + \n\
(7.0 * (sample[2] + sample[10] + sample[14] + sample[22])) + \n\
(16.0 * (sample[6] + sample[8] + sample[16] + sample[18])) + \n\
(26.0 * (sample[7] + sample[11] + sample[13] + sample[17])) + \n\
(41.0 * sample[12]) \n\
) / 273.0; \n\
}"
end
-- 获得数据内容[FSH][磨砂]
function M:getSharpenFSH()
return
" \n\
precision mediump float; \n\
uniform sampler2D u_Texture; \n\
uniform vec2 u_TextureCoordOffset[25]; \n\
varying vec2 v_texCoord; \n\
varying vec4 v_fragmentColor; \n\
\n\
void main(void) \n\
{ \n\
vec4 sample[25]; \n\
\n\
for (int i = 0; i < 25; i++) \n\
{ \n\
sample[i] = texture2D(u_Texture, \n\
v_texCoord.st + u_TextureCoordOffset[i]); \n\
} \n\
//-------------------------------------------------------- \n\
// -1 -1 -1 \n\
// -1 9 -1 \n\
// -1 -1 -1 \n\
\n\
//gl_FragColor = (sample[4] * 9.0) - \n\
// (sample[0] + sample[1] + sample[2] + \n\
// sample[3] + sample[5] + \n\
// sample[6] + sample[7] + sample[8]); \n\
//-------------------------------------------------------- \n\
// Sharpen weighting: \n\
// 0 -1 -1 -1 0 \n\
// -1 2 -4 2 -1 \n\
// -1 -4 13 -4 -1 \n\
// -1 2 -4 2 -1 \n\
// 0 -1 -1 -1 0 \n\
\n\
//gl_FragColor = ( \n\
//(-1.0 * ( sample[1] + sample[2] + sample[3] + sample[5] + \n\
//sample[9] + sample[10] + sample[14] + sample[15] + \n\
//sample[19] + sample[21] + sample[22] + sample[23]) ) + \n\
//(2.0 * (sample[6] + sample[8] + sample[16] + sample[18])) + \n\
//(-4.0 *(sample[7] + sample[11] + sample[13] + sample[17]))+ \n\
//( 13.0 * sample[12] ) \n\
//); \n\
\n\
// 1 1 1 1 1 \n\
// 1 1 1 1 1 \n\
// 1 1 -14 1 1 \n\
// 1 1 1 1 1 \n\
// 1 1 1 1 1 \n\
\n\
gl_FragColor = -14.0 * sample[12]; \n\
\n\
for (int i = 0; i < 25; i++) \n\
{ \n\
if (i != 12) \n\
gl_FragColor += sample[i]; \n\
} \n\
gl_FragColor /= 14.0; \n\
}"
end
-- 获得数据内容[FSH][膨胀]
function M:getDilateFSH()
return
" \n\
precision mediump float; \n\
uniform sampler2D u_Texture; \n\
uniform vec2 u_TextureCoordOffset[25]; \n\
varying vec2 v_texCoord; \n\
varying vec4 v_fragmentColor; \n\
\n\
void main(void) \n\
{ \n\
vec4 sample[25]; \n\
vec4 maxValue = vec4(0.0); \n\
\n\
for (int i = 0; i < 25; i++) \n\
{ \n\
// Sample a grid around and including our texel \n\
sample[i] = texture2D(u_Texture, v_texCoord.st + u_TextureCoordOffset[i]); \n\
// Keep the maximum value \n\
maxValue = max(sample[i], maxValue); \n\
} \n\
\n\
gl_FragColor = maxValue; \n\
}"
end
-- 获得数据内容[FSH][侵蚀]
function M:getErodeFSH()
return
" \n\
precision mediump float; \n\
uniform sampler2D u_Texture; \n\
uniform vec2 u_TextureCoordOffset[25]; \n\
varying vec2 v_texCoord; \n\
varying vec4 v_fragmentColor; \n\
\n\
void main(void) \n\
{ \n\
vec4 sample[25]; \n\
vec4 minValue = vec4(1.0); \n\
\n\
for (int i = 0; i < 25; i++) \n\
{ \n\
// Sample a grid around and including our texel \n\
sample[i] = texture2D(u_Texture, v_texCoord.st + u_TextureCoordOffset[i]); \n\
// Keep the minimum value \n\
minValue = min(sample[i], minValue); \n\
} \n\
\n\
gl_FragColor = minValue; \n\
}"
end
-- 获得数据内容[FSH][Laplacian描边]
function M:getLaplacianEdgeDetectionFSH()
return
" \n\
precision mediump float; \n\
uniform sampler2D u_Texture; \n\
uniform vec2 u_TextureCoordOffset[25]; \n\
varying vec2 v_texCoord; \n\
varying vec4 v_fragmentColor; \n\
\n\
void main(void) \n\
{ \n\
vec4 sample[25]; \n\
\n\
for (int i = 0; i < 25; i++) \n\
{ \n\
// Sample a grid around and including our texel \n\
sample[i] = texture2D(u_Texture, v_texCoord.st + u_TextureCoordOffset[i]); \n\
} \n\
\n\
// Laplacian weighting: \n\
// -1 -1 -1 -1 -1 \n\
// -1 -1 -1 -1 -1 \n\
// -1 -1 24 -1 -1 \n\
// -1 -1 -1 -1 -1 \n\
// -1 -1 -1 -1 -1 \n\
\n\
gl_FragColor = 24.0 * sample[12]; \n\
\n\
for (int i = 0; i < 25; i++) \n\
{ \n\
if (i != 12) \n\
gl_FragColor -= sample[i]; \n\
} \n\
}"
end
-- 获得数据内容[FSH][Sobel边缘检测]
function M:getSobelEdgeDetectionFSH()
return
" \n\
precision mediump float; \n\
uniform sampler2D u_Texture; \n\
uniform vec2 u_TextureCoordOffset[25]; \n\
varying vec2 v_texCoord; \n\
varying vec4 v_fragmentColor; \n\
\n\
void main(void) \n\
{ \n\
vec4 sample[25]; \n\
\n\
for (int i = 0; i < 25; i++) \n\
{ \n\
sample[i] = texture2D(u_Texture, \n\
v_texCoord.st + u_TextureCoordOffset[i]); \n\
} \n\
// Sobel x: \n\
// 1 2 0 -2 -1 \n\
// 4 8 0 -8 -4 \n\
// 6 12 0 -12-6 / 12 \n\
// 4 8 0 -8 -4 \n\
// 1 2 0 -2 -1 \n\
// Sobel y: \n\
// -1 -4 -6 -4 -1 \n\
// -2 -8 -12-8 -2 \n\
// 0 0 0 0 0 / 12 \n\
// 2 8 12 8 2 \n\
// 1 4 6 4 1 \n\
\n\
vec4 vertEdge = sample[0] + 4.0 * sample[1] + \n\
6.0 * sample[2] + 4.0 * sample[3] + sample[4] + \n\
2.0 * sample[5] + 8.0 * sample[6] + 12.0 * sample[7] + \n\
8.0 * sample[8] + 2.0 * sample[9] - 2.0 * sample[15] - \n\
8.0 * sample[16] - 12.0 * sample[17] - 8.0 * sample[18] - \n\
2.0 * sample[19] - sample[20] - 4.0 * sample[21] - \n\
6.0 * sample[22] - 4.0 * sample[23] - sample[24]; \n\
\n\
vec4 horizEdge = - sample[0] - 2.0 * sample[1] + \n\
2.0 * sample[3] + sample[4] - 4.0 * sample[5] - \n\
8.0 * sample[6] + 8.0 * sample[8] + 4.0 * sample[9] - \n\
6.0 * sample[10] - 12.0 * sample[11] + 12.0 * sample[13] + \n\
6.0 * sample[14] - 4.0 * sample[15] - 8.0 * sample[16] + \n\
8.0 * sample[18] + 4.0 * sample[19] - sample[20] - \n\
2.0 * sample[21] + 2.0 * sample[23] + sample[24]; \n\
\n\
//gl_FragColor.rgb = sqrt(horizEdge.rgb) + sqrt(vertEdge.rgb); \n\
gl_FragColor.rgb = sqrt((horizEdge.rgb * horizEdge.rgb) + \n\
(vertEdge.rgb * vertEdge.rgb)) / 12.0f; \n\
gl_FragColor.a = 1.0; \n\
}"
end
-- 获得数据内容[FSH][Prewitt边缘检测]
function M:getPrewittEdgeDetectionFSH()
return
" \n\
precision mediump float; \n\
uniform sampler2D u_Texture; \n\
uniform vec2 u_TextureCoordOffset[25]; \n\
varying vec2 v_texCoord; \n\
varying vec4 v_fragmentColor; \n\
\n\
void main(void) \n\
{ \n\
vec4 sample[25]; \n\
\n\
for (int i = 0; i < 25; i++) \n\
{ \n\
sample[i] = texture2D(u_Texture, \n\
v_texCoord.st + u_TextureCoordOffset[i]); \n\
} \n\
// Prewitt x: \n\
// -5 -4 0 4 5 \n\
// -8-10 0 10 8 \n\
//-10-20 0 20 10 / 20 \n\
// -8-10 0 10 8 \n\
// -5 -4 0 4 5 \n\
// Prewitt y: \n\
// 5 8 10 8 5 \n\
// 4 10 20 10 4 \n\
// 0 0 0 0 0 / 20 \n\
// -4-10-20-10 -4 \n\
// -5 -8-10 -8 -5 \n\
\n\
vec4 vertEdge = - 5.0 * sample[0] - 8.0 * sample[1] - \n\
10.0 * sample[2] - 8.0 * sample[3] - 5.0 * sample[4] - \n\
4.0 * sample[5] - 10.0 * sample[6] - 20.0 * sample[7] - \n\
10.0 * sample[8] - 4.0 * sample[9] + 4.0 * sample[15] + \n\
10.0 * sample[16] + 20.0 * sample[17] + 10.0 * sample[18] + \n\
4.0 * sample[19] + 5.0 * sample[20] + 8.0 * sample[21] + \n\
10.0 * sample[22] + 8.0 * sample[23] + 5.0 * sample[24]; \n\
\n\
vec4 horizEdge = 5.0 * sample[0] + 4.0 * sample[1] - \n\
4.0 * sample[3] - 5.0 * sample[4] + 8.0 * sample[5] + \n\
10.0 * sample[6] - 10.0 * sample[8] - 8.0 * sample[9] + \n\
10.0 * sample[10] + 20.0 * sample[11] - 20.0 * sample[13] - \n\
10.0 * sample[14] + 8.0 * sample[15] + 10.0 * sample[16] - \n\
10.0 * sample[18] - 8.0 * sample[19] + 5.0 * sample[20] + \n\
4.0 * sample[21] - 4.0 * sample[23] - 5.0 * sample[24]; \n\
\n\
gl_FragColor.rgb = sqrt((horizEdge.rgb * horizEdge.rgb) + \n\
(vertEdge.rgb * vertEdge.rgb)) / 20.0f; \n\
gl_FragColor.a = 1.0; \n\
}"
end
-- 获得数据内容[FSH][运动模糊]
function M:getMotionBlurFSH()
return
" \n\
precision mediump float; \n\
uniform sampler2D u_Texture; \n\
uniform vec2 u_TextureCoordOffset[25]; \n\
varying vec2 v_texCoord; \n\
varying vec4 v_fragmentColor; \n\
uniform sampler2D tex; \n\
\n\
const float contrast = 1.6; \n\
const float brightness = 0.3; \n\
const float factor = -0.5 * contrast + brightness; \n\
\n\
void main() \n\
{ \n\
gl_FragColor = vec4(0.0); \n\
//vec4 c = texture2D(u_Texture,v_texCoord.st); \n\
//gl_FragColor = clamp(c * contrast + factor, 0.0, 1.); \n\
gl_FragColor += texture2D(u_Texture, v_texCoord + vec2(0.0, -0.028))*0.0044299121055113265; \n\
gl_FragColor += texture2D(u_Texture, v_texCoord + vec2(0.0, -0.024))*0.00895781211794; \n\
gl_FragColor += texture2D(u_Texture, v_texCoord + vec2(0.0, -0.020))*0.0215963866053; \n\
gl_FragColor += texture2D(u_Texture, v_texCoord + vec2(0.0, -0.016))*0.0443683338718; \n\
gl_FragColor += texture2D(u_Texture, v_texCoord + vec2(0.0, -0.012))*0.0776744219933; \n\
gl_FragColor += texture2D(u_Texture, v_texCoord + vec2(0.0, -0.008))*0.115876621105; \n\
gl_FragColor += texture2D(u_Texture, v_texCoord + vec2(0.0, -0.004))*0.147308056121; \n\
gl_FragColor += texture2D(u_Texture, v_texCoord )*0.159576912161; \n\
gl_FragColor += texture2D(u_Texture, v_texCoord + vec2(0.0, 0.004))*0.147308056121; \n\
gl_FragColor += texture2D(u_Texture, v_texCoord + vec2(0.0, 0.008))*0.115876621105; \n\
gl_FragColor += texture2D(u_Texture, v_texCoord + vec2(0.0, 0.012))*0.0776744219933; \n\
gl_FragColor += texture2D(u_Texture, v_texCoord + vec2(0.0, 0.016))*0.0443683338718; \n\
gl_FragColor += texture2D(u_Texture, v_texCoord + vec2(0.0, 0.020))*0.0215963866053; \n\
gl_FragColor += texture2D(u_Texture, v_texCoord + vec2(0.0, 0.024))*0.00895781211794; \n\
gl_FragColor += texture2D(u_Texture, v_texCoord + vec2(0.0, 0.028))*0.0044299121055113265; \n\
}"
end
-- 获得数据内容[VSH]
function M:getDefaultVSH()
return
" \n\
attribute vec4 a_position; \n\
attribute vec2 a_texCoord; \n\
attribute vec4 a_color; \n\
\n\
#ifdef GL_ES \n\
varying lowp vec4 v_fragmentColor; \n\
varying mediump vec2 v_texCoord; \n\
#else \n\
varying vec4 v_fragmentColor; \n\
varying vec2 v_texCoord; \n\
#endif \n\
\n\
void main() \n\
{ \n\
gl_Position = CC_MVPMatrix * a_position; \n\
v_fragmentColor = a_color; \n\
v_texCoord = a_texCoord; \n\
}"
end
-- 获得数据内容[FSH][默认]
function M:getDefaultFSH()
return
" \n\
precision mediump float; \n\
uniform sampler2D u_Texture; \n\
uniform vec2 u_TextureCoordOffset[25]; \n\
varying vec2 v_texCoord; \n\
varying vec4 v_fragmentColor; \n\
\n\
void main(void) \n\
{ \n\
gl_FragColor = texture2D(u_Texture, v_texCoord.st); \n\
} \n\
"
end
-- 获得数据内容[FSH][反色]
function M:getNegativeFSH()
-- 负色
-- 逐像素,使用白色减去当前像素颜色得到
return
" \n\
precision mediump float; \n\
uniform sampler2D u_Texture; \n\
varying vec2 v_texCoord; \n\
varying vec4 v_fragmentColor; \n\
void main() \n\
{ \n\
float T = 1.0; \n\
vec2 st = v_texCoord.st; \n\
vec3 irgb = texture2D(u_Texture, st).rgb; \n\
vec3 neg = vec3(1., 1., 1.)-irgb; \n\
gl_FragColor = vec4(mix(irgb,neg, T), 1.); \n\
}"
end
-- 获得数据内容[FSH][高光]
function M:getBrightnessFSH()
-- 高光
-- 使用添加 或者 减去黑色,达到调整图片光亮度的效果
return
" \n\
precision mediump float; \n\
uniform sampler2D u_Texture; \n\
varying vec2 v_texCoord; \n\
varying vec4 v_fragmentColor; \n\
\n\
void main() \n\
{ \n\
float T = 2.0; \n\
vec2 st = v_texCoord.st; \n\
vec3 irgb = texture2D(u_Texture, st).rgb; \n\
vec3 black = vec3(0., 0., 0.); \n\
gl_FragColor = vec4(mix(black, irgb, T), 1.); \n\
}"
end
-- 获得数据内容[FSH][老照片]
function M:getColorSpriteFSH()
return
" \n\
#ifdef GL_ES \n\
precision mediump float; \n\
#endif \n\
\n\
uniform sampler2D u_texture; \n\
varying vec2 v_texCoord; \n\
varying vec4 v_fragmentColor; \n\
\n\
void main(void) \n\
{ \n\
// vec3( 0.299, 0.587, 0.114 ) 是RGB转YUV的参数值,生成灰色图 \n\
float MixColor = dot(texture2D(u_texture, v_texCoord).rgb, vec3(0.299, 0.587, 0.114)); \n\
// 使用灰色图进行颜色混合 \n\
vec4 blendColor = vec4( 1.2, 1.0, 0.8, 1.0 ); // 调整这个值以修改最终混合色值 \n\
gl_FragColor = vec4(MixColor * blendColor.r, MixColor * blendColor.g, MixColor * blendColor.b, blendColor.a); \n\
}"
end
-- 获得数据内容[FSH][对比]
function M:getContrastFSH()
-- 对比效果
-- 使用一个灰色图作为基础图像,和彩色图混合。
-- 逐像素的将图片颜色差向灰度两边扩大,得到对比效果
return
" \n\
precision mediump float; \n\
uniform sampler2D u_Texture; \n\
varying vec2 v_texCoord; \n\
varying vec4 v_fragmentColor; \n\
\n\
void main() \n\
{ \n\
float T = 2.0; \n\
vec2 st = v_texCoord.st; \n\
vec3 irgb = texture2D(u_Texture, st).rgb; \n\
vec3 target = vec3(0.5, 0.5, 0.5); \n\
gl_FragColor = vec4(mix(target, irgb, T), 1.); \n\
}"
end
-- 获得数据内容[FSH][饱和]
function M:getSaturationFSH()
-- 饱和
-- 混合彩色图片和其亮度图的灰阶,得到饱和图
return
" \n\
precision mediump float; \n\
uniform sampler2D u_Texture; \n\
varying vec2 v_texCoord; \n\
varying vec4 v_fragmentColor; \n\
const vec3 W = vec3(0.2125, 0.7154, 0.0721); \n\
\n\
void main() \n\
{ \n\
float T = 3.0; \n\
vec2 st = v_texCoord.st; \n\
vec3 irgb = texture2D(u_Texture, st).rgb; \n\
float luminance = dot(irgb, W); \n\
vec3 target = vec3(luminance, luminance, luminance); \n\
gl_FragColor = vec4(mix(target, irgb, T), 1.); \n\
}"
end
-- 获得数据内容[FSH][黑白]
function M:getBlackWhiteFSH()
-- 黑白
-- 转为灰度图,然后根据阀值,转为黑白
return
" \n\
precision mediump float; \n\
uniform sampler2D u_Texture; \n\
varying vec2 v_texCoord; \n\
varying vec4 v_fragmentColor; \n\
const vec4 W = vec4(0.2125, 0.7154, 0.0721, 0); \n\
\n\
void main() \n\
{ \n\
vec4 col = texture2D(u_Texture, v_texCoord.st); \n\
float lum = dot(col, W); \n\
if (0.5 < lum) { \n\
gl_FragColor = v_fragmentColor; \n\
} else { \n\
gl_FragColor = vec4(0, 0, 0, 1);} \n\
}"
end
-- 获得数据内容[FSH][边缘]
function M:getEdgeDetectionFSH()
return
" \n\
#ifdef GL_ES \n\
precision mediump float; \n\
precision mediump int; \n\
#endif \n\
\n\
uniform sampler2D u_Texture; \n\
const vec2 texOffset = vec2( 0.005, 0.005); \n\
\n\
varying vec2 v_texCoord; \n\
varying vec4 v_fragmentColor; \n\
\n\
const vec4 lumcoeff = vec4(0.299, 0.587, 0.114, 0); \n\
\n\
void main() \n\
{ \n\
vec2 tc0 = v_texCoord.st + vec2(-texOffset.s, -texOffset.t); \n\
vec2 tc1 = v_texCoord.st + vec2( 0.0, -texOffset.t); \n\
vec2 tc2 = v_texCoord.st + vec2(+texOffset.s, -texOffset.t); \n\
vec2 tc3 = v_texCoord.st + vec2(-texOffset.s, 0.0); \n\
vec2 tc4 = v_texCoord.st + vec2( 0.0, 0.0); \n\
vec2 tc5 = v_texCoord.st + vec2(+texOffset.s, 0.0); \n\
vec2 tc6 = v_texCoord.st + vec2(-texOffset.s, +texOffset.t); \n\
vec2 tc7 = v_texCoord.st + vec2( 0.0, +texOffset.t); \n\
vec2 tc8 = v_texCoord.st + vec2(+texOffset.s, +texOffset.t); \n\
\n\
vec4 col0 = texture2D(u_Texture, tc0); \n\
vec4 col1 = texture2D(u_Texture, tc1); \n\
vec4 col2 = texture2D(u_Texture, tc2); \n\
vec4 col3 = texture2D(u_Texture, tc3); \n\
vec4 col4 = texture2D(u_Texture, tc4); \n\
vec4 col5 = texture2D(u_Texture, tc5); \n\
vec4 col6 = texture2D(u_Texture, tc6); \n\
vec4 col7 = texture2D(u_Texture, tc7); \n\
vec4 col8 = texture2D(u_Texture, tc8); \n\
\n\
vec4 sum = 8.0 * col4 - (col0 + col1 + col2 + col3 + col5 + col6 + col7 + col8); \n\
gl_FragColor = vec4(sum.rgb, 1.0) * v_fragmentColor; \n\
}"
end
-- 获得数据内容[FSH][浮雕]
function M:getEmbossFSH()
return
" \n\
#ifdef GL_ES \n\
precision mediump float; \n\
precision mediump int; \n\
#endif \n\
\n\
uniform sampler2D u_Texture; \n\
const vec2 texOffset = vec2( 0.005, 0.005); \n\
\n\
varying vec4 v_fragmentColor; \n\
varying vec2 v_texCoord; \n\
\n\
const vec4 lumcoeff = vec4(0.299, 0.587, 0.114, 0); \n\
\n\
void main() \n\
{ \n\
vec2 tc0 = v_texCoord.st + vec2(-texOffset.s, -texOffset.t); \n\
vec2 tc1 = v_texCoord.st + vec2( 0.0, -texOffset.t); \n\
vec2 tc2 = v_texCoord.st + vec2(-texOffset.s, 0.0); \n\
vec2 tc3 = v_texCoord.st + vec2(+texOffset.s, 0.0); \n\
vec2 tc4 = v_texCoord.st + vec2( 0.0, +texOffset.t); \n\
vec2 tc5 = v_texCoord.st + vec2(+texOffset.s, +texOffset.t); \n\
\n\
vec4 col0 = texture2D(u_Texture, tc0); \n\
vec4 col1 = texture2D(u_Texture, tc1); \n\
vec4 col2 = texture2D(u_Texture, tc2); \n\
vec4 col3 = texture2D(u_Texture, tc3); \n\
vec4 col4 = texture2D(u_Texture, tc4); \n\
vec4 col5 = texture2D(u_Texture, tc5); \n\
\n\
vec4 sum = vec4(0.5) + (col0 + col1 + col2) - (col3 + col4 + col5); \n\
float lum = dot(sum, lumcoeff); \n\
gl_FragColor = vec4(lum, lum, lum, 1.0) * v_fragmentColor; \n\
}"
end
-- 获得Shadow结点数据[VSH]
function M:getShaderNodeVSH()
-- ccPositionTextureA8Color_vert
return
" \n\
attribute vec4 a_position; \n\
attribute vec2 a_texCoord; \n\
attribute vec4 a_color; \n\
\n\
#ifdef GL_ES \n\
varying lowp vec4 v_fragmentColor; \n\
varying mediump vec2 v_texCoord; \n\
#else \n\
varying vec4 v_fragmentColor; \n\
varying vec2 v_texCoord; \n\
#endif \n\
\n\
void main() \n\
{ \n\
gl_Position = CC_MVPMatrix * a_position; \n\
v_fragmentColor = a_color; \n\
v_texCoord = a_texCoord; \n\
} \n\
"
end
-- 获得Shadow结点数据[FSH]
function M:getShaderNodeFSHEmboss()
return
" \n\
#ifdef GL_ES \n\
precision mediump float; \n\
#endif \n\
varying vec2 v_texCoord; \n\
uniform sampler2D u_texture; \n\
uniform float u_time; \n\
void main() \n\
{ \n\
vec2 onePixel = vec2(1.0 / 480.0, 1.0 / 320.0); \n\
vec2 texCoord = v_texCoord; \n\
texCoord.x += sin(u_time) * (onePixel.x * 6.0); \n\
texCoord.y += cos(u_time) * (onePixel.y * 6.0); \n\
vec4 color; \n\
color.rgb = vec3(0.5); \n\
color -= texture2D(u_texture, texCoord - onePixel) * 5.0; \n\
color += texture2D(u_texture, texCoord + onePixel) * 5.0; \n\
color.rgb = vec3((color.r + color.g + color.b) / 3.0); \n\
gl_FragColor = vec4(color.rgb, 1); \n\
}"
end
-- 获得Shadow结点数据[FSH]
function M:getShaderNodeFSHColorRamp()
return
" \n\
#ifdef GL_ES \n\
precision mediump float; \n\
#endif \n\
varying vec2 v_texCoord; \n\
uniform sampler2D u_texture; \n\
uniform sampler2D u_colorRampTexture; \n\
void main() \n\
{ \n\
vec3 normalColor = texture2D( u_texture, v_texCoord ).rgb; \n\
float rampedR = texture2D( u_colorRampTexture, vec2( normalColor.r, 0 )).g; \n\
float rampedG = texture2D( u_colorRampTexture, vec2( normalColor.r, 0 )).g; \n\
float rampedB = texture2D( u_colorRampTexture, vec2( normalColor.r, 0 )).b; \n\
gl_FragColor = vec4( rampedR, rampedG, rampedB, 1 ); \n\
}"
end