three
Version:
JavaScript 3D library
80 lines (55 loc) • 1.83 kB
JavaScript
export const vertex = /* glsl */`
uniform float rotation;
uniform vec2 center;
void main() {
vec4 mvPosition = modelViewMatrix[ 3 ];
vec2 scale = vec2( length( modelMatrix[ 0 ].xyz ), length( modelMatrix[ 1 ].xyz ) );
bool isPerspective = isPerspectiveMatrix( projectionMatrix );
if ( isPerspective ) scale *= - mvPosition.z;
vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;
vec2 rotatedPosition;
rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;
rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;
mvPosition.xy += rotatedPosition;
gl_Position = projectionMatrix * mvPosition;
}
`;
export const fragment = /* glsl */`
uniform vec3 diffuse;
uniform float opacity;
void main() {
vec4 diffuseColor = vec4( diffuse, opacity );
vec3 outgoingLight = vec3( 0.0 );
outgoingLight = diffuseColor.rgb;
}
`;