[]请教下, 自己写了个渐变色shader, 但是效果始终不对。麻烦大神们看看代码哪里有问题
var attributeMap = {
'a_Position': Laya.VertexElementUsage.POSITION0
};
var uniformMap = {
'u_MvpMatrix': [Laya.Sprite3D.MVPMATRIX, Laya.Shader3D.PERIOD_MATERIAL],
'u_StartColor':[Laya.VertexElementUsage.STARTCOLOR0,Laya.Shader3D.PERIOD_MATERIAL],
'u_EndColor':[Laya.VertexElementUsage.ENDCOLOR0,Laya.Shader3D.PERIOD_MATERIAL]
//'u_MainTex': [1, Laya.Shader3D.PERIOD_MATERIAL]
};
var vs = "uniform mat4 u_MvpMatrix; \n" +
"attribute vec4 a_Position; \n" +
"void main(){ \n " +
"gl_Position = u_MvpMatrix * a_Position; \n " +
"};";
var ps = "precision mediump float; \n" +
"uniform vec4 u_StartColor; \n" +
"uniform vec4 u_EndColor; \n" +
"void main() { \n" +
"gl_FragColor = mix(u_StartColor, u_EndColor, 1);\n" +
"};";
this._setColor(Laya.VertexElementUsage.STARTCOLOR0,new Laya.Vector4(1,0,0,1));
this._setColor(Laya.VertexElementUsage.ENDCOLOR0,new Laya.Vector4(0,0,1,1));
var customShader = Laya.Shader3D.nameKey.add("GradientShader");
Laya.ShaderCompile3D.add(customShader, vs, ps, attributeMap, uniformMap);
this.setShaderName("GradientShader");
'a_Position': Laya.VertexElementUsage.POSITION0
};
var uniformMap = {
'u_MvpMatrix': [Laya.Sprite3D.MVPMATRIX, Laya.Shader3D.PERIOD_MATERIAL],
'u_StartColor':[Laya.VertexElementUsage.STARTCOLOR0,Laya.Shader3D.PERIOD_MATERIAL],
'u_EndColor':[Laya.VertexElementUsage.ENDCOLOR0,Laya.Shader3D.PERIOD_MATERIAL]
//'u_MainTex': [1, Laya.Shader3D.PERIOD_MATERIAL]
};
var vs = "uniform mat4 u_MvpMatrix; \n" +
"attribute vec4 a_Position; \n" +
"void main(){ \n " +
"gl_Position = u_MvpMatrix * a_Position; \n " +
"};";
var ps = "precision mediump float; \n" +
"uniform vec4 u_StartColor; \n" +
"uniform vec4 u_EndColor; \n" +
"void main() { \n" +
"gl_FragColor = mix(u_StartColor, u_EndColor, 1);\n" +
"};";
this._setColor(Laya.VertexElementUsage.STARTCOLOR0,new Laya.Vector4(1,0,0,1));
this._setColor(Laya.VertexElementUsage.ENDCOLOR0,new Laya.Vector4(0,0,1,1));
var customShader = Laya.Shader3D.nameKey.add("GradientShader");
Laya.ShaderCompile3D.add(customShader, vs, ps, attributeMap, uniformMap);
this.setShaderName("GradientShader");
没有找到相关结果
已邀请:
要回复问题请先登录
2 个回复
Aar0n
赞同来自:
Ace1024
赞同来自: