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

« back to all changes in this revision

Viewing changes to demos/webgl/CubicVR_Core.fs

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2014-01-19 14:12:40 UTC
  • mfrom: (4.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20140119141240-nfiw0p8033oitpfz
Tags: 1.9.0~20140119~7dc8c2f-1
* New snapshot release (Closes: #733714)
* Provide sources for javascript and flash. Done in orig-tar.sh
  Available in third_party/websockify/include/web-socket-js/src/
  (Closes: #735903)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifdef GL_ES
2
 
  precision highp float;
3
 
#endif
4
 
 
5
 
  uniform vec3 mDiff;
6
 
  uniform vec3 mColor;
7
 
  uniform vec3 mAmb;
8
 
 
9
 
  varying vec3 vNormal;
10
 
 
11
 
  varying vec2 vTextureCoord;
12
 
 
13
 
#if alphaDepth
14
 
  uniform vec3 depthInfo;
15
 
  float ConvertDepth3(float d) { return (depthInfo.x*depthInfo.y)/(depthInfo.y-d*(depthInfo.y-depthInfo.x));  }
16
 
  // transform range in world-z to 0-1 for near-far
17
 
  float DepthRange( float d ) { return ( d - depthInfo.x ) / ( depthInfo.y - depthInfo.x ); }
18
 
#endif
19
 
 
20
 
#if hasColorMap
21
 
        uniform sampler2D colorMap;
22
 
#endif
23
 
 
24
 
#if hasBumpMap
25
 
        varying vec3 eyeVec; 
26
 
        uniform sampler2D bumpMap;
27
 
#endif
28
 
 
29
 
 
30
 
#if hasEnvSphereMap
31
 
        uniform sampler2D envSphereMap;
32
 
        uniform float envAmount;
33
 
#if hasNormalMap
34
 
        varying vec3 u;
35
 
#else
36
 
        varying vec2 vEnvTextureCoord;
37
 
#endif
38
 
#endif
39
 
 
40
 
#if hasReflectMap
41
 
  uniform sampler2D reflectMap;
42
 
#endif
43
 
 
44
 
#if hasNormalMap
45
 
        uniform sampler2D normalMap;
46
 
#endif
47
 
 
48
 
        uniform float mAlpha;
49
 
 
50
 
#if hasAmbientMap
51
 
        uniform sampler2D ambientMap;
52
 
#endif
53
 
 
54
 
#if hasSpecularMap
55
 
        uniform sampler2D specularMap;
56
 
#endif
57
 
 
58
 
#if hasAlphaMap
59
 
        uniform sampler2D alphaMap;
60
 
#endif
61
 
 
62
 
#if lightPoint||lightDirectional||lightSpot||lightArea
63
 
  struct Light {
64
 
    vec3 lDir;
65
 
    vec3 lPos;
66
 
    vec3 lSpec;
67
 
    vec3 lDiff;
68
 
    float lInt;
69
 
    float lDist;
70
 
  };
71
 
  uniform Light lights[loopCount];  
72
 
        varying vec3 lightDir[loopCount];
73
 
#endif
74
 
 
75
 
uniform vec3 mSpec;
76
 
uniform float mShine;
77
 
uniform vec3 lAmb;
78
 
 
79
 
#if lightPoint||lightSpot
80
 
  varying vec3 lightPos[loopCount];
81
 
#endif
82
 
 
83
 
 
84
 
 
85
 
varying vec3 camPos;
86
 
varying vec4 vPosition;
87
 
 
88
 
uniform mat4 uPMatrix;
89
 
 
90
 
void main(void) 
91
 
{
92
 
        vec3 n;
93
 
        vec4 color = vec4(0.0,0.0,0.0,0.0);
94
 
        
95
 
#if hasBumpMap
96
 
  float height = texture2D(bumpMap, vTextureCoord.xy).r;  
97
 
  float v = (height) * 0.05 - 0.04; // * scale and - bias 
98
 
  vec3 eye = normalize(eyeVec); 
99
 
  vec2 texCoord = vTextureCoord.xy + (eye.xy * v);
100
 
#else 
101
 
#if hasColorMap||hasBumpMap||hasNormalMap||hasAmbientMap||hasSpecularMap||hasAlphaMap
102
 
        vec2 texCoord = vTextureCoord;
103
 
#endif
104
 
#endif
105
 
 
106
 
 
107
 
#if hasNormalMap
108
 
                vec3 bumpNorm = vec3(texture2D(normalMap, texCoord));
109
 
 
110
 
                n = (vec4(normalize(vNormal),1.0)).xyz;
111
 
    bumpNorm = (bumpNorm-0.5)*2.0;
112
 
    bumpNorm.y = -bumpNorm.y;
113
 
    n = normalize((n+bumpNorm)/2.0);
114
 
#else
115
 
                n = normalize(vNormal);
116
 
#endif
117
 
 
118
 
 
119
 
#if hasColorMap
120
 
#if !(lightPoint||lightDirectional||lightSpot||lightArea)
121
 
        color = texture2D(colorMap, vec2(texCoord.s, texCoord.t)).rgba;
122
 
        //vec4(lAmb,1.0)*
123
 
#else
124
 
  color = texture2D(colorMap, vec2(texCoord.s, texCoord.t)).rgba;
125
 
  color.rgb *= mColor;
126
 
#endif
127
 
        if (color.a<=0.9) discard;  
128
 
#else
129
 
        color = vec4(mColor,1.0);
130
 
#endif
131
 
 
132
 
#if hasAlphaMap
133
 
        color.a = texture2D(alphaMap, texCoord).r;
134
 
  if (color.a==0.0) discard;
135
 
#else
136
 
#if hasAlpha
137
 
        color.a = mAlpha;
138
 
#endif
139
 
#endif
140
 
 
141
 
 
142
 
//float envAmount = 1.0;
143
 
 
144
 
vec3 accum = lAmb;
145
 
 
146
 
 
147
 
#if lightPoint
148
 
  float dist;
149
 
        float NdotL;
150
 
 
151
 
        float NdotHV = 0.0;
152
 
  float att = 0.0;
153
 
 
154
 
  vec3 halfVector;
155
 
  vec3 specTotal = vec3(0.0,0.0,0.0);
156
 
 
157
 
  for (int i = 0; i < loopCount; i++) {
158
 
  
159
 
          halfVector = normalize(vec3(0.0,0.0,1.0)+lightDir[i]);
160
 
 
161
 
    dist = length(lightPos[i]-vPosition.xyz);
162
 
 
163
 
        NdotL = max(dot(normalize(lightDir[i]),n),0.0);
164
 
 
165
 
        if (NdotL > 0.0) {
166
 
                // basic diffuse
167
 
      att = clamp(((lights[i].lDist-dist)/lights[i].lDist), 0.0, 1.0)*lights[i].lInt;
168
 
 
169
 
                accum += att * NdotL * lights[i].lDiff * mDiff;
170
 
 
171
 
                NdotHV = max(dot(n, halfVector),0.0);
172
 
 
173
 
        
174
 
            #if hasSpecularMap
175
 
                          vec3 spec2 = lights[i].lSpec * texture2D(specularMap, vec2(texCoord.s, texCoord.t)).rgb * pow(NdotHV,mShine);
176
 
            #else
177
 
                          vec3 spec2 = lights[i].lSpec * mSpec * pow(NdotHV,mShine);
178
 
            #endif
179
 
  
180
 
        specTotal += spec2;
181
 
        }
182
 
        
183
 
  }
184
 
  
185
 
  color.rgb *= accum;
186
 
  color.rgb += specTotal;
187
 
#endif
188
 
 
189
 
 
190
 
 
191
 
 
192
 
#if lightDirectional
193
 
  float NdotL;
194
 
  float NdotHV = 0.0;
195
 
  vec3 specTotal = vec3(0.0,0.0,0.0);
196
 
  vec3 spec2 = vec3(0.0,0.0,0.0);
197
 
 
198
 
        vec3 halfVector;
199
 
  
200
 
  for (int i = 0; i < loopCount; i++) {
201
 
 
202
 
          halfVector = normalize(vec3(0.0,0.0,1.0)-lightDir[i]);
203
 
 
204
 
        NdotL = max(dot(normalize(-lightDir[i]),n),0.0);
205
 
 
206
 
        if (NdotL > 0.0)        {
207
 
                accum += lights[i].lInt * mDiff * lights[i].lDiff * NdotL;              
208
 
 
209
 
                NdotHV = max(dot(n, halfVector),0.0);
210
 
 
211
 
      #if hasSpecularMap
212
 
        spec2 = lights[i].lSpec * texture2D(specularMap, vec2(texCoord.s, texCoord.t)).rgb * pow(NdotHV,mShine);
213
 
      #else
214
 
        spec2 = lights[i].lSpec * mSpec * pow(NdotHV,mShine);
215
 
      #endif
216
 
      
217
 
      specTotal += spec2;
218
 
        }
219
 
  }  
220
 
  
221
 
  color.rgb *= accum;
222
 
  color.rgb += specTotal;
223
 
#endif
224
 
 
225
 
 
226
 
#if hasReflectMap
227
 
  float environmentAmount = texture2D( reflectMap, texCoord).r;
228
 
#endif
229
 
 
230
 
#if hasEnvSphereMap
231
 
#if hasNormalMap
232
 
        vec3 r = reflect( u, n );
233
 
        float m = 2.0 * sqrt( r.x*r.x + r.y*r.y + (r.z+1.0)*(r.z+1.0) );
234
 
 
235
 
        vec3 coord;
236
 
        coord.s = r.x/m + 0.5;
237
 
        coord.t = r.y/m + 0.5;
238
 
        
239
 
  #if hasReflectMap
240
 
                color.rgb += mColor*accum*texture2D( envSphereMap, coord.st).rgb * environmentAmount;
241
 
         #else
242
 
                color.rgb += mColor*accum*texture2D( envSphereMap, coord.st).rgb * envAmount;
243
 
         #endif
244
 
 
245
 
#else
246
 
        #if hasReflectMap
247
 
          color.rgb += mColor*accum*texture2D( envSphereMap, vEnvTextureCoord).rgb * environmentAmount;
248
 
        #else
249
 
                color.rgb += mColor*accum*texture2D( envSphereMap, vEnvTextureCoord).rgb*envAmount;
250
 
        #endif
251
 
#endif
252
 
 
253
 
#endif
254
 
 
255
 
 
256
 
 
257
 
#if hasAmbientMap
258
 
#if lightPoint||lightDirectional||lightSpot||lightArea
259
 
  color.rgb += texture2D(ambientMap, texCoord).rgb*(vec3(1.0,1.0,1.0)+mColor*mAmb);
260
 
#else
261
 
  color.rgb = color.rgb*texture2D(ambientMap, texCoord).rgb;                                                    
262
 
#endif
263
 
#else
264
 
#if !hasColorMap
265
 
        color.rgb += mColor*mAmb;
266
 
#else
267
 
  color.rgb += mAmb*texture2D(colorMap, texCoord).rgb;
268
 
#endif
269
 
#endif
270
 
 
271
 
 
272
 
#if alphaDepth
273
 
#if !hasAlpha
274
 
  float linear_depth = DepthRange( ConvertDepth3( gl_FragCoord.z ));
275
 
 
276
 
  color.a = linear_depth;
277
 
#endif
278
 
#endif
279
 
 
280
 
        gl_FragColor = clamp(color,0.0,1.0);
281
 
}
 
 
b'\\ No newline at end of file'