[]请教下, 自己写了个渐变色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");
 
已邀请:

Aar0n

赞同来自:

改写shader 不在官方服务范围内,希望有小伙伴踊跃在下方留言。

Ace1024

赞同来自:

    static vertexShader = `
uniform vec3 u_colorStart;
uniform vec3 u_colorEnd;

varying vec3 v_color;

void main() {
v_color = mix(u_colorStart, u_colorEnd, uv.x);
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`;

static fragmentShader = `
varying vec3 v_color;

void main() {
gl_FragColor = vec4(v_color, 1.0);
}
`;
这是我写的shader,基本能实现功能,但是很简陋,想添加变化角度等

要回复问题请先

商务合作
商务合作