aboutsummaryrefslogtreecommitdiff
path: root/assets/shaders/test_fshader_full.glsl
diff options
context:
space:
mode:
Diffstat (limited to 'assets/shaders/test_fshader_full.glsl')
-rw-r--r--assets/shaders/test_fshader_full.glsl82
1 files changed, 82 insertions, 0 deletions
diff --git a/assets/shaders/test_fshader_full.glsl b/assets/shaders/test_fshader_full.glsl
new file mode 100644
index 00000000..ef721b39
--- /dev/null
+++ b/assets/shaders/test_fshader_full.glsl
@@ -0,0 +1,82 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/>
3No 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
9precision highp float;
10#endif
11
12// lighting uniforms
13uniform vec3 u_lightPos;
14uniform vec4 u_lightDiff;
15uniform vec4 u_lightAmb;
16
17// diffuse map
18uniform sampler2D colMap;
19
20// environment map
21uniform sampler2D envMap;
22
23// normal map
24uniform sampler2D normalMap;
25
26//material uniforms
27uniform vec4 u_matAmbient;
28uniform vec4 u_matDiffuse;
29uniform vec4 u_matSpecular;
30uniform float u_matShininess;
31uniform vec4 u_matEmission;
32uniform float u_renderGlow;
33
34// varyings
35varying vec4 vNormal; // w = texcoord.x
36varying vec4 vECPos; // w = texcoord.y
37varying vec3 vEyePos;
38
39void main()
40{
41 vec4 colMapTexel = vec4(texture2D(colMap, vec2(vNormal.w, vECPos.w)).rgb, 1.0);
42
43 // normal mapping
44 vec3 normal = normalize(vNormal.xyz);
45 vec3 mapNormal = texture2D(normalMap, vec2(vNormal.w, vECPos.w)).xyz * 2.0 - 1.0;
46 mapNormal = normalize(mapNormal.x*vec3(normal.z, 0.0, -normal.x) + vec3(0.0, mapNormal.y, 0.0) + mapNormal.z*normal);
47
48 // create envmap coordinates
49 vec3 r = reflect( normalize(vec3(vECPos.xyz - vEyePos.xyz)), mapNormal);
50 float m = 2.0 * sqrt( r.x*r.x + r.y*r.y + r.z*r.z );
51
52 // calculate environment map texel
53 vec4 envMapTexel = vec4(texture2D(envMap, vec2(r.x/m + 0.5, r.y/m + 0.5)).rgb, 0.0);
54
55 // lighting
56 vec3 lightDirection = u_lightPos - vECPos.xyz;
57 float lightDist = length(lightDirection);
58 lightDirection /= lightDist;
59
60 float attenuation = clamp(1.0 - lightDist * 0.01, 0.0, 1.0);
61
62 vec3 halfVec = normalize(lightDirection + vEyePos);
63
64 float diffuseIntensity = max(0.0, dot(mapNormal, lightDirection));
65 float specularModifier = max(0.0, dot(mapNormal, halfVec));
66
67 float pf;
68 if(diffuseIntensity == 0.0)
69 pf = 0.0;
70 else
71 pf = pow(specularModifier, 76.0);
72
73 vec4 ambient = u_matAmbient * u_lightAmb;
74 vec4 diffuse = u_matDiffuse * (colMapTexel + envMapTexel);
75
76 if (u_renderGlow <= 0.5)
77 diffuse *= u_lightDiff * diffuseIntensity * attenuation;
78
79 vec4 specular = 2.0 * pf * envMapTexel;
80
81 gl_FragColor = (colMapTexel*(ambient + diffuse)) + specular + vec4(0.0,0.0,0.0,1.0);
82}