From 648ee61ae84216d0236e0dbc211addc13b2cfa3a Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Fri, 6 Jul 2012 11:52:06 -0700 Subject: Expand tabs --- assets/shaders/ub_fshader.glsl | 414 ++++++++++++++++++++--------------------- 1 file changed, 207 insertions(+), 207 deletions(-) (limited to 'assets/shaders/ub_fshader.glsl') diff --git a/assets/shaders/ub_fshader.glsl b/assets/shaders/ub_fshader.glsl index e4e0e2d3..840a97b6 100755 --- a/assets/shaders/ub_fshader.glsl +++ b/assets/shaders/ub_fshader.glsl @@ -30,257 +30,257 @@ POSSIBILITY OF SUCH DAMAGE. // defines #if defined( GL_ES ) - precision highp float; + precision highp float; #endif uniform mat4 u_viewMatrix; #if defined( MATERIAL ) - uniform vec4 u_ambientColor; - uniform vec4 u_diffuseColor; - uniform vec4 u_specularColor; - uniform float u_specularPower; + uniform vec4 u_ambientColor; + uniform vec4 u_diffuseColor; + uniform vec4 u_specularColor; + uniform float u_specularPower; #endif #if defined( LIGHTING ) - varying vec3 v_normal; - #if defined( LIGHT_0 ) -// uniform int u_light0Type; - uniform vec3 u_light0Pos; - uniform vec3 u_light0Dir; - uniform vec3 u_light0Atten; - uniform vec2 u_light0Spot; - uniform vec4 u_light0Color; - uniform vec4 u_light0Specular; - varying vec3 v_light0Dir; - varying vec3 v_light0SpotDir; - #endif + varying vec3 v_normal; + #if defined( LIGHT_0 ) +// uniform int u_light0Type; + uniform vec3 u_light0Pos; + uniform vec3 u_light0Dir; + uniform vec3 u_light0Atten; + uniform vec2 u_light0Spot; + uniform vec4 u_light0Color; + uniform vec4 u_light0Specular; + varying vec3 v_light0Dir; + varying vec3 v_light0SpotDir; + #endif - #if defined( LIGHT_1 ) -// uniform int u_light1Type; - uniform vec3 u_light1Pos; - uniform vec3 u_light1Dir; - uniform vec3 u_light1Atten; - uniform vec2 u_light1Spot; - uniform vec4 u_light1Color; - uniform vec4 u_light1Specular; - varying vec3 v_light1Dir; - varying vec3 v_light1SpotDir; - #endif + #if defined( LIGHT_1 ) +// uniform int u_light1Type; + uniform vec3 u_light1Pos; + uniform vec3 u_light1Dir; + uniform vec3 u_light1Atten; + uniform vec2 u_light1Spot; + uniform vec4 u_light1Color; + uniform vec4 u_light1Specular; + varying vec3 v_light1Dir; + varying vec3 v_light1SpotDir; + #endif - #if defined( LIGHT_2 ) -// uniform int u_light2Type; - uniform vec3 u_light2Pos; - uniform vec3 u_light2Dir; - uniform vec3 u_light2Atten; - uniform vec2 u_light2Spot; - uniform vec4 u_light2Color; - uniform vec4 u_light2Specular; - varying vec3 v_light2Dir; - varying vec3 v_light2SpotDir; - #endif + #if defined( LIGHT_2 ) +// uniform int u_light2Type; + uniform vec3 u_light2Pos; + uniform vec3 u_light2Dir; + uniform vec3 u_light2Atten; + uniform vec2 u_light2Spot; + uniform vec4 u_light2Color; + uniform vec4 u_light2Specular; + varying vec3 v_light2Dir; + varying vec3 v_light2SpotDir; + #endif - #if defined( LIGHT_3 ) -// uniform int u_light3Type; - uniform vec3 u_light3Pos; - uniform vec3 u_light3Dir; - uniform vec3 u_light3Atten; - uniform vec2 u_light3Spot; - uniform vec4 u_light3Color; - uniform vec4 u_light3Specular; - varying vec3 v_light3Dir; - varying vec3 v_light3SpotDir; - #endif + #if defined( LIGHT_3 ) +// uniform int u_light3Type; + uniform vec3 u_light3Pos; + uniform vec3 u_light3Dir; + uniform vec3 u_light3Atten; + uniform vec2 u_light3Spot; + uniform vec4 u_light3Color; + uniform vec4 u_light3Specular; + varying vec3 v_light3Dir; + varying vec3 v_light3SpotDir; + #endif #endif #if defined( ENVIRONMENT_MAP ) - uniform float u_envReflection; + uniform float u_envReflection; #endif uniform vec3 u_eye; -uniform sampler2D s_diffuseMap; -uniform sampler2D s_normalMap; -uniform sampler2D s_envMap; -uniform sampler2D s_specMap; +uniform sampler2D s_diffuseMap; +uniform sampler2D s_normalMap; +uniform sampler2D s_envMap; +uniform sampler2D s_specMap; varying vec3 v_mvPos; varying vec3 v_eyeDir; varying vec2 v_texcoord; void main() { - // these are the four principle color elements making up the final fragment equation. - vec4 a = vec4(0.0,0.0,0.0,0.0); // ambient contribution - vec4 d = vec4(0.0,0.0,0.0,0.0); // diffuse contribution - vec4 s = vec4(0.0,0.0,0.0,0.0); // specular contribution - vec4 l = vec4(0.0,0.0,0.0,0.0); // lighting contribution - + // these are the four principle color elements making up the final fragment equation. + vec4 a = vec4(0.0,0.0,0.0,0.0); // ambient contribution + vec4 d = vec4(0.0,0.0,0.0,0.0); // diffuse contribution + vec4 s = vec4(0.0,0.0,0.0,0.0); // specular contribution + vec4 l = vec4(0.0,0.0,0.0,0.0); // lighting contribution + #if defined( MATERIAL ) - a += u_ambientColor; - d += u_diffuseColor; + a += u_ambientColor; + d += u_diffuseColor; #endif #if defined( DIFFUSE_MAP ) - d *= texture2D(s_diffuseMap, v_texcoord); + d *= texture2D(s_diffuseMap, v_texcoord); #endif #if ( defined( LIGHTING ) || defined( ENVIRONMENT_MAPPING ) ) - vec3 normal = normalize( v_normal ); + vec3 normal = normalize( v_normal ); #endif - + #if defined( LIGHTING ) - #if defined( NORMAL_MAP ) - vec4 normalMap = texture2D(s_normalMap, v_texcoord); - normalMap = vec4( (normalMap.xyz * 2.0 - 1.0), 0.0 ); - normal = normalize(normalMap.x*vec3(normal.z, 0.0, normal.x) + vec3(0.0, normalMap.y, 0.0) + normalMap.z*normal); - #endif // NORMAL_MAP + #if defined( NORMAL_MAP ) + vec4 normalMap = texture2D(s_normalMap, v_texcoord); + normalMap = vec4( (normalMap.xyz * 2.0 - 1.0), 0.0 ); + normal = normalize(normalMap.x*vec3(normal.z, 0.0, normal.x) + vec3(0.0, normalMap.y, 0.0) + normalMap.z*normal); + #endif // NORMAL_MAP - #if defined( LIGHT_0 ) - { - // diffuse lighting - float ldist = length( v_light0Dir.xyz ); - vec3 ldir = v_light0Dir.xyz / ldist; - - float atten = 1.0; - - #if ( LIGHT_0 > 0 ) - atten = 1.0 / ( u_light0Atten.x + u_light0Atten.y * ldist + u_light0Atten.z * ( ldist * ldist ) ); - #if (LIGHT_0 == 2) - float spotAngle = dot( ldir, normalize( v_light0SpotDir ) ); - float spotAtten = 0.0; - if ( spotAngle > u_light0Spot.y ) { - spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light0Spot.y ) / ( u_light0Spot.x - u_light0Spot.y ) ) ); - } - atten *= spotAtten; - #endif - #endif - - float ndotl = max( 0.0, dot( normal, ldir ) ); - l += ndotl * atten * u_light0Color; + #if defined( LIGHT_0 ) + { + // diffuse lighting + float ldist = length( v_light0Dir.xyz ); + vec3 ldir = v_light0Dir.xyz / ldist; + + float atten = 1.0; + + #if ( LIGHT_0 > 0 ) + atten = 1.0 / ( u_light0Atten.x + u_light0Atten.y * ldist + u_light0Atten.z * ( ldist * ldist ) ); + #if (LIGHT_0 == 2) + float spotAngle = dot( ldir, normalize( v_light0SpotDir ) ); + float spotAtten = 0.0; + if ( spotAngle > u_light0Spot.y ) { + spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light0Spot.y ) / ( u_light0Spot.x - u_light0Spot.y ) ) ); + } + atten *= spotAtten; + #endif + #endif + + float ndotl = max( 0.0, dot( normal, ldir ) ); + l += ndotl * atten * u_light0Color; - #if defined( LIGHT_0_SPECULAR ) - // specular contribution - vec3 halfAngleVec = normalize( normalize( v_light0Dir.xyz ) + vec3(0.0,0.0,1.0) ); - float ndoth = max( 0.0, dot( normal, halfAngleVec ) ); - s += atten * pow( ndoth, u_specularPower ) * (u_specularColor * u_light0Specular); - #endif - } - #endif // LIGHT_0 - - #if defined( LIGHT_1 ) - { - // diffuse lighting - float ldist = length( v_light1Dir.xyz ); - vec3 ldir = v_light1Dir.xyz / ldist; - - float atten = 1.0; - - #if ( LIGHT_1 > 0 ) - atten = 1.0 / ( u_light1Atten.x + u_light1Atten.y * ldist + u_light1Atten.z * ( ldist * ldist ) ); - #if (LIGHT_1 == 2) - float spotAngle = dot( ldir, normalize( v_light1SpotDir ) ); - float spotAtten = 0.0; - if ( spotAngle > u_light1Spot.y ) { - spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light1Spot.y ) / ( u_light1Spot.x - u_light1Spot.y ) ) ); - } - atten *= spotAtten; - #endif - #endif - - float ndotl = max( 0.0, dot( normal, ldir ) ); - l += ndotl * atten * u_light1Color; + #if defined( LIGHT_0_SPECULAR ) + // specular contribution + vec3 halfAngleVec = normalize( normalize( v_light0Dir.xyz ) + vec3(0.0,0.0,1.0) ); + float ndoth = max( 0.0, dot( normal, halfAngleVec ) ); + s += atten * pow( ndoth, u_specularPower ) * (u_specularColor * u_light0Specular); + #endif + } + #endif // LIGHT_0 + + #if defined( LIGHT_1 ) + { + // diffuse lighting + float ldist = length( v_light1Dir.xyz ); + vec3 ldir = v_light1Dir.xyz / ldist; + + float atten = 1.0; + + #if ( LIGHT_1 > 0 ) + atten = 1.0 / ( u_light1Atten.x + u_light1Atten.y * ldist + u_light1Atten.z * ( ldist * ldist ) ); + #if (LIGHT_1 == 2) + float spotAngle = dot( ldir, normalize( v_light1SpotDir ) ); + float spotAtten = 0.0; + if ( spotAngle > u_light1Spot.y ) { + spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light1Spot.y ) / ( u_light1Spot.x - u_light1Spot.y ) ) ); + } + atten *= spotAtten; + #endif + #endif + + float ndotl = max( 0.0, dot( normal, ldir ) ); + l += ndotl * atten * u_light1Color; - #if defined( LIGHT_1_SPECULAR ) - // specular contribution - vec3 halfAngleVec = normalize( normalize( v_light1Dir.xyz ) + vec3(0.0,0.0,1.0) ); - float ndoth = max( 0.0, dot( normal, halfAngleVec ) ); - s += atten * pow( ndoth, u_specularPower ) * (u_specularColor * u_light1Specular); - #endif - } - #endif // LIGHT_1 - - #if defined( LIGHT_2 ) - { - // diffuse lighting - float ldist = length( v_light2Dir.xyz ); - vec3 ldir = v_light2Dir.xyz / ldist; - - float atten = 1.0; - - #if ( LIGHT_2 > 0 ) - atten = 1.0 / ( u_light2Atten.x + u_light2Atten.y * ldist + u_light2Atten.z * ( ldist * ldist ) ); - #if (LIGHT_2 == 2) - float spotAngle = dot( ldir, normalize( v_light2SpotDir ) ); - float spotAtten = 0.0; - if ( spotAngle > u_light2Spot.y ) { - spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light2Spot.y ) / ( u_light2Spot.x - u_light2Spot.y ) ) ); - } - atten *= spotAtten; - #endif - #endif - - float ndotl = max( 0.0, dot( normal, ldir ) ); - l += ndotl * atten * u_light2Color; + #if defined( LIGHT_1_SPECULAR ) + // specular contribution + vec3 halfAngleVec = normalize( normalize( v_light1Dir.xyz ) + vec3(0.0,0.0,1.0) ); + float ndoth = max( 0.0, dot( normal, halfAngleVec ) ); + s += atten * pow( ndoth, u_specularPower ) * (u_specularColor * u_light1Specular); + #endif + } + #endif // LIGHT_1 + + #if defined( LIGHT_2 ) + { + // diffuse lighting + float ldist = length( v_light2Dir.xyz ); + vec3 ldir = v_light2Dir.xyz / ldist; + + float atten = 1.0; + + #if ( LIGHT_2 > 0 ) + atten = 1.0 / ( u_light2Atten.x + u_light2Atten.y * ldist + u_light2Atten.z * ( ldist * ldist ) ); + #if (LIGHT_2 == 2) + float spotAngle = dot( ldir, normalize( v_light2SpotDir ) ); + float spotAtten = 0.0; + if ( spotAngle > u_light2Spot.y ) { + spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light2Spot.y ) / ( u_light2Spot.x - u_light2Spot.y ) ) ); + } + atten *= spotAtten; + #endif + #endif + + float ndotl = max( 0.0, dot( normal, ldir ) ); + l += ndotl * atten * u_light2Color; - #if defined( LIGHT_2_SPECULAR ) - // specular contribution - vec3 halfAngleVec = normalize( normalize( v_light2Dir.xyz ) + vec3(0.0,0.0,1.0) ); - float ndoth = max( 0.0, dot( normal, halfAngleVec ) ); - s += atten * pow( ndoth, u_specularPower ) * (u_specularColor * u_light2Specular); - #endif - } - #endif // LIGHT_2 - - #if defined( LIGHT_3 ) - { - // diffuse lighting - float ldist = length( v_light3Dir.xyz ); - vec3 ldir = v_light3Dir.xyz / ldist; - - float atten = 1.0; - - #if ( LIGHT_3 > 0 ) - atten = 1.0 / ( u_light3Atten.x + u_light3Atten.y * ldist + u_light3Atten.z * ( ldist * ldist ) ); - #if (LIGHT_3 == 2) - float spotAngle = dot( ldir, normalize( v_light3SpotDir ) ); - float spotAtten = 0.0; - if ( spotAngle > u_light3Spot.y ) { - spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light3Spot.y ) / ( u_light3Spot.x - u_light3Spot.y ) ) ); - } - atten *= spotAtten; - #endif - #endif - - float ndotl = max( 0.0, dot( normal, ldir ) ); - l += ndotl * atten * u_light3Color; + #if defined( LIGHT_2_SPECULAR ) + // specular contribution + vec3 halfAngleVec = normalize( normalize( v_light2Dir.xyz ) + vec3(0.0,0.0,1.0) ); + float ndoth = max( 0.0, dot( normal, halfAngleVec ) ); + s += atten * pow( ndoth, u_specularPower ) * (u_specularColor * u_light2Specular); + #endif + } + #endif // LIGHT_2 + + #if defined( LIGHT_3 ) + { + // diffuse lighting + float ldist = length( v_light3Dir.xyz ); + vec3 ldir = v_light3Dir.xyz / ldist; + + float atten = 1.0; + + #if ( LIGHT_3 > 0 ) + atten = 1.0 / ( u_light3Atten.x + u_light3Atten.y * ldist + u_light3Atten.z * ( ldist * ldist ) ); + #if (LIGHT_3 == 2) + float spotAngle = dot( ldir, normalize( v_light3SpotDir ) ); + float spotAtten = 0.0; + if ( spotAngle > u_light3Spot.y ) { + spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light3Spot.y ) / ( u_light3Spot.x - u_light3Spot.y ) ) ); + } + atten *= spotAtten; + #endif + #endif + + float ndotl = max( 0.0, dot( normal, ldir ) ); + l += ndotl * atten * u_light3Color; - #if defined( LIGHT_3_SPECULAR ) - // specular contribution - vec3 halfAngleVec = normalize( normalize( v_light3Dir.xyz ) + vec3(0.0,0.0,1.0) ); - float ndoth = max( 0.0, dot( normal, halfAngleVec ) ); - s += atten * pow( ndoth, u_specularPower ) * (u_specularColor * u_light3Specular); - #endif - } - #endif // LIGHT_3 + #if defined( LIGHT_3_SPECULAR ) + // specular contribution + vec3 halfAngleVec = normalize( normalize( v_light3Dir.xyz ) + vec3(0.0,0.0,1.0) ); + float ndoth = max( 0.0, dot( normal, halfAngleVec ) ); + s += atten * pow( ndoth, u_specularPower ) * (u_specularColor * u_light3Specular); + #endif + } + #endif // LIGHT_3 #endif // LIGHTING #if defined( SPECULAR ) && defined( SPECULAR_MAP ) - vec4 specMapColor = texture2D(s_specMap, v_texcoord); - s *= specMapColor; + vec4 specMapColor = texture2D(s_specMap, v_texcoord); + s *= specMapColor; #endif #if defined( ENVIRONMENT_MAP ) - vec3 r = reflect( normalize( vec3(0.0,0.0,1.0) ), normal ); - float m = 2.0 * length(r); - vec4 envMapColor = texture2D(s_envMap, vec2(r.x/m + 0.5, r.y/m + 0.5)) * u_envReflection; - - #if defined( GLOSS_MAP ) - // this is an option to modulate the alpha channel of the specular map with the environment - // map (i.e. - gloss mapping). - envMapColor *= specMapColor.a; - #endif - - s += envMapColor; + vec3 r = reflect( normalize( vec3(0.0,0.0,1.0) ), normal ); + float m = 2.0 * length(r); + vec4 envMapColor = texture2D(s_envMap, vec2(r.x/m + 0.5, r.y/m + 0.5)) * u_envReflection; + + #if defined( GLOSS_MAP ) + // this is an option to modulate the alpha channel of the specular map with the environment + // map (i.e. - gloss mapping). + envMapColor *= specMapColor.a; + #endif + + s += envMapColor; #endif gl_FragColor = ( a + l ) * d + s; -- cgit v1.2.3 From 6803c0abd279fcb640c38b3881b751bab982cbe0 Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Fri, 6 Jul 2012 12:42:16 -0700 Subject: Remove trailing spaces --- assets/shaders/ub_fshader.glsl | 102 ++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 51 deletions(-) (limited to 'assets/shaders/ub_fshader.glsl') diff --git a/assets/shaders/ub_fshader.glsl b/assets/shaders/ub_fshader.glsl index 840a97b6..9b37899d 100755 --- a/assets/shaders/ub_fshader.glsl +++ b/assets/shaders/ub_fshader.glsl @@ -51,9 +51,9 @@ uniform mat4 u_viewMatrix; uniform vec3 u_light0Atten; uniform vec2 u_light0Spot; uniform vec4 u_light0Color; - uniform vec4 u_light0Specular; + uniform vec4 u_light0Specular; varying vec3 v_light0Dir; - varying vec3 v_light0SpotDir; + varying vec3 v_light0SpotDir; #endif #if defined( LIGHT_1 ) @@ -63,9 +63,9 @@ uniform mat4 u_viewMatrix; uniform vec3 u_light1Atten; uniform vec2 u_light1Spot; uniform vec4 u_light1Color; - uniform vec4 u_light1Specular; + uniform vec4 u_light1Specular; varying vec3 v_light1Dir; - varying vec3 v_light1SpotDir; + varying vec3 v_light1SpotDir; #endif #if defined( LIGHT_2 ) @@ -75,9 +75,9 @@ uniform mat4 u_viewMatrix; uniform vec3 u_light2Atten; uniform vec2 u_light2Spot; uniform vec4 u_light2Color; - uniform vec4 u_light2Specular; + uniform vec4 u_light2Specular; varying vec3 v_light2Dir; - varying vec3 v_light2SpotDir; + varying vec3 v_light2SpotDir; #endif #if defined( LIGHT_3 ) @@ -87,9 +87,9 @@ uniform mat4 u_viewMatrix; uniform vec3 u_light3Atten; uniform vec2 u_light3Spot; uniform vec4 u_light3Color; - uniform vec4 u_light3Specular; + uniform vec4 u_light3Specular; varying vec3 v_light3Dir; - varying vec3 v_light3SpotDir; + varying vec3 v_light3SpotDir; #endif #endif @@ -114,7 +114,7 @@ void main() { vec4 d = vec4(0.0,0.0,0.0,0.0); // diffuse contribution vec4 s = vec4(0.0,0.0,0.0,0.0); // specular contribution vec4 l = vec4(0.0,0.0,0.0,0.0); // lighting contribution - + #if defined( MATERIAL ) a += u_ambientColor; d += u_diffuseColor; @@ -124,10 +124,10 @@ void main() { d *= texture2D(s_diffuseMap, v_texcoord); #endif -#if ( defined( LIGHTING ) || defined( ENVIRONMENT_MAPPING ) ) +#if ( defined( LIGHTING ) || defined( ENVIRONMENT_MAPPING ) ) vec3 normal = normalize( v_normal ); #endif - + #if defined( LIGHTING ) #if defined( NORMAL_MAP ) vec4 normalMap = texture2D(s_normalMap, v_texcoord); @@ -136,25 +136,25 @@ void main() { #endif // NORMAL_MAP #if defined( LIGHT_0 ) - { + { // diffuse lighting float ldist = length( v_light0Dir.xyz ); vec3 ldir = v_light0Dir.xyz / ldist; - + float atten = 1.0; - + #if ( LIGHT_0 > 0 ) atten = 1.0 / ( u_light0Atten.x + u_light0Atten.y * ldist + u_light0Atten.z * ( ldist * ldist ) ); #if (LIGHT_0 == 2) float spotAngle = dot( ldir, normalize( v_light0SpotDir ) ); float spotAtten = 0.0; if ( spotAngle > u_light0Spot.y ) { - spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light0Spot.y ) / ( u_light0Spot.x - u_light0Spot.y ) ) ); - } - atten *= spotAtten; + spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light0Spot.y ) / ( u_light0Spot.x - u_light0Spot.y ) ) ); + } + atten *= spotAtten; #endif #endif - + float ndotl = max( 0.0, dot( normal, ldir ) ); l += ndotl * atten * u_light0Color; @@ -166,27 +166,27 @@ void main() { #endif } #endif // LIGHT_0 - + #if defined( LIGHT_1 ) - { + { // diffuse lighting float ldist = length( v_light1Dir.xyz ); vec3 ldir = v_light1Dir.xyz / ldist; - + float atten = 1.0; - + #if ( LIGHT_1 > 0 ) atten = 1.0 / ( u_light1Atten.x + u_light1Atten.y * ldist + u_light1Atten.z * ( ldist * ldist ) ); #if (LIGHT_1 == 2) float spotAngle = dot( ldir, normalize( v_light1SpotDir ) ); float spotAtten = 0.0; if ( spotAngle > u_light1Spot.y ) { - spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light1Spot.y ) / ( u_light1Spot.x - u_light1Spot.y ) ) ); - } - atten *= spotAtten; + spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light1Spot.y ) / ( u_light1Spot.x - u_light1Spot.y ) ) ); + } + atten *= spotAtten; #endif #endif - + float ndotl = max( 0.0, dot( normal, ldir ) ); l += ndotl * atten * u_light1Color; @@ -198,27 +198,27 @@ void main() { #endif } #endif // LIGHT_1 - + #if defined( LIGHT_2 ) - { + { // diffuse lighting float ldist = length( v_light2Dir.xyz ); vec3 ldir = v_light2Dir.xyz / ldist; - + float atten = 1.0; - + #if ( LIGHT_2 > 0 ) atten = 1.0 / ( u_light2Atten.x + u_light2Atten.y * ldist + u_light2Atten.z * ( ldist * ldist ) ); #if (LIGHT_2 == 2) float spotAngle = dot( ldir, normalize( v_light2SpotDir ) ); float spotAtten = 0.0; if ( spotAngle > u_light2Spot.y ) { - spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light2Spot.y ) / ( u_light2Spot.x - u_light2Spot.y ) ) ); - } - atten *= spotAtten; + spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light2Spot.y ) / ( u_light2Spot.x - u_light2Spot.y ) ) ); + } + atten *= spotAtten; #endif #endif - + float ndotl = max( 0.0, dot( normal, ldir ) ); l += ndotl * atten * u_light2Color; @@ -228,29 +228,29 @@ void main() { float ndoth = max( 0.0, dot( normal, halfAngleVec ) ); s += atten * pow( ndoth, u_specularPower ) * (u_specularColor * u_light2Specular); #endif - } - #endif // LIGHT_2 - + } + #endif // LIGHT_2 + #if defined( LIGHT_3 ) - { + { // diffuse lighting float ldist = length( v_light3Dir.xyz ); vec3 ldir = v_light3Dir.xyz / ldist; - + float atten = 1.0; - + #if ( LIGHT_3 > 0 ) atten = 1.0 / ( u_light3Atten.x + u_light3Atten.y * ldist + u_light3Atten.z * ( ldist * ldist ) ); #if (LIGHT_3 == 2) float spotAngle = dot( ldir, normalize( v_light3SpotDir ) ); float spotAtten = 0.0; if ( spotAngle > u_light3Spot.y ) { - spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light3Spot.y ) / ( u_light3Spot.x - u_light3Spot.y ) ) ); - } - atten *= spotAtten; + spotAtten = min(1.0, max( 0.0, ( spotAngle - u_light3Spot.y ) / ( u_light3Spot.x - u_light3Spot.y ) ) ); + } + atten *= spotAtten; #endif #endif - + float ndotl = max( 0.0, dot( normal, ldir ) ); l += ndotl * atten * u_light3Color; @@ -260,8 +260,8 @@ void main() { float ndoth = max( 0.0, dot( normal, halfAngleVec ) ); s += atten * pow( ndoth, u_specularPower ) * (u_specularColor * u_light3Specular); #endif - } - #endif // LIGHT_3 + } + #endif // LIGHT_3 #endif // LIGHTING #if defined( SPECULAR ) && defined( SPECULAR_MAP ) @@ -271,15 +271,15 @@ void main() { #if defined( ENVIRONMENT_MAP ) vec3 r = reflect( normalize( vec3(0.0,0.0,1.0) ), normal ); - float m = 2.0 * length(r); + float m = 2.0 * length(r); vec4 envMapColor = texture2D(s_envMap, vec2(r.x/m + 0.5, r.y/m + 0.5)) * u_envReflection; - + #if defined( GLOSS_MAP ) - // this is an option to modulate the alpha channel of the specular map with the environment - // map (i.e. - gloss mapping). + // this is an option to modulate the alpha channel of the specular map with the environment + // map (i.e. - gloss mapping). envMapColor *= specMapColor.a; #endif - + s += envMapColor; #endif -- cgit v1.2.3