UNPKG

1.35 kBJavaScriptView Raw
1var xtend = require('xtend')
2var number = require('as-number')
3
4module.exports = function(THREE) {
5 return function (opt) {
6 opt = opt||{}
7
8 var ret = xtend({
9 uniforms: {
10 thickness: { type: 'f', value: number(opt.thickness, 0.1) },
11 opacity: { type: 'f', value: number(opt.opacity, 1.0) },
12 diffuse: { type: 'c', value: new THREE.Color(opt.diffuse) }
13 },
14 attributes: {
15 lineMiter: { type: 'f', value: 0 },
16 lineNormal: { type: 'v2', value: new THREE.Vector2() }
17 },
18 vertexShader: [
19 "uniform float thickness;",
20 "attribute float lineMiter;",
21 "attribute vec2 lineNormal;",
22 "void main() {",
23 "vec3 pointPos = position.xyz + vec3(lineNormal * thickness/2.0 * lineMiter, 0.0);",
24 "gl_Position = projectionMatrix * modelViewMatrix * vec4( pointPos, 1.0 );",
25 "}"
26 ].join("\n"),
27 fragmentShader: [
28 "uniform float opacity;",
29 "uniform vec3 diffuse;",
30 "void main() {",
31 "gl_FragColor = vec4(diffuse, opacity);",
32 "}"
33 ].join("\n")
34 }, opt)
35 return ret
36 }
37}
\No newline at end of file