summaryrefslogtreecommitdiffstats
path: root/src/extras/shaders/es2/morphphong.vert
blob: d091e87c08959155d376c3c90b09584648df0b6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
attribute vec3 vertexPosition;
attribute vec3 vertexNormal;
attribute vec3 vertexPositionTarget;
attribute vec3 vertexNormalTarget;

varying vec3 worldPosition;
varying vec3 worldNormal;

uniform mat4 modelMatrix;
uniform mat3 modelNormalMatrix;
uniform mat4 modelViewProjection;
uniform float interpolator;

void main()
{
    vec3 morphPos;
    vec3 morphNormal;
    if (interpolator > 0.0) {
        // normalized
        morphPos = mix(vertexPosition, vertexPositionTarget, interpolator);
        morphNormal = normalize(mix(vertexNormal, vertexNormalTarget, interpolator));
    } else {
        // relative
        morphPos = vertexPosition + vertexPositionTarget * abs(interpolator);
        morphNormal = normalize(vertexNormal + vertexNormalTarget * abs(interpolator));
    }

    worldNormal = normalize( modelNormalMatrix * morphPos );
    worldPosition = vec3( modelMatrix * vec4( morphPos, 1.0 ) );

    gl_Position = modelViewProjection * vec4( morphPos, 1.0 );
}