UNPKG

whs-component-glowline

Version:

Simple plugin to make glow lines

32 lines (24 loc) 1.97 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.glowShader = undefined; var _three = require('three'); var THREE = _interopRequireWildcard(_three); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } var glowShader = exports.glowShader = function glowShader(params) { return { uniforms: { color: { value: new THREE.Color(params.glow.color) }, normalIntensity: { value: params.glow.normalIntensity / 100 }, cameraIntensity: { value: params.glow.cameraIntensity / 100 }, glowMargin: { value: params.glow.margin }, glowPow: { value: params.glow.pow } }, vertexShader: '\n\t\tvarying vec3 vNormal1;\n\t\tvarying vec3 vNormal2;\n\n\t\tuniform float cameraIntensity;\n\n\t\tvoid main() {\n\t\t\tvNormal1 = normalize(normalMatrix * normal);\n\t\t\tvNormal2 = normalize(normal);\n\n\t\t\tvec4 cameraPosition = projectionMatrix * modelViewMatrix * vec4(0.0, 0.0, 10.0, 0.0);\n\t\t\tfloat cameraDistance = distance(position.xyz, cameraPosition.xyz);\n\n\t\t gl_Position = projectionMatrix * modelViewMatrix * \n\t\t \tvec4(position + normal * cameraIntensity * cameraDistance, 1.0);\n\t\t}\n\t', fragmentShader: '\n\t\tvarying vec3 vNormal1;\n\t\tvarying vec3 vNormal2;\n\n\t\tuniform vec3 color;\n\t\tuniform float normalIntensity;\n\t\tuniform float glowMargin;\n\t\tuniform float glowPow;\n\n\t\tvoid main() {\n\t\t\tfloat intensity = \n\t\t\t\tpow(glowMargin - dot(vNormal1, vec3(0.0, 0.0, 1.0)), glowPow) * normalIntensity\n\t\t\t\t+ pow(glowMargin - dot(vNormal2, vec3(0.0, 0.0, 1.0)), glowPow) * (1.00 - normalIntensity);\n\n\t\t\tgl_FragColor = vec4(color, 1.0) * intensity;\n\t\t}\n\t', // side: THREE.BackSide, transparent: true, blending: THREE.AdditiveBlending }; };