Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Rekod3DBuildings.Engine.prototype.createVertexShaderForSnowParticles = function( scriptId ) {
  2.     if ( typeof scriptId === 'string' ) {
  3.         var script = document.createElement( 'script' );
  4.         script.id = scriptId;
  5.         script.type = 'x-shader/x-vertex';
  6.         script.textContent = '\
  7.                 attribute float size;\
  8.                 attribute float time;\
  9.                 attribute vec3 customColor;\
  10.                 uniform float globalTime;\
  11.                 varying vec3 vColor;\
  12.                 varying float fAlpha;\
  13.                 \
  14.                 void main() {\
  15.                     vColor = customColor;\
  16.                     vec3 pos = position;\
  17.                     float localTime = time + globalTime;\
  18.                     float modTime = mod( localTime, 1.0 );\
  19.                     float accTime = modTime * modTime;\
  20.                     pos.x += cos( modTime * 8.0 + ( position.z ) ) * 70.0;\
  21.                     pos.z += sin( modTime * 6.0 + ( position.x ) ) * 100.0;\
  22.                     fAlpha = ( pos.z ) / 1800.0;\
  23.                     vec3 animated = vec3( pos.x, pos.y * accTime, pos.z );\
  24.                     vec4 mvPosition = modelViewMatrix * vec4( animated, 1.0 );\
  25.                     gl_PointSize = min( 150.0, size * ( 150.0 / length( mvPosition.xyz ) ) );\
  26.                     gl_Position = projectionMatrix * mvPosition;\
  27.                 }';
  28.         document.head.appendChild( script );       
  29.         return script;
  30.     }
  31.     else
  32.         console.error( 'Script id for the vertex shader isn\'t a type of `string`.' );
  33. };
  34. Rekod3DBuildings.Engine.prototype.createFragmentShaderForSnowParticles = function( scriptId ) {
  35.     if ( typeof scriptId === 'string' ) {
  36.         var script = document.createElement( 'script' );
  37.         script.id = scriptId;
  38.         script.type = 'x-shader/x-fragment';
  39.         script.textContent = '\
  40.                 uniform vec3 color;\
  41.                 uniform sampler2D texture;\
  42.                 varying vec3 vColor;\
  43.                 varying float fAlpha;\
  44.                 \
  45.                 void main() {\
  46.                     gl_FragColor = vec4( color * vColor, fAlpha );\
  47.                     gl_FragColor = gl_FragColor * texture2D( texture, gl_PointCoord );\
  48.                 }';
  49.         document.head.appendChild( script );       
  50.         return script;
  51.     }
  52.     else
  53.         console.error( 'Script id for the fragment shader isn\'t a type of `string`.' );
  54. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement