~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to demos/webgl/CubicVR_Core.vs

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
        attribute vec3 aVertexPosition;
 
2
        attribute vec3 aNormal;
 
3
  attribute vec2 aTextureCoord;
 
4
        varying vec2 vTextureCoord;
 
5
 
 
6
//  #if hasColorMap||hasBumpMap||hasNormalMap||hasAmbientMap||hasSpecularMap||hasAlphaMap
 
7
//  #endif
 
8
 
 
9
        uniform mat4 uMVMatrix;
 
10
        uniform mat4 uPMatrix;
 
11
        uniform mat4 uOMatrix;
 
12
        uniform mat3 uNMatrix;
 
13
 
 
14
  vec3 mSpec;
 
15
  float mShine;
 
16
 
 
17
        varying vec3 vNormal;
 
18
        varying vec4 vPosition;
 
19
  varying vec3 camPos;
 
20
 
 
21
 
 
22
 
 
23
#if loopCount
 
24
  struct Light {
 
25
    vec3 lDir;
 
26
    vec3 lPos;
 
27
    vec3 lSpec;
 
28
    vec3 lDiff;
 
29
    float lInt;
 
30
    float lDist;
 
31
  };
 
32
 uniform Light lights[loopCount];
 
33
 varying vec3 lightDir[loopCount];
 
34
#endif
 
35
 
 
36
 
 
37
#if lightPoint
 
38
  varying vec3 lightPos[loopCount];
 
39
#endif
 
40
 
 
41
 
 
42
#if hasEnvSphereMap
 
43
#if hasNormalMap
 
44
        varying vec3 u;
 
45
#else
 
46
        varying vec2 vEnvTextureCoord;
 
47
#endif
 
48
#endif
 
49
 
 
50
 
 
51
        
 
52
#if hasBumpMap||hasNormalMap
 
53
        varying vec3 eyeVec; 
 
54
#endif
 
55
 
 
56
void main(void) 
 
57
{
 
58
  mat4 uMVOMatrix = uMVMatrix * uOMatrix;
 
59
  mat4 uMVPMatrix = uPMatrix * uMVMatrix;
 
60
 
 
61
        vTextureCoord = aTextureCoord;
 
62
 
 
63
        vPosition = uMVOMatrix * vec4(aVertexPosition, 1.0);
 
64
 
 
65
        camPos.xyz = vec3(0.0,0.0,0.0);
 
66
        
 
67
        gl_Position = uMVPMatrix * uOMatrix * vec4(aVertexPosition, 1.0);
 
68
        
 
69
  vNormal = uNMatrix * normalize(uOMatrix*vec4(aNormal,0.0)).xyz;
 
70
 
 
71
 
 
72
#if hasBumpMap||hasNormalMap
 
73
        vec3 tangent;
 
74
        vec3 binormal;
 
75
 
 
76
        vec3 c1 = cross( aNormal, vec3(0.0, 0.0, 1.0) );
 
77
        vec3 c2 = cross( aNormal, vec3(0.0, 1.0, 0.0) );
 
78
 
 
79
        if ( length(c1) > length(c2) )  {
 
80
                tangent = c1;
 
81
        }       else {
 
82
                tangent = c2;
 
83
        }
 
84
 
 
85
        tangent = normalize(tangent);
 
86
 
 
87
        binormal = cross(aNormal, tangent);
 
88
        binormal = normalize(binormal);
 
89
 
 
90
        mat3 TBNMatrix = mat3( (vec3 (uMVOMatrix * vec4 (tangent, 0.0))), 
 
91
                               (vec3 (uMVOMatrix * vec4 (binormal, 0.0))), 
 
92
                               (vec3 (uMVOMatrix * vec4 (aNormal, 0.0)))
 
93
                             );
 
94
 
 
95
        eyeVec = vec3(uMVOMatrix * vec4(aVertexPosition,1.0)) * TBNMatrix;
 
96
#endif
 
97
 
 
98
 
 
99
#if lightDirectional
 
100
    for (int i = 0; i < loopCount; i++)
 
101
    {
 
102
            lightDir[i] = uNMatrix * lights[i].lDir;
 
103
    }
 
104
#endif
 
105
 
 
106
#if lightPoint
 
107
    for (int i = 0; i < loopCount; i++)
 
108
    {
 
109
      lightDir[i] = uNMatrix*normalize(lights[i].lPos-(uOMatrix * vec4(aVertexPosition, 1.0)).xyz);
 
110
      lightPos[i] = (uMVMatrix*vec4(lights[i].lPos,1.0)).xyz;
 
111
    }
 
112
#endif
 
113
 
 
114
#if hasEnvSphereMap
 
115
#if hasNormalMap
 
116
        u = normalize( vPosition.xyz );
 
117
 #else
 
118
  vec3 ws = (uMVMatrix * vec4(aVertexPosition,1.0)).xyz;
 
119
        vec3 u = normalize( vPosition.xyz );
 
120
        vec3 r = reflect(ws  - camPos, vNormal );
 
121
        float m = 2.0 * sqrt( r.x*r.x + r.y*r.y + (r.z+1.0)*(r.z+1.0) );
 
122
        vEnvTextureCoord.s = r.x/m + 0.5;
 
123
        vEnvTextureCoord.t = r.y/m + 0.5;
 
124
#endif
 
125
#endif
 
126
 
 
127
}
 
 
b'\\ No newline at end of file'