1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- /**
- * @author mikael emtinger / http://gomo.se/
- *
- */
- THREE.ShaderSprite = {
- 'sprite': {
- vertexShader: [
- "uniform int useScreenCoordinates;",
- "uniform int affectedByDistance;",
- "uniform vec3 screenPosition;",
- "uniform mat4 modelViewMatrix;",
- "uniform mat4 projectionMatrix;",
- "uniform float rotation;",
- "uniform vec2 scale;",
- "uniform vec2 alignment;",
- "uniform vec2 uvOffset;",
- "uniform vec2 uvScale;",
- "attribute vec2 position;",
- "attribute vec2 uv;",
- "varying vec2 vUV;",
- "void main() {",
- "vUV = uvOffset + uv * uvScale;",
- "vec2 alignedPosition = position + alignment;",
- "vec2 rotatedPosition;",
- "rotatedPosition.x = ( cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y ) * scale.x;",
- "rotatedPosition.y = ( sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y ) * scale.y;",
- "vec4 finalPosition;",
- "if( useScreenCoordinates != 0 ) {",
- "finalPosition = vec4( screenPosition.xy + rotatedPosition, screenPosition.z, 1.0 );",
- "} else {",
- "finalPosition = projectionMatrix * modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );",
- "finalPosition.xy += rotatedPosition * ( affectedByDistance == 1 ? 1.0 : finalPosition.z );",
- "}",
- "gl_Position = finalPosition;",
- "}"
- ].join( "\n" ),
- fragmentShader: [
- "#ifdef GL_ES",
- "precision highp float;",
- "#endif",
- "uniform vec3 color;",
- "uniform sampler2D map;",
- "uniform float opacity;",
- "varying vec2 vUV;",
- "void main() {",
- "vec4 texture = texture2D( map, vUV );",
- "gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );",
- "}"
- ].join( "\n" )
- }
- };
|