#lua中编写shader的方式

时间:2024-12-19 09:37:56

lua中编写shader的方式

1. 字符串拼接

类似于下面这种

vertDefaultSource = "\n".."\n" ..
"attribute vec4 a_position;\n" ..
"attribute vec2 a_texCoord;\n" ..
"attribute vec4 a_color;\n\n" ..
"\n#ifdef GL_ES\n" ..
"varying lowp vec4 v_fragmentColor;\n" ..
"varying mediump vec2 v_texCoord;\n" ..
"\n#else\n" ..
"varying vec4 v_fragmentColor;" ..
"varying vec2 v_texCoord;" ..
"\n#endif\n" ..
"void main()\n" ..
"{\n" ..
" gl_Position = CC_MVPMatrix * a_position;\n"..
" v_fragmentColor = a_color;\n"..
" v_texCoord = a_texCoord;\n" ..
"} \n"

2. 双括号字符串方式[[]]

kShaderDefaultVsh = [[
attribute vec4 a_position;
attribute vec2 a_texCoord;
attribute vec4 a_color; #ifdef GL_ES
varying mediump 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;
}
]]

上面这两种方式都可以,感觉第二种方便点。

相关文章