Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bfb38c8
commit e807c78
Showing
5 changed files
with
135 additions
and
54 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
varying vec2 uvCoord; | ||
varying vec3 vNormal; | ||
varying float depth; | ||
|
||
uniform vec3 baseColor; | ||
|
||
void main() { | ||
gl_FragColor.xyz = baseColor; | ||
|
||
// Apply some basic lighting | ||
vec3 light = vec3(0.5, 0.4, 1.0); | ||
float lightScalar = abs(dot(vNormal, light)); | ||
lightScalar += 0.2; // ambient | ||
gl_FragColor.xyz *= lightScalar; | ||
|
||
// Apply fog | ||
float fog = smoothstep(1000.0, 150.0, depth); | ||
gl_FragColor.xyz *= fog; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
module.exports = class PistonChute extends Lysertron.Layer | ||
uniformAttrs: | ||
baseColor: 'c' | ||
|
||
initialize: -> | ||
@radialQty = 24 | ||
@lengthQty = 24 | ||
|
||
@radius = 120 | ||
@length = 5000 | ||
|
||
@currentBeatCount = 0 | ||
|
||
@rotationSpeed = new THREE.Vector3( | ||
0 | ||
THREE.Math.randFloatSpread(40.degToRad) | ||
0 | ||
) | ||
|
||
@baseColor = new THREE.Color().setHSV( | ||
Math.random() | ||
0.5 | ||
0.5 | ||
) | ||
|
||
|
||
@chute = new THREE.Mesh( | ||
new THREE.CylinderGeometry(@radius, @radius, @length, 64, 1, true) | ||
new THREE.ShaderMaterial( | ||
uniforms: @uniforms | ||
vertexShader: assets['vert.glsl'] | ||
fragmentShader: assets['frag.glsl'] | ||
side: THREE.DoubleSide | ||
) | ||
) | ||
@chute.rotation.x = 90.degToRad | ||
@add @chute | ||
|
||
# Pistons | ||
@pistonGeom = new THREE.CubeGeometry(20, 20, 20) | ||
@pistonMat = new THREE.ShaderMaterial( | ||
uniforms: @uniforms | ||
vertexShader: assets['vert.glsl'] | ||
fragmentShader: assets['frag.glsl'] | ||
) | ||
|
||
@pistons = [] | ||
for u in [0...@radialQty] | ||
for v in [0..@lengthQty] | ||
piston = new THREE.Mesh( | ||
@pistonGeom | ||
@pistonMat | ||
) | ||
piston.direction = -1 | ||
piston.scale.z = @getScale piston | ||
|
||
piston.direction = [1, -1].random() | ||
piston.beatNum = [0..3].random() | ||
|
||
angle = u / @radialQty * 2 * Math.PI | ||
angle += v * 2 | ||
|
||
piston.position.set( | ||
Math.sin(angle) * @radius | ||
v * 30 | ||
Math.cos(angle) * @radius | ||
) | ||
|
||
piston.rotation.y = angle | ||
piston.rotation.z = 45.degToRad | ||
|
||
@pistons.push piston | ||
@chute.add piston | ||
|
||
getScale: (piston) -> | ||
if piston.direction is 1 | ||
3.2 | ||
else | ||
0.5 | ||
|
||
|
||
update: (elapsed) -> | ||
rotation = THREE.Vector3.temp(@rotationSpeed) | ||
rotation.multiplyScalar elapsed | ||
@chute.rotation.add rotation | ||
|
||
onBeat: (beat) -> | ||
@currentBeatCount++ | ||
|
||
animateUpBeat = @currentBeatCount % 4 | ||
for piston in @pistons when piston.beatNum is animateUpBeat | ||
# easing = [TWEEN.Easing.Cubic, TWEEN.Easing.Quadratic, ] | ||
piston.direction = 1 | ||
new TWEEN.Tween(piston.scale) | ||
.to({z: @getScale(piston)}, beat.duration * 1000) | ||
.easing(TWEEN.Easing.Back.In) | ||
.start() | ||
|
||
animateDownBeat = (@currentBeatCount - 1) % 4 | ||
for piston in @pistons when piston.beatNum is animateDownBeat | ||
piston.direction = -1 | ||
new TWEEN.Tween(piston.scale) | ||
.to({z: @getScale(piston)}, beat.duration * 3 * 1000) | ||
.easing(TWEEN.Easing.Cubic.InOut) | ||
.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
varying vec2 uvCoord; | ||
varying vec3 vNormal; | ||
varying float depth; | ||
|
||
void main() { | ||
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); | ||
|
||
uvCoord = uv; | ||
vNormal = normal; | ||
depth = gl_Position.z; | ||
} |