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.glsl432
1 files changed, 216 insertions, 216 deletions
diff --git a/assets/shaders/ub_fshader.glsl b/assets/shaders/ub_fshader.glsl
index e4e0e2d3..9b37899d 100755
--- a/assets/shaders/ub_fshader.glsl
+++ b/assets/shaders/ub_fshader.glsl
@@ -30,257 +30,257 @@ POSSIBILITY OF SUCH DAMAGE.
30 30
31// defines 31// defines
32#if defined( GL_ES ) 32#if defined( GL_ES )
33 precision highp float; 33 precision highp float;
34#endif 34#endif
35 35
36uniform mat4 u_viewMatrix; 36uniform mat4 u_viewMatrix;
37 37
38#if defined( MATERIAL ) 38#if defined( MATERIAL )
39 uniform vec4 u_ambientColor; 39 uniform vec4 u_ambientColor;
40 uniform vec4 u_diffuseColor; 40 uniform vec4 u_diffuseColor;
41 uniform vec4 u_specularColor; 41 uniform vec4 u_specularColor;
42 uniform float u_specularPower; 42 uniform float u_specularPower;
43#endif 43#endif
44 44
45#if defined( LIGHTING ) 45#if defined( LIGHTING )
46 varying vec3 v_normal; 46 varying vec3 v_normal;
47 #if defined( LIGHT_0 ) 47 #if defined( LIGHT_0 )
48// uniform int u_light0Type; 48// uniform int u_light0Type;
49 uniform vec3 u_light0Pos; 49 uniform vec3 u_light0Pos;
50 uniform vec3 u_light0Dir; 50 uniform vec3 u_light0Dir;
51 uniform vec3 u_light0Atten; 51 uniform vec3 u_light0Atten;
52 uniform vec2 u_light0Spot; 52 uniform vec2 u_light0Spot;
53 uniform vec4 u_light0Color; 53 uniform vec4 u_light0Color;
54 uniform vec4 u_light0Specular; 54 uniform vec4 u_light0Specular;
55 varying vec3 v_light0Dir; 55 varying vec3 v_light0Dir;
56 varying vec3 v_light0SpotDir; 56 varying vec3 v_light0SpotDir;
57 #endif 57 #endif
58 58
59 #if defined( LIGHT_1 ) 59 #if defined( LIGHT_1 )
60// uniform int u_light1Type; 60// uniform int u_light1Type;
61 uniform vec3 u_light1Pos; 61 uniform vec3 u_light1Pos;
62 uniform vec3 u_light1Dir; 62 uniform vec3 u_light1Dir;
63 uniform vec3 u_light1Atten; 63 uniform vec3 u_light1Atten;
64 uniform vec2 u_light1Spot; 64 uniform vec2 u_light1Spot;
65 uniform vec4 u_light1Color; 65 uniform vec4 u_light1Color;
66 uniform vec4 u_light1Specular; 66 uniform vec4 u_light1Specular;
67 varying vec3 v_light1Dir; 67 varying vec3 v_light1Dir;
68 varying vec3 v_light1SpotDir; 68 varying vec3 v_light1SpotDir;
69 #endif 69 #endif
70 70
71 #if defined( LIGHT_2 ) 71 #if defined( LIGHT_2 )
72// uniform int u_light2Type; 72// uniform int u_light2Type;
73 uniform vec3 u_light2Pos; 73 uniform vec3 u_light2Pos;
74 uniform vec3 u_light2Dir; 74 uniform vec3 u_light2Dir;
75 uniform vec3 u_light2Atten; 75 uniform vec3 u_light2Atten;
76 uniform vec2 u_light2Spot; 76 uniform vec2 u_light2Spot;
77 uniform vec4 u_light2Color; 77 uniform vec4 u_light2Color;
78 uniform vec4 u_light2Specular; 78 uniform vec4 u_light2Specular;
79 varying vec3 v_light2Dir; 79 varying vec3 v_light2Dir;
80 varying vec3 v_light2SpotDir; 80 varying vec3 v_light2SpotDir;
81 #endif 81 #endif
82 82
83 #if defined( LIGHT_3 ) 83 #if defined( LIGHT_3 )
84// uniform int u_light3Type; 84// uniform int u_light3Type;
85 uniform vec3 u_light3Pos; 85 uniform vec3 u_light3Pos;
86 uniform vec3 u_light3Dir; 86 uniform vec3 u_light3Dir;
87 uniform vec3 u_light3Atten; 87 uniform vec3 u_light3Atten;
88 uniform vec2 u_light3Spot; 88 uniform vec2 u_light3Spot;
89 uniform vec4 u_light3Color; 89 uniform vec4 u_light3Color;
90 uniform vec4 u_light3Specular; 90 uniform vec4 u_light3Specular;
91 varying vec3 v_light3Dir; 91 varying vec3 v_light3Dir;
92 varying vec3 v_light3SpotDir; 92 varying vec3 v_light3SpotDir;
93 #endif 93 #endif
94#endif 94#endif
95 95
96#if defined( ENVIRONMENT_MAP ) 96#if defined( ENVIRONMENT_MAP )
97 uniform float u_envReflection; 97 uniform float u_envReflection;
98#endif 98#endif
99 99
100uniform vec3 u_eye; 100uniform vec3 u_eye;
101 101
102uniform sampler2D s_diffuseMap; 102uniform sampler2D s_diffuseMap;
103uniform sampler2D s_normalMap; 103uniform sampler2D s_normalMap;
104uniform sampler2D s_envMap; 104uniform sampler2D s_envMap;
105uniform sampler2D s_specMap; 105uniform sampler2D s_specMap;
106 106
107varying vec3 v_mvPos; 107varying vec3 v_mvPos;
108varying vec3 v_eyeDir; 108varying vec3 v_eyeDir;
109varying vec2 v_texcoord; 109varying vec2 v_texcoord;
110 110
111void main() { 111void main() {
112 // these are the four principle color elements making up the final fragment equation. 112 // 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 113 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 114 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 115 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 116 vec4 l = vec4(0.0,0.0,0.0,0.0); // lighting contribution
117 117
118#if defined( MATERIAL ) 118#if defined( MATERIAL )
119 a += u_ambientColor; 119 a += u_ambientColor;
120 d += u_diffuseColor; 120 d += u_diffuseColor;
121#endif 121#endif
122 122
123#if defined( DIFFUSE_MAP ) 123#if defined( DIFFUSE_MAP )
124 d *= texture2D(s_diffuseMap, v_texcoord); 124 d *= texture2D(s_diffuseMap, v_texcoord);
125#endif 125#endif
126 126
127#if ( defined( LIGHTING ) || defined( ENVIRONMENT_MAPPING ) ) 127#if ( defined( LIGHTING ) || defined( ENVIRONMENT_MAPPING ) )
128 vec3 normal = normalize( v_normal ); 128 vec3 normal = normalize( v_normal );
129#endif 129#endif
130 130
131#if defined( LIGHTING ) 131#if defined( LIGHTING )
132 #if defined( NORMAL_MAP ) 132 #if defined( NORMAL_MAP )
133 vec4 normalMap = texture2D(s_normalMap, v_texcoord); 133 vec4 normalMap = texture2D(s_normalMap, v_texcoord);
134 normalMap = vec4( (normalMap.xyz * 2.0 - 1.0), 0.0 ); 134 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); 135 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 136 #endif // NORMAL_MAP
137 137
138 #if defined( LIGHT_0 ) 138 #if defined( LIGHT_0 )
139 { 139 {
140 // diffuse lighting 140 // diffuse lighting
141 float ldist = length( v_light0Dir.xyz ); 141 float ldist = length( v_light0Dir.xyz );
142 vec3 ldir = v_light0Dir.xyz / ldist; 142 vec3 ldir = v_light0Dir.xyz / ldist;
143 143
144 float atten = 1.0; 144 float atten = 1.0;
145 145
146 #if ( LIGHT_0 > 0 ) 146 #if ( LIGHT_0 > 0 )
147 atten = 1.0 / ( u_light0Atten.x + u_light0Atten.y * ldist + u_light0Atten.z * ( ldist * ldist ) ); 147 atten = 1.0 / ( u_light0Atten.x + u_light0Atten.y * ldist + u_light0Atten.z * ( ldist * ldist ) );
148 #if (LIGHT_0 == 2) 148 #if (LIGHT_0 == 2)
149 float spotAngle = dot( ldir, normalize( v_light0SpotDir ) ); 149 float spotAngle = dot( ldir, normalize( v_light0SpotDir ) );
150 float spotAtten = 0.0; 150 float spotAtten = 0.0;
151 if ( spotAngle > u_light0Spot.y ) { 151 if ( spotAngle > u_light0Spot.y ) {
152 spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light0Spot.y ) / ( u_light0Spot.x - u_light0Spot.y ) ) ); 152 spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light0Spot.y ) / ( u_light0Spot.x - u_light0Spot.y ) ) );
153 } 153 }
154 atten *= spotAtten; 154 atten *= spotAtten;
155 #endif 155 #endif
156 #endif 156 #endif
157 157
158 float ndotl = max( 0.0, dot( normal, ldir ) ); 158 float ndotl = max( 0.0, dot( normal, ldir ) );
159 l += ndotl * atten * u_light0Color; 159 l += ndotl * atten * u_light0Color;
160 160
161 #if defined( LIGHT_0_SPECULAR ) 161 #if defined( LIGHT_0_SPECULAR )
162 // specular contribution 162 // specular contribution
163 vec3 halfAngleVec = normalize( normalize( v_light0Dir.xyz ) + vec3(0.0,0.0,1.0) ); 163 vec3 halfAngleVec = normalize( normalize( v_light0Dir.xyz ) + vec3(0.0,0.0,1.0) );
164 float ndoth = max( 0.0, dot( normal, halfAngleVec ) ); 164 float ndoth = max( 0.0, dot( normal, halfAngleVec ) );
165 s += atten * pow( ndoth, u_specularPower ) * (u_specularColor * u_light0Specular); 165 s += atten * pow( ndoth, u_specularPower ) * (u_specularColor * u_light0Specular);
166 #endif 166 #endif
167 } 167 }
168 #endif // LIGHT_0 168 #endif // LIGHT_0
169 169
170 #if defined( LIGHT_1 ) 170 #if defined( LIGHT_1 )
171 { 171 {