-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathshaderUtil.js
75 lines (69 loc) · 2.03 KB
/
shaderUtil.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { getRgbColor } from './util.js';
export const vertexShader = `
varying vec3 vNormal;
varying vec2 vUv;
void main()
{
vNormal = normal;
vUv=uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}`;
//渐变柱体shader
export const barShader = `
uniform vec3 topColor;
uniform vec3 bottomColor;
varying vec2 vUv;
varying vec3 vNormal;
void main() {
if(vNormal.y==1.0){
gl_FragColor = vec4(topColor, 1.0 );
}else if(vNormal.y==-1.0){
gl_FragColor = vec4(bottomColor, 1.0 );
}else{
gl_FragColor = vec4(mix(bottomColor,topColor,vUv.y), 1.0 );
}
}`;
export function getGradientShaderMaterial(THREE, topColor, bottomColor) {
const uniforms = {
topColor: { value: new THREE.Color(getRgbColor(topColor)) },
bottomColor: { value: new THREE.Color(getRgbColor(bottomColor)) }
};
return new THREE.ShaderMaterial({
uniforms: uniforms,
vertexShader: vertexShader,
fragmentShader: barShader,
side: THREE.DoubleSide
});
}
//飞线shader
export const lineFShader = `
uniform float time;
uniform vec3 colorA;
uniform vec3 colorB;
varying vec2 vUv;
void main() {
vec3 color =vUv.x<time?colorB:colorA;
gl_FragColor = vec4(color,1.0);
}`;
export function getLineShaderMaterial(THREE, color, color1) {
const uniforms = {
time: { value: 0.0 },
colorA: { value: new THREE.Color(getRgbColor(color)) },
colorB: { value: new THREE.Color(getRgbColor(color1)) }
};
return new THREE.ShaderMaterial({
uniforms: uniforms,
vertexShader: vertexShader,
fragmentShader: lineFShader,
side: THREE.DoubleSide,
transparent: true
});
}
export const circlePointsShader = `float d=distance(gl_PointCoord, vec2(0.5, 0.5));
if(d < 0.3){
gl_FragColor = diffuseColor;
}else{
gl_FragColor.rgb = diffuseColor.rgb;
float cd =(1.0-d*2.0);
gl_FragColor.a=diffuseColor.a*cd*0.5;
}`;