I have a shader material.
function createGradient(originColor){
return new THREE.ShaderMaterial({
uniforms: {
originColor: {
value: originColor
},
center: {
value: new THREE.Vector3(-5, -20, 0)
},
radius: {
value: 20.0
}
},
vertexShader: `
varying vec3 vPosition;
void main() {
vPosition = position;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0);
}
`,
fragmentShader: `
uniform vec3 originColor;
uniform vec3 center;
uniform float radius;
varying vec3 vPosition;
void main() {
float dis = distance(vPosition, center);
float bound1 = radius / 3.0;
float bound2 = (radius / 3.0) * 2.0;
float r, g, b;
if (dis < bound1) {
float rate = dis / bound1;
r = 1.0;
g = mix(0.0, 1.0, rate);
b = 0.0;
}
if (dis >= bound1 && dis < bound2) {
float rate = (dis - bound1) / bound1;
r = mix(1.0, 0.0, rate);
g = 1.0;
b = mix(0.0, 1.0, rate);
}
if (dis >= bound2 && dis <= radius) {
float rate = (dis - bound2) / bound1;
r = 0.0;
g = mix(1.0, 0.0, rate);
b = 1.0;
}
if (dis > radius) {
r = originColor.r;
g = originColor.g;
b = originColor.b;
}
gl_FragColor = vec4(r, g, b, 1.0);
}`
});
}
When switch to the gradient material.
mesh.material = createGradient(mesh.material.color)
so out of the gradient radius use mesh original color.
but lost original material oapcity and light.
Is there a easy to combine the gradient and original material?