[]写shader还区分2d,与3d么!看官网是3d的shader例子,有没有2d的shader例子?
private initShader(): void {
var attributeMap = {
'a_Position': Laya.VertexElementUsage.POSITION0,
'a_Normal': Laya.VertexElementUsage.NORMAL0
};
var uniformMap = {
'u_MvpMatrix': [Laya.Sprite3D.MVPMATRIX, Laya.Shader3D.PERIOD_SPRITE],
'u_WorldMat': [Laya.Sprite3D.WORLDMATRIX, Laya.Shader3D.PERIOD_SPRITE]
};
var customShader: number = Laya.Shader3D.nameKey.add("CustomShader");
var vs: string = "attribute vec4 a_Position;\n" +
"uniform mat4 u_MvpMatrix;\n" +
"uniform mat4 u_WorldMat;\n" +
"attribute vec3 a_Normal;\n" +
"varying vec3 v_Normal;\n" +
"void main(){\n" +
"gl_Position = u_MvpMatrix * a_Position;\n" +
"mat3 worldMat=mat3(u_WorldMat);\n" +
"v_Normal=worldMat*a_Normal;}";
var ps: string = "#ifdef FSHIGHPRECISION\n" +
"precision highp float;\n" +
"#else\n" +
"precision mediump float;\n" +
"#endif\n" +
"varying vec3 v_Normal;\n" +
"void main(){\n" +
"gl_FragColor=vec4(v_Normal,1.0);}\n";
Laya.ShaderCompile3D.add(customShader, vs, ps, attributeMap, uniformMap);
}
var attributeMap = {
'a_Position': Laya.VertexElementUsage.POSITION0,
'a_Normal': Laya.VertexElementUsage.NORMAL0
};
var uniformMap = {
'u_MvpMatrix': [Laya.Sprite3D.MVPMATRIX, Laya.Shader3D.PERIOD_SPRITE],
'u_WorldMat': [Laya.Sprite3D.WORLDMATRIX, Laya.Shader3D.PERIOD_SPRITE]
};
var customShader: number = Laya.Shader3D.nameKey.add("CustomShader");
var vs: string = "attribute vec4 a_Position;\n" +
"uniform mat4 u_MvpMatrix;\n" +
"uniform mat4 u_WorldMat;\n" +
"attribute vec3 a_Normal;\n" +
"varying vec3 v_Normal;\n" +
"void main(){\n" +
"gl_Position = u_MvpMatrix * a_Position;\n" +
"mat3 worldMat=mat3(u_WorldMat);\n" +
"v_Normal=worldMat*a_Normal;}";
var ps: string = "#ifdef FSHIGHPRECISION\n" +
"precision highp float;\n" +
"#else\n" +
"precision mediump float;\n" +
"#endif\n" +
"varying vec3 v_Normal;\n" +
"void main(){\n" +
"gl_FragColor=vec4(v_Normal,1.0);}\n";
Laya.ShaderCompile3D.add(customShader, vs, ps, attributeMap, uniformMap);
}
没有找到相关结果
已邀请:
要回复问题请先登录
1 个回复
Aar0n
赞同来自: 纪龙