Created
July 15, 2020 15:01
-
-
Save williammanco/16c70f84782e6ab2175a60c210454e67 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| vec4 applyMatrix4( vec4 p, mat4 m) { | |
| return m * p; | |
| } | |
| vec3 applyMatrix4(vec3 p, mat4 m) { | |
| return vec3( m * vec4(p, 1.0) ); | |
| } | |
| vec3 applyMatrix3(vec3 p, mat3 m) { | |
| return m * p; | |
| } | |
| mat4 rotationTranslateMatrix(vec3 axis, float angle, vec3 axisTranslate) { | |
| axis = normalize(axis); | |
| float s = sin(angle); | |
| float c = cos(angle); | |
| float oc = 1.0 - c; | |
| return mat4( | |
| oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0.0, | |
| oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0.0, | |
| oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0.0, | |
| axisTranslate.x, axisTranslate.y, axisTranslate.z, 1.0 | |
| ); | |
| } | |
| vec3 twist(vec3 p, float t ) { | |
| float theta = sin( (t * 2.) + p.y) * p.z; | |
| float c = cos( theta ) ; | |
| float s = sin( theta); | |
| mat3 mx = mat3( | |
| c, 0, s, | |
| 0, 1, 0, | |
| -s, 0, c | |
| ); | |
| return applyMatrix3(p, mx); | |
| } | |
| // in the main | |
| if (nY >= 3. && nY <= 7.) { | |
| vec3 direction = vec3(0.2, 1., 1.0); | |
| mat4 mr = rotationTranslateMatrix(direction, sin(uTime * 4.0 ) * 0.1, vec3(sin(uTime * 3.0 ) * 0.02, sin(uTime * 4.0 ) * 0.02, 0.0)); | |
| transformed = applyMatrix4(transformed, mr); | |
| vNormal = applyMatrix4(vNormal, mr); | |
| mat4 ms = scaleMatrix(vec3(1. + uCollision * 0.5, 1. + uCollision * 0.2, 1.)); | |
| transformed = applyMatrix4(transformed, ms); | |
| } | |
| if (nY == 4. || nY == 5.) { // elica e timone | |
| float intensity = 5. + rand(ids); | |
| transformed = twist(transformed, uTime * intensity); | |
| vNormal = twist(vNormal, uTime * intensity); | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment