aboutsummaryrefslogtreecommitdiff
path: root/assets/shaders/ub_fshader.glsl
diff options
context:
space:
mode:
Diffstat (limited to 'assets/shaders/ub_fshader.glsl')
-rwxr-xr-xassets/shaders/ub_fshader.glsl455
1 files changed, 228 insertions, 227 deletions
diff --git a/assets/shaders/ub_fshader.glsl b/assets/shaders/ub_fshader.glsl
index e4e0e2d3..408b1184 100755
--- a/assets/shaders/ub_fshader.glsl
+++ b/assets/shaders/ub_fshader.glsl
@@ -1,24 +1,25 @@
1/* <copyright> 1/* <copyright>
2Copyright (c) 2012, Motorola Mobility, Inc 2Copyright (c) 2012, Motorola Mobility LLC.
3All Rights Reserved. 3All Rights Reserved.
4BSD License.
5 4
6Redistribution and use in source and binary forms, with or without 5Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met: 6modification, are permitted provided that the following conditions are met:
8 7
9 - Redistributions of source code must retain the above copyright notice, 8* Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer. 9 this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright 10
12 notice, this list of conditions and the following disclaimer in the 11* Redistributions in binary form must reproduce the above copyright notice,
13 documentation and/or other materials provided with the distribution. 12 this list of conditions and the following disclaimer in the documentation
14 - Neither the name of Motorola Mobility nor the names of its contributors 13 and/or other materials provided with the distribution.
15 may be used to endorse or promote products derived from this software 14
16 without specific prior written permission. 15* Neither the name of Motorola Mobility LLC nor the names of its
16 contributors may be used to endorse or promote products derived from this
17 software without specific prior written permission.
17 18
18THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 22ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
@@ -30,257 +31,257 @@ POSSIBILITY OF SUCH DAMAGE.
30 31
31// defines 32// defines
32#if defined( GL_ES ) 33#if defined( GL_ES )
33 precision highp float; 34 precision highp float;
34#endif 35#endif
35 36
36uniform mat4 u_viewMatrix; 37uniform mat4 u_viewMatrix;
37 38
38#if defined( MATERIAL ) 39#if defined( MATERIAL )
39 uniform vec4 u_ambientColor; 40 uniform vec4 u_ambientColor;
40 uniform vec4 u_diffuseColor; 41 uniform vec4 u_diffuseColor;
41 uniform vec4 u_specularColor; 42 uniform vec4 u_specularColor;
42 uniform float u_specularPower; 43 uniform float u_specularPower;
43#endif 44#endif
44 45
45#if defined( LIGHTING ) 46#if defined( LIGHTING )
46 varying vec3 v_normal; 47 varying vec3 v_normal;
47 #if defined( LIGHT_0 ) 48 #if defined( LIGHT_0 )
48// uniform int u_light0Type; 49// uniform int u_light0Type;
49 uniform vec3 u_light0Pos; 50 uniform vec3 u_light0Pos;
50 uniform vec3 u_light0Dir; 51 uniform vec3 u_light0Dir;
51 uniform vec3 u_light0Atten; 52 uniform vec3 u_light0Atten;
52 uniform vec2 u_light0Spot; 53 uniform vec2 u_light0Spot;
53 uniform vec4 u_light0Color; 54 uniform vec4 u_light0Color;
54 uniform vec4 u_light0Specular; 55 uniform vec4 u_light0Specular;
55 varying vec3 v_light0Dir; 56 varying vec3 v_light0Dir;
56 varying vec3 v_light0SpotDir; 57 varying vec3 v_light0SpotDir;
57 #endif 58 #endif
58 59
59 #if defined( LIGHT_1 ) 60 #if defined( LIGHT_1 )
60// uniform int u_light1Type; 61// uniform int u_light1Type;
61 uniform vec3 u_light1Pos; 62 uniform vec3 u_light1Pos;
62 uniform vec3 u_light1Dir; 63 uniform vec3 u_light1Dir;
63 uniform vec3 u_light1Atten; 64 uniform vec3 u_light1Atten;
64 uniform vec2 u_light1Spot; 65 uniform vec2 u_light1Spot;
65 uniform vec4 u_light1Color; 66 uniform vec4 u_light1Color;
66 uniform vec4 u_light1Specular; 67 uniform vec4 u_light1Specular;
67 varying vec3 v_light1Dir; 68 varying vec3 v_light1Dir;
68 varying vec3 v_light1SpotDir; 69 varying vec3 v_light1SpotDir;
69 #endif 70 #endif
70 71
71 #if defined( LIGHT_2 ) 72 #if defined( LIGHT_2 )
72// uniform int u_light2Type; 73// uniform int u_light2Type;
73 uniform vec3 u_light2Pos; 74 uniform vec3 u_light2Pos;
74 uniform vec3 u_light2Dir; 75 uniform vec3 u_light2Dir;
75 uniform vec3 u_light2Atten; 76 uniform vec3 u_light2Atten;
76 uniform vec2 u_light2Spot; 77 uniform vec2 u_light2Spot;
77 uniform vec4 u_light2Color; 78 uniform vec4 u_light2Color;
78 uniform vec4 u_light2Specular; 79 uniform vec4 u_light2Specular;
79 varying vec3 v_light2Dir; 80 varying vec3 v_light2Dir;
80 varying vec3 v_light2SpotDir; 81 varying vec3 v_light2SpotDir;
81 #endif 82 #endif
82 83
83 #if defined( LIGHT_3 ) 84 #if defined( LIGHT_3 )
84// uniform int u_light3Type; 85// uniform int u_light3Type;
85 uniform vec3 u_light3Pos; 86 uniform vec3 u_light3Pos;
86 uniform vec3 u_light3Dir; 87 uniform vec3 u_light3Dir;
87 uniform vec3 u_light3Atten; 88 uniform vec3 u_light3Atten;
88 uniform vec2 u_light3Spot; 89 uniform vec2 u_light3Spot;
89 uniform vec4 u_light3Color; 90 uniform vec4 u_light3Color;
90 uniform vec4 u_light3Specular; 91 uniform vec4 u_light3Specular;
91 varying vec3 v_light3Dir; 92 varying vec3 v_light3Dir;
92 varying vec3 v_light3SpotDir; 93 varying vec3 v_light3SpotDir;
93 #endif 94 #endif
94#endif 95#endif
95 96
96#if defined( ENVIRONMENT_MAP ) 97#if defined( ENVIRONMENT_MAP )
97 uniform float u_envReflection; 98 uniform float u_envReflection;
98#endif 99#endif
99 100
100uniform vec3 u_eye; 101uniform vec3 u_eye;
101 102
102uniform sampler2D s_diffuseMap; 103uniform sampler2D s_diffuseMap;
103uniform sampler2D s_normalMap; 104uniform sampler2D s_normalMap;
104uniform sampler2D s_envMap; 105uniform sampler2D s_envMap;
105uniform sampler2D s_specMap; 106uniform sampler2D s_specMap;
106 107
107varying vec3 v_mvPos; 108varying vec3 v_mvPos;
108varying vec3 v_eyeDir; 109varying vec3 v_eyeDir;
109varying vec2 v_texcoord; 110varying vec2 v_texcoord;
110 111
111void main() { 112void main() {
112 // these are the four principle color elements making up the final fragment equation. 113 // these are the four principle color elements making up the final fragment equation.
113 vec4 a = vec4(0.0,0.0,0.0,0.0); // ambient contribution 114 vec4 a = vec4(0.0,0.0,0.0,0.0); // ambient contribution
114 vec4 d = vec4(0.0,0.0,0.0,0.0); // diffuse contribution 115 vec4 d = vec4(0.0,0.0,0.0,0.0); // diffuse contribution
115 vec4 s = vec4(0.0,0.0,0.0,0.0); // specular contribution 116 vec4 s = vec4(0.0,0.0,0.0,0.0); // specular contribution
116 vec4 l = vec4(0.0,0.0,0.0,0.0); // lighting contribution 117 vec4 l = vec4(0.0,0.0,0.0,0.0); // lighting contribution
117 118
118#if defined( MATERIAL ) 119#if defined( MATERIAL )
119 a += u_ambientColor; 120 a += u_ambientColor;
120 d += u_diffuseColor; 121 d += u_diffuseColor;
121#endif 122#endif
122 123
123#if defined( DIFFUSE_MAP ) 124#if defined( DIFFUSE_MAP )
124 d *= texture2D(s_diffuseMap, v_texcoord); 125 d *= texture2D(s_diffuseMap, v_texcoord);
125#endif 126#endif
126 127
127#if ( defined( LIGHTING ) || defined( ENVIRONMENT_MAPPING ) ) 128#if ( defined( LIGHTING ) || defined( ENVIRONMENT_MAPPING ) )
128 vec3 normal = normalize( v_normal ); 129 vec3 normal = normalize( v_normal );
129#endif 130#endif
130 131
131#if defined( LIGHTING ) 132#if defined( LIGHTING )
132 #if defined( NORMAL_MAP ) 133 #if defined( NORMAL_MAP )
133 vec4 normalMap = texture2D(s_normalMap, v_texcoord); 134 vec4 normalMap = texture2D(s_normalMap, v_texcoord);
134 normalMap = vec4( (normalMap.xyz * 2.0 - 1.0), 0.0 ); 135 normalMap = vec4( (normalMap.xyz * 2.0 - 1.0), 0.0 );
135 normal = normalize(normalMap.x*vec3(normal.z, 0.0, normal.x) + vec3(0.0, normalMap.y, 0.0) + normalMap.z*normal); 136 normal = normalize(normalMap.x*vec3(normal.z, 0.0, normal.x) + vec3(0.0, normalMap.y, 0.0) + normalMap.z*normal);
136 #endif // NORMAL_MAP 137 #endif // NORMAL_MAP
137 138
138 #if defined( LIGHT_0 ) 139 #if defined( LIGHT_0 )
139 { 140 {
140 // diffuse lighting 141 // diffuse lighting
141 float ldist = length( v_light0Dir.xyz ); 142 float ldist = length( v_light0Dir.xyz );
142 vec3 ldir = v_light0Dir.xyz / ldist; 143 vec3 ldir = v_light0Dir.xyz / ldist;
143 144
144 float atten = 1.0; 145 float atten = 1.0;
145 146
146 #if ( LIGHT_0 > 0 ) 147 #if ( LIGHT_0 > 0 )
147 atten = 1.0 / ( u_light0Atten.x + u_light0Atten.y * ldist + u_light0Atten.z * ( ldist * ldist ) ); 148 atten = 1.0 / ( u_light0Atten.x + u_light0Atten.y * ldist + u_light0Atten.z * ( ldist * ldist ) );
148 #if (LIGHT_0 == 2) 149 #if (LIGHT_0 == 2)
149 float spotAngle = dot( ldir, normalize( v_light0SpotDir ) ); 150 float spotAngle = dot( ldir, normalize( v_light0SpotDir ) );
150