1var THREEx = THREEx || {} 2 3/** 4 * from http://stemkoski.blogspot.fr/2013/07/shaders-in-threejs-glow-and-halo.html 5 * @return {[type]} [description] 6 */ 7THREEx.createAtmosphereMaterial = function(){ 8 var vertexShader = [ 9 'varying vec3 vVertexWorldPosition;', 10 'varying vec3 vVertexNormal;', 11 12 'varying vec4 vFragColor;', 13 14 'void main(){', 15 ' vVertexNormal = normalize(normalMatrix * normal);', 16 17 ' vVertexWorldPosition = (modelMatrix * vec4(position, 1.0)).xyz;', 18 19 ' // set gl_Position', 20 ' gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);', 21 '}', 22 23 ].join('\n') 24 var fragmentShader = [ 25 'uniform vec3 glowColor;', 26 'uniform float coeficient;', 27 'uniform float power;', 28 29 'varying vec3 vVertexNormal;', 30 'varying vec3 vVertexWorldPosition;', 31 32 'varying vec4 vFragColor;', 33 34 'void main(){', 35 ' vec3 worldCameraToVertex= vVertexWorldPosition - cameraPosition;', 36 ' vec3 viewCameraToVertex = (viewMatrix * vec4(worldCameraToVertex, 0.0)).xyz;', 37 ' viewCameraToVertex = normalize(viewCameraToVertex);', 38 ' float intensity = pow(coeficient + dot(vVertexNormal, viewCameraToVertex), power);', 39 ' gl_FragColor = vec4(glowColor, intensity);', 40 '}', 41 ].join('\n') 42 43 // create custom material from the shader code above 44 // that is within specially labeled script tags 45 var material = new THREEP3DL.ShaderMaterial({ 46 uniforms: { 47 coeficient : { 48 type : "f", 49 value : 1.0 50 }, 51 power : { 52 type : "f", 53 value : 2 54 }, 55 glowColor : { 56 type : "c", 57 value : new THREEP3DL.Color('pink') 58 }, 59 }, 60 vertexShader : vertexShader, 61 fragmentShader : fragmentShader, 62 //blending : THREEP3DL.AdditiveBlending, 63 transparent : true, 64 depthWrite : false, 65 }); 66 return material 67}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.