forked from cjcliffe/CubicVR.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CubicVR_Core.fs
628 lines (491 loc) · 17.1 KB
/
CubicVR_Core.fs
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
#ifdef GL_ES
#if LIGHT_PERPIXEL
precision highp float;
#else
precision lowp float;
#endif
#endif
uniform vec3 materialAmbient;
uniform vec3 lightAmbient;
uniform vec3 materialColor;
#if LIGHT_PERPIXEL
uniform vec3 materialDiffuse;
uniform vec3 materialSpecular;
uniform float materialShininess;
#if LIGHT_IS_POINT||LIGHT_IS_DIRECTIONAL||LIGHT_IS_SPOT||LIGHT_IS_AREA
uniform vec3 lightDirection[LIGHT_COUNT];
uniform vec3 lightPosition[LIGHT_COUNT];
uniform vec3 lightSpecular[LIGHT_COUNT];
uniform vec3 lightDiffuse[LIGHT_COUNT];
uniform float lightIntensity[LIGHT_COUNT];
uniform float lightDistance[LIGHT_COUNT];
#if LIGHT_IS_SPOT
uniform float lightCutOffAngle[LIGHT_COUNT];
#endif
#endif
#if LIGHT_IS_PROJECTOR
uniform sampler2D lightProjectionMap[LIGHT_COUNT];
#endif
#if LIGHT_SHADOWED
varying vec4 lightProjectionOut[LIGHT_COUNT];
uniform sampler2D lightShadowMap[LIGHT_COUNT];
uniform vec3 lightDepthClip[LIGHT_COUNT];
#endif
#else // !LIGHT_PERPIXEL
varying vec3 lightColorOut;
varying vec3 lightSpecularOut;
#endif // LIGHT_PERPIXEL
varying vec3 vertexNormalOut;
varying vec2 vertexTexCoordOut;
#if VERTEX_COLOR
varying vec3 vertexColorOut;
#endif
#if FX_DEPTH_ALPHA||LIGHT_DEPTH_PASS||LIGHT_SHADOWED
uniform vec3 postDepthInfo;
float ConvertDepth3(float d) { return (postDepthInfo.x*postDepthInfo.y)/(postDepthInfo.y-d*(postDepthInfo.y-postDepthInfo.x)); }
// transform range in world-z to 0-1 for near-far
float DepthRange( float d ) { return ( d - postDepthInfo.x ) / ( postDepthInfo.y - postDepthInfo.x ); }
float ConvertDepth3A(float d, float near, float far) { return (near*far)/(far-d*(far-near)); }
// transform range in world-z to 0-1 for near-far
float DepthRangeA( float d, float near, float far ) { return ( d - near ) / ( far - near ); }
#endif
#if LIGHT_DEPTH_PASS
vec4 packFloatToVec4i(const float value)
{
const vec4 bitSh = vec4(256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);
const vec4 bitMsk = vec4(0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);
vec4 res = fract(value * bitSh);
res -= res.xxyz * bitMsk;
return res;
}
#endif
#if LIGHT_SHADOWED
float unpackFloatFromVec4i(const vec4 value)
{
const vec4 bitSh = vec4(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0, 1.0);
return(dot(value, bitSh));
}
#if LIGHT_SHADOWED_SOFT
float getShadowVal(sampler2D shadowTex,vec4 shadowCoord, float proj, float texel_size) {
vec2 filterTaps[6];
filterTaps[0] = vec2(-0.326212,-0.40581);
filterTaps[1] = vec2(-0.840144,-0.07358);
filterTaps[2] = vec2(-0.695914,0.457137);
filterTaps[3] = vec2(-0.203345,0.620716);
filterTaps[4] = vec2(0.96234,-0.194983);
filterTaps[5] = vec2(0.473434,-0.480026);
/* filterTaps[6] = vec2(0.519456,0.767022);
filterTaps[7] = vec2(0.185461,-0.893124);
filterTaps[8] = vec2(0.507431,0.064425);
filterTaps[9] = vec2(0.89642,0.412458) ;
filterTaps[10] =vec2(-0.32194,-0.932615);
filterTaps[11] =vec2(-0.791559,-0.59771); */
float shadow = 0.0;
vec4 shadowSample;
float distanceFromLight;
for (int i = 0; i < 6; i++) {
shadowSample = texture2D(shadowTex,shadowCoord.st+filterTaps[i]*(2.0*texel_size));
distanceFromLight = unpackFloatFromVec4i(shadowSample);
shadow += distanceFromLight <= shadowCoord.z ? 0.0 : 1.0 ;
}
shadow /= 6.0;
return shadow;
}
#else
float getShadowVal(sampler2D shadowTex,vec4 shadowCoord, float proj, float texel_size) {
vec4 shadowSample = texture2D(shadowTex,shadowCoord.st);
float distanceFromLight = unpackFloatFromVec4i(shadowSample);
float shadow = 1.0;
shadow = distanceFromLight <= (shadowCoord.z) ? 0.0 : 1.0 ;
return shadow;
}
#endif
#endif
#if !LIGHT_DEPTH_PASS
#if TEXTURE_COLOR
uniform sampler2D textureColor;
#endif
#if TEXTURE_BUMP||TEXTURE_NORMAL
varying vec3 envEyeVectorOut;
#endif
#if TEXTURE_BUMP
uniform sampler2D textureBump;
#endif
#if TEXTURE_ENVSPHERE
uniform sampler2D textureEnvSphere;
uniform float materialEnvironment;
#if TEXTURE_NORMAL
varying vec3 envTexCoordOut;
#else
varying vec2 envTexCoordOut;
#endif
#endif
#if TEXTURE_REFLECT
uniform sampler2D textureReflect;
#endif
#if TEXTURE_NORMAL
uniform sampler2D textureNormal;
#endif
uniform float materialAlpha;
#if TEXTURE_AMBIENT
uniform sampler2D textureAmbient;
#endif
#if TEXTURE_SPECULAR
uniform sampler2D textureSpecular;
#endif
#endif // !LIGHT_DEPTH_PASS
#if TEXTURE_ALPHA
uniform sampler2D textureAlpha;
#endif
varying vec4 vertexPositionOut;
vec2 cubicvr_texCoord() {
#if LIGHT_DEPTH_PASS
return vertexTexCoordOut;
#else
#if TEXTURE_BUMP
float height = texture2D(textureBump, vertexTexCoordOut.xy).r;
float v = (height) * 0.05 - 0.04; // * scale and - bias
vec3 eye = normalize(envEyeVectorOut);
return vertexTexCoordOut.xy + (eye.xy * v);
#else
//#if TEXTURE_COLOR||TEXTURE_BUMP||TEXTURE_NORMAL||TEXTURE_AMBIENT||TEXTURE_SPECULAR||TEXTURE_ALPHA
return vertexTexCoordOut;
//#endif
#endif
#endif
}
vec3 cubicvr_normal(vec2 texCoord) {
#if TEXTURE_NORMAL && !LIGHT_DEPTH_PASS
vec3 bumpNorm = vec3(texture2D(textureNormal, texCoord));
vec3 n = (vec4(normalize(vertexNormalOut),1.0)).xyz;
bumpNorm = (bumpNorm-0.5)*2.0;
bumpNorm.y = -bumpNorm.y;
return normalize((n+bumpNorm)/2.0);
#else
return normalize(vertexNormalOut);
#endif
}
vec4 cubicvr_color(vec2 texCoord) {
vec4 color = vec4(0.0,0.0,0.0,0.0);
#if !LIGHT_DEPTH_PASS
#if TEXTURE_COLOR
#if !(LIGHT_IS_POINT||LIGHT_IS_DIRECTIONAL||LIGHT_IS_SPOT||LIGHT_IS_AREA)
color = texture2D(textureColor, texCoord).rgba;
color.rgb *= materialColor;
//vec4(lightAmbient,1.0)*
#else
color = texture2D(textureColor, texCoord).rgba;
#if !TEXTURE_ALPHA
if (color.a<=0.9) {
discard;
}
#endif
color.rgb *= materialColor;
#endif
#if VERTEX_COLOR
color *= vec4(vertexColorOut,1.0);
#endif
#else
#if VERTEX_COLOR
color = vec4(vertexColorOut,1.0);
#else
color = vec4(materialColor,1.0);
#endif
#endif
#if TEXTURE_ALPHA
color.a = texture2D(textureAlpha, texCoord).r;
#if FX_DEPTH_ALPHA
if (color.a < 0.9) discard;
#else
#if MATERIAL_ALPHA
if (color.a == 0.0) discard;
#else
if (color.a < 0.9) discard;
#endif
#endif
#else
#if MATERIAL_ALPHA
color.a = materialAlpha;
#endif
#endif
#endif
return color;
}
vec4 cubicvr_lighting(vec4 color_in, vec3 n, vec2 texCoord) {
vec4 color = color_in;
#if !LIGHT_DEPTH_PASS
vec3 accum = lightAmbient;
#if LIGHT_PERPIXEL
#if LIGHT_IS_POINT
vec3 specTotal = vec3(0.0,0.0,0.0);
for (int i = 0; i < LIGHT_COUNT; i++) {
vec3 lightDirection = lightPosition[i]-vertexPositionOut.xyz;
float dist = length(lightDirection);
vec3 halfVector = normalize(vec3(0.0,0.0,1.0)+lightDirection);
float NdotL = max(dot(normalize(lightDirection),n),0.0);
if (NdotL > 0.0) {
// basic diffuse
float att = clamp(((lightDistance[i]-dist)/lightDistance[i]), 0.0, 1.0)*lightIntensity[i];
accum += att * NdotL * lightDiffuse[i] * materialDiffuse;
float NdotHV = max(dot(n, halfVector),0.0);
#if TEXTURE_SPECULAR
vec3 spec2 = lightSpecular[i] * texture2D(textureSpecular, vec2(texCoord.s, texCoord.t)).rgb * pow(NdotHV,materialShininess);
#else
vec3 spec2 = lightSpecular[i] * materialSpecular * pow(NdotHV,materialShininess);
#endif
specTotal += spec2;
}
}
color.rgb *= accum;
color.rgb += specTotal;
#endif
#if LIGHT_IS_DIRECTIONAL
float NdotL;
float NdotHV = 0.0;
vec3 specTotal = vec3(0.0,0.0,0.0);
vec3 spec2 = vec3(0.0,0.0,0.0);
vec3 halfVector;
for (int i = 0; i < LIGHT_COUNT; i++) {
halfVector = normalize(vec3(0.0,0.0,1.0)-lightDirection[i]);
NdotL = max(dot(normalize(-lightDirection[i]),n),0.0);
if (NdotL > 0.0) {
accum += lightIntensity[i] * materialDiffuse * lightDiffuse[i] * NdotL;
NdotHV = max(dot(n, halfVector),0.0);
#if TEXTURE_SPECULAR
spec2 = lightSpecular[i] * texture2D(textureSpecular, vec2(texCoord.s, texCoord.t)).rgb * pow(NdotHV,materialShininess);
#else
spec2 = lightSpecular[i] * materialSpecular * pow(NdotHV,materialShininess);
#endif
specTotal += spec2;
}
}
color.rgb *= accum;
color.rgb += specTotal;
#endif
#if LIGHT_IS_AREA
vec3 specTotal = vec3(0.0,0.0,0.0);
vec3 spec2 = vec3(0.0,0.0,0.0);
float NdotL;
float NdotHV = 0.0;
vec3 halfVector;
for (int i = 0; i < LIGHT_COUNT; i++) {
halfVector = normalize(vec3(0.0,0.0,1.0)-lightDirection[i]);
NdotL = max(dot(normalize(-lightDirection[i]),n),0.0);
if (NdotL > 0.0) {
NdotHV = max(dot(n, halfVector),0.0);
#if LIGHT_SHADOWED
vec4 shadowCoord = lightProjectionOut[i] / lightProjectionOut[i].w;
shadowCoord.z = DepthRangeA(ConvertDepth3A(shadowCoord.z,lightDepthClip[i].x,lightDepthClip[i].y),lightDepthClip[i].x,lightDepthClip[i].y);
vec4 shadowSample;
float shadow = 1.0;
// this seems to get around a shader crash ...
if (shadowCoord.s > 0.000&&shadowCoord.s < 1.000 && shadowCoord.t > 0.000 && shadowCoord.t < 1.000) if (i == 0) { shadow = getShadowVal(lightShadowMap[0],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z);}
#if LIGHT_COUNT>1
else if (i == 1) { shadow = getShadowVal(lightShadowMap[1],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z); }
#endif
#if LIGHT_COUNT>2
else if (i == 2) { shadow = getShadowVal(lightShadowMap[2],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z); }
#endif
#if LIGHT_COUNT>3
else if (i == 3) { shadow = getShadowVal(lightShadowMap[3],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z); }
#endif
#if LIGHT_COUNT>4
else if (i == 4) { shadow = getShadowVal(lightShadowMap[4],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z); }
#endif
#if LIGHT_COUNT>5
else if (i == 5) { shadow = getShadowVal(lightShadowMap[5],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z); }
#endif
#if LIGHT_COUNT>6
else if (i == 6) { shadow = getShadowVal(lightShadowMap[6],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z); }
#endif
#if LIGHT_COUNT>7
else if (i == 7) { shadow = getShadowVal(lightShadowMap[7],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z); }
#endif
accum += shadow * lightIntensity[i] * materialDiffuse * lightDiffuse[i] * NdotL;
#else
accum += lightIntensity[i] * materialDiffuse * lightDiffuse[i] * NdotL;
#endif
#if TEXTURE_SPECULAR
spec2 = lightSpecular[i] * texture2D(textureSpecular, vec2(texCoord.s, texCoord.t)).rgb * pow(NdotHV,materialShininess);
#else
spec2 = lightSpecular[i] * materialSpecular * pow(NdotHV,materialShininess);
#endif
#if LIGHT_SHADOWED
spec2 *= shadow;
#endif
specTotal += spec2;
#if LIGHT_SHADOWED
// accum = texture2D(lightShadowMap[0], vec2(shadowCoord.s, shadowCoord.t)).rgb;
#endif
}
}
color.rgb *= accum;
color.rgb += specTotal;
#endif
#if LIGHT_IS_SPOT
vec3 specTotal = vec3(0.0,0.0,0.0);
vec3 spec2 = vec3(0.0,0.0,0.0);
vec3 halfVector;
float spotEffect;
float spotDot;
float power;
for (int i = 0; i < LIGHT_COUNT; i++) {
vec3 l = lightPosition[i]-vertexPositionOut.xyz;
float dist = length(l);
float att = clamp(((lightDistance[i]-dist)/lightDistance[i]), 0.0, 1.0)*lightIntensity[i];
att = clamp(att,0.0,1.0);
spotDot = dot(normalize(-l), normalize(lightDirection[i]));
if ( spotDot < cos((lightCutOffAngle[i]/2.0)*(3.14159/180.0)) ) {
spotEffect = 0.0;
}
else {
spotEffect = pow(spotDot, 1.0);
}
#if !LIGHT_IS_PROJECTOR
att *= spotEffect;
#endif
vec3 v = normalize(-vertexPositionOut.xyz);
vec3 h = normalize(l + v);
float NdotL = max(0.0, dot(n, normalize(l)));
float NdotH = max(0.0, dot(n, h));
if (NdotL > 0.0) {
power = pow(NdotH, materialShininess);
}
else {
power = 0.0;
}
#if LIGHT_SHADOWED
vec4 shadowCoord = lightProjectionOut[i] / lightProjectionOut[i].w;
shadowCoord.z = DepthRangeA(ConvertDepth3A(shadowCoord.z,lightDepthClip[i].x,lightDepthClip[i].y),lightDepthClip[i].x,lightDepthClip[i].y);
vec4 shadowSample;
float shadow = 1.0;
// this seems to get around a shader crash ...
if (shadowCoord.s >= 0.000&&shadowCoord.s <= 1.000 && shadowCoord.t >= 0.000 && shadowCoord.t <= 1.000) if (i == 0) { shadow = getShadowVal(lightShadowMap[0],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z);}
#if LIGHT_COUNT>1
else if (i == 1) { shadow = getShadowVal(lightShadowMap[1],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z); }
#endif
#if LIGHT_COUNT>2
else if (i == 2) { shadow = getShadowVal(lightShadowMap[2],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z); }
#endif
#if LIGHT_COUNT>3
else if (i == 3) { shadow = getShadowVal(lightShadowMap[3],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z); }
#endif
#if LIGHT_COUNT>4
else if (i == 4) { shadow = getShadowVal(lightShadowMap[4],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z); }
#endif
#if LIGHT_COUNT>5
else if (i == 5) { shadow = getShadowVal(lightShadowMap[5],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z); }
#endif
#if LIGHT_COUNT>6
else if (i == 6) { shadow = getShadowVal(lightShadowMap[6],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z); }
#endif
#if LIGHT_COUNT>7
else if (i == 7) { shadow = getShadowVal(lightShadowMap[7],shadowCoord,lightProjectionOut[i].w,lightDepthClip[i].z); }
#endif
att = att * shadow;
#endif
#if LIGHT_IS_PROJECTOR && LIGHT_SHADOWED
if (shadowCoord.s >= 0.0&&shadowCoord.s <= 1.0 && shadowCoord.t >= 0.0 && shadowCoord.t <= 1.0 && spotDot > cos((90.0)*(3.14159/180.0))) {
vec3 projTex = texture2D(lightProjectionMap[i],shadowCoord.st).rgb;
accum += att * projTex * lightIntensity[i] * materialDiffuse * lightDiffuse[i] * NdotL;
}
#else
accum += att * lightDiffuse[i] * materialDiffuse * NdotL;
#endif
#if TEXTURE_SPECULAR
spec2 = lightSpecular[i] * texture2D(textureSpecular, vec2(texCoord.s, texCoord.t)).rgb * power;
#else
spec2 = lightSpecular[i] * materialSpecular * power;
#endif
#if LIGHT_SHADOWED
spec2 *= shadow;
#endif
specTotal += spec2*spotEffect;
}
color.rgb *= accum;
color.rgb += specTotal;
#if LIGHT_SHADOWED
// color = texture2D(lightShadowMap[0], vec2(texCoord.s, texCoord.t)).rgba;
#endif
#endif
#else
// vertex lighting
#if LIGHT_IS_POINT||LIGHT_IS_DIRECTIONAL||LIGHT_IS_SPOT||LIGHT_IS_AREA
color.rgb *= lightColorOut;
color.rgb += lightSpecularOut;
#endif
#endif // LIGHT_PERPIXEL
#if TEXTURE_AMBIENT
#if LIGHT_IS_POINT||LIGHT_IS_DIRECTIONAL||LIGHT_IS_SPOT||LIGHT_IS_AREA
color.rgb += texture2D(textureAmbient, texCoord).rgb*(vec3(1.0,1.0,1.0)+materialColor*materialAmbient);
#else
color.rgb = color.rgb*texture2D(textureAmbient, texCoord).rgb;
#endif
#else
#if TEXTURE_COLOR
color.rgb += materialAmbient*texture2D(textureColor, texCoord).rgb;
#else
color.rgb += materialColor*materialAmbient;
#endif
#endif
#endif
return color;
}
vec4 cubicvr_environment(vec4 color_in, vec3 n, vec2 texCoord) {
vec4 color = color_in;
#if !LIGHT_DEPTH_PASS
#if TEXTURE_REFLECT
float environmentAmount = texture2D( textureReflect, texCoord).r;
#endif
#if TEXTURE_ENVSPHERE
#if TEXTURE_NORMAL
vec3 r = reflect( envTexCoordOut, n );
float m = 2.0 * sqrt( r.x*r.x + r.y*r.y + (r.z+1.0)*(r.z+1.0) );
vec3 coord;
coord.s = r.x/m + 0.5;
coord.t = r.y/m + 0.5;
#if TEXTURE_REFLECT
color.rgb += materialColor*texture2D( textureEnvSphere, coord.st).rgb * environmentAmount;
#else
color.rgb += materialColor*texture2D( textureEnvSphere, coord.st).rgb * materialEnvironment;
#endif
#else
#if TEXTURE_REFLECT
color.rgb += materialColor*texture2D( textureEnvSphere, envTexCoordOut).rgb * environmentAmount;
#else
color.rgb += materialColor*texture2D( textureEnvSphere, envTexCoordOut).rgb * materialEnvironment;
#endif
#endif
#endif // TEXTURE_ENVSPHERE
#endif // ! LIGHT_DEPTH_PASS
#if FX_DEPTH_ALPHA
#if !MATERIAL_ALPHA
float linear_depth = DepthRange( ConvertDepth3(gl_FragCoord.z) );
color.a = linear_depth;
#endif
#endif
return color;
}
#if LIGHT_DEPTH_PASS
vec4 cubicvr_depthPack(vec2 texCoord) {
#if TEXTURE_ALPHA
float alphaVal = texture2D(textureAlpha, texCoord).r;
if (alphaVal < 0.9) discard;
#endif
return packFloatToVec4i(DepthRange( ConvertDepth3(gl_FragCoord.z)));
}
#endif
#define customShader_splice 1
void main(void)
{
vec2 texCoord = cubicvr_texCoord();
#if !LIGHT_DEPTH_PASS
vec4 color = cubicvr_color(texCoord);
vec3 normal = cubicvr_normal(texCoord);
color = cubicvr_environment(color,normal,texCoord);
color = cubicvr_lighting(color,normal,texCoord);
gl_FragColor = clamp(color,0.0,1.0);
#else // LIGHT_DEPTH_PASS for shadows, discard to cut
gl_FragColor = cubicvr_depthPack(texCoord);
#endif
}