diff options
Diffstat (limited to 'assets/shaders/test_fshader.glsl')
-rw-r--r-- | assets/shaders/test_fshader.glsl | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/assets/shaders/test_fshader.glsl b/assets/shaders/test_fshader.glsl new file mode 100644 index 00000000..3a0af39f --- /dev/null +++ b/assets/shaders/test_fshader.glsl | |||
@@ -0,0 +1,159 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | |||
8 | #ifdef GL_ES | ||
9 | precision highp float; | ||
10 | #endif | ||
11 | |||
12 | // lighting uniforms | ||
13 | uniform vec3 u_light0Pos; | ||
14 | uniform vec4 u_light0Diff; | ||
15 | uniform vec4 u_light0Amb; | ||
16 | |||
17 | // diffuse map | ||
18 | uniform sampler2D colMap; | ||
19 | |||
20 | // environment map | ||
21 | uniform sampler2D envMap; | ||
22 | |||
23 | // normal map | ||
24 | uniform sampler2D normalMap; | ||
25 | |||
26 | // glow map | ||
27 | uniform sampler2D glowMap; | ||
28 | |||
29 | // glow map | ||
30 | uniform sampler2D depthMap; | ||
31 | |||
32 | //material uniforms | ||
33 | uniform vec4 u_matAmbient; | ||
34 | uniform vec4 u_matDiffuse; | ||
35 | uniform vec4 u_matSpecular; | ||
36 | uniform float u_matShininess; | ||
37 | uniform vec4 u_matEmission; | ||
38 | uniform float u_renderGlow; | ||
39 | |||
40 | // varyings | ||
41 | varying vec4 vNormal; // w = texcoord.x | ||
42 | varying vec4 vECPos; // w = texcoord.y | ||
43 | varying vec3 vEyePos; | ||
44 | varying vec4 vShadowCoord; | ||
45 | varying vec2 vEnvTexCoord; | ||
46 | varying float vDiffuseIntensity; | ||
47 | |||
48 | #ifdef PC | ||
49 | |||
50 | void main() | ||
51 | { | ||
52 | vec4 rgba_depth = texture2D(depthMap, vShadowCoord.xy/vShadowCoord.w, -32.0); | ||
53 | const vec4 bit_shift = vec4(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0, 1.0); | ||
54 | float dist = vShadowCoord.w/200.0; | ||
55 | float d = dot(rgba_depth, bit_shift); | ||
56 | float shadowCoef = (dist > d + 0.00779) ? (0.6) : (1.0); | ||
57 | |||
58 | vec4 colMapTexel = vec4(0); | ||
59 | if (u_renderGlow <= 0.5) { | ||
60 | colMapTexel = vec4(texture2D(colMap, vec2(vNormal.w, vECPos.w)).rgb, 1.0); | ||
61 | } else { | ||
62 | colMapTexel = vec4(texture2D(glowMap, vec2(vNormal.w, vECPos.w)).rgb, 1.0); | ||
63 | } | ||
64 | |||
65 | // normal mapping | ||
66 | vec3 normal = normalize(vNormal.xyz); | ||
67 | vec3 mapNormal = texture2D(normalMap, vec2(vNormal.w, vECPos.w)).xyz * 2.0 - 1.0; | ||
68 | mapNormal = normalize(mapNormal.x*vec3(normal.z, 0.0, -normal.x) + vec3(0.0, mapNormal.y, 0.0) + mapNormal.z*normal); | ||
69 | |||
70 | // create envmap coordinates | ||
71 | vec3 r = reflect( normalize(vec3(vECPos.xyz - vEyePos.xyz)), mapNormal); | ||
72 | float m = 2.0 * sqrt( r.x*r.x + r.y*r.y + r.z*r.z ); | ||
73 | |||
74 | // calculate environment map texel | ||
75 | vec4 envMapTexel = vec4(texture2D(envMap, vec2(r.x/m + 0.5, r.y/m + 0.5)).rgb, 0.0); | ||
76 | |||
77 | // lighting | ||
78 | vec3 lightDirection = u_light0Pos - vECPos.xyz; | ||
79 | float lightDist = length(lightDirection); | ||
80 | lightDirection /= lightDist; | ||
81 | |||
82 | float attenuation = clamp(1.0 - lightDist * 0.01, 0.0, 1.0); | ||
83 | |||
84 | vec3 halfVec = normalize(lightDirection + vEyePos); | ||
85 | |||
86 | float diffuseIntensity = max(0.0, dot(mapNormal, lightDirection)); | ||
87 | float specularModifier = max(0.0, dot(mapNormal, halfVec)); | ||
88 | |||
89 | float pf; | ||
90 | if(diffuseIntensity == 0.0) | ||
91 | pf = 0.0; | ||
92 | else | ||
93 | pf = pow(specularModifier, 76.0); | ||
94 | |||
95 | vec4 ambient = u_matAmbient * u_light0Amb; | ||
96 | |||
97 | vec4 diffuse = u_matDiffuse * (colMapTexel + envMapTexel)*shadowCoef; | ||
98 | |||
99 | if (u_renderGlow <= 0.5) { | ||
100 | diffuse *= u_light0Diff; | ||
101 | } | ||
102 | |||
103 | vec4 specular = 2.0 * pf * envMapTexel; | ||
104 | |||
105 | //gl_FragColor = vec4(dist, dist, dist, 1.0); | ||
106 | gl_FragColor = ((colMapTexel*(ambient + diffuse)) + specular); | ||
107 | } | ||
108 | |||
109 | #endif | ||
110 | |||
111 | #ifdef DEVICE | ||
112 | |||
113 | void main() | ||
114 | { | ||
115 | vec4 colMapTexel = vec4(texture2D(colMap, vec2(vNormal.w, vECPos.w)).rgb, 1.0); | ||
116 | |||
117 | // // normal mapping | ||
118 | vec3 normal = normalize(vNormal.xyz); | ||
119 | // vec3 mapNormal = texture2D(normalMap, vec2(vNormal.w, vECPos.w)).xyz * 2.0 - 1.0; | ||
120 | // mapNormal = normalize(mapNormal.x*vec3(normal.z, 0.0, -normal.x) + vec3(0.0, mapNormal.y, 0.0) + mapNormal.z*normal); | ||
121 | // | ||
122 | // // create envmap coordinates | ||
123 | // vec3 r = reflect( (vec3(vECPos.xyz - vEyePos.xyz)), mapNormal); | ||
124 | // float m = 2.0 * length(r); | ||
125 | |||
126 | // calculate environment map texel | ||
127 | //vec4 envMapTexel = vec4(texture2D(envMap, vec2(r.x/m + 0.5, r.y/m + 0.5)).rgb, 0.0); | ||
128 | vec4 envMapTexel = vec4(texture2D(envMap, vEnvTexCoord).rgb, 0.0); | ||
129 | |||
130 | // lighting | ||
131 | //vec3 lightDirection = normalize(u_light0Pos - vECPos.xyz); | ||
132 | // float lightDist = length(lightDirection); | ||
133 | // lightDirection /= lightDist; | ||
134 | |||
135 | |||
136 | //vec3 halfVec = normalize(lightDirection + vEyePos); | ||
137 | |||
138 | //float diffuseIntensity = max(0.0, dot(normal, lightDirection)); | ||
139 | // float specularModifier = max(0.0, dot(mapNormal, halfVec)); | ||
140 | |||
141 | // float pf; | ||
142 | //if(diffuseIntensity == 0.0) | ||
143 | //pf = 0.0; | ||
144 | //else | ||
145 | //pf = pow(specularModifier, 76.0); | ||
146 | |||
147 | // vec4 ambient = u_matAmbient * u_light0Amb; | ||
148 | |||
149 | vec4 diffuse = u_matDiffuse*(colMapTexel + envMapTexel)*(vDiffuseIntensity + u_matAmbient); | ||
150 | |||
151 | //diffuse *= u_light0Diff * diffuseIntensity; | ||
152 | |||
153 | //vec4 specular = envMapTexel; | ||
154 | |||
155 | //gl_FragColor = vec4(dist, dist, dist, 1.0); | ||
156 | gl_FragColor = diffuse;//(colMapTexel*(ambient + diffuse)) + specular; | ||
157 | } | ||
158 | |||
159 | #endif \ No newline at end of file | ||