Home | History | Annotate | Download | only in Terrain
      1 
      2 uniform float m_Shininess;
      3 uniform vec4 g_LightDirection;
      4 
      5 varying vec4 AmbientSum;
      6 varying vec4 DiffuseSum;
      7 varying vec4 SpecularSum;
      8 
      9 varying vec3 vNormal;
     10 varying vec2 texCoord;
     11 varying vec3 vPosition;
     12 varying vec3 vnPosition;
     13 varying vec3 vViewDir;
     14 varying vec4 vLightDir;
     15 varying vec4 vnLightDir;
     16 varying vec3 lightVec;
     17 
     18 
     19 #ifdef DIFFUSEMAP
     20   uniform sampler2D m_DiffuseMap;
     21 #endif
     22 #ifdef DIFFUSEMAP_1
     23   uniform sampler2D m_DiffuseMap_1;
     24 #endif
     25 #ifdef DIFFUSEMAP_2
     26   uniform sampler2D m_DiffuseMap_2;
     27 #endif
     28 #ifdef DIFFUSEMAP_3
     29   uniform sampler2D m_DiffuseMap_3;
     30 #endif
     31 #ifdef DIFFUSEMAP_4
     32   uniform sampler2D m_DiffuseMap_4;
     33 #endif
     34 #ifdef DIFFUSEMAP_5
     35   uniform sampler2D m_DiffuseMap_5;
     36 #endif
     37 #ifdef DIFFUSEMAP_6
     38   uniform sampler2D m_DiffuseMap_6;
     39 #endif
     40 #ifdef DIFFUSEMAP_7
     41   uniform sampler2D m_DiffuseMap_7;
     42 #endif
     43 #ifdef DIFFUSEMAP_8
     44   uniform sampler2D m_DiffuseMap_8;
     45 #endif
     46 #ifdef DIFFUSEMAP_9
     47   uniform sampler2D m_DiffuseMap_9;
     48 #endif
     49 #ifdef DIFFUSEMAP_10
     50   uniform sampler2D m_DiffuseMap_10;
     51 #endif
     52 #ifdef DIFFUSEMAP_11
     53   uniform sampler2D m_DiffuseMap_11;
     54 #endif
     55 
     56 
     57 #ifdef DIFFUSEMAP_0_SCALE
     58   uniform float m_DiffuseMap_0_scale;
     59 #endif
     60 #ifdef DIFFUSEMAP_1_SCALE
     61   uniform float m_DiffuseMap_1_scale;
     62 #endif
     63 #ifdef DIFFUSEMAP_2_SCALE
     64   uniform float m_DiffuseMap_2_scale;
     65 #endif
     66 #ifdef DIFFUSEMAP_3_SCALE
     67   uniform float m_DiffuseMap_3_scale;
     68 #endif
     69 #ifdef DIFFUSEMAP_4_SCALE
     70   uniform float m_DiffuseMap_4_scale;
     71 #endif
     72 #ifdef DIFFUSEMAP_5_SCALE
     73   uniform float m_DiffuseMap_5_scale;
     74 #endif
     75 #ifdef DIFFUSEMAP_6_SCALE
     76   uniform float m_DiffuseMap_6_scale;
     77 #endif
     78 #ifdef DIFFUSEMAP_7_SCALE
     79   uniform float m_DiffuseMap_7_scale;
     80 #endif
     81 #ifdef DIFFUSEMAP_8_SCALE
     82   uniform float m_DiffuseMap_8_scale;
     83 #endif
     84 #ifdef DIFFUSEMAP_9_SCALE
     85   uniform float m_DiffuseMap_9_scale;
     86 #endif
     87 #ifdef DIFFUSEMAP_10_SCALE
     88   uniform float m_DiffuseMap_10_scale;
     89 #endif
     90 #ifdef DIFFUSEMAP_11_SCALE
     91   uniform float m_DiffuseMap_11_scale;
     92 #endif
     93 
     94 
     95 #ifdef ALPHAMAP
     96   uniform sampler2D m_AlphaMap;
     97 #endif
     98 #ifdef ALPHAMAP_1
     99   uniform sampler2D m_AlphaMap_1;
    100 #endif
    101 #ifdef ALPHAMAP_2
    102   uniform sampler2D m_AlphaMap_2;
    103 #endif
    104 
    105 #ifdef NORMALMAP
    106   uniform sampler2D m_NormalMap;
    107 #endif
    108 #ifdef NORMALMAP_1
    109   uniform sampler2D m_NormalMap_1;
    110 #endif
    111 #ifdef NORMALMAP_2
    112   uniform sampler2D m_NormalMap_2;
    113 #endif
    114 #ifdef NORMALMAP_3
    115   uniform sampler2D m_NormalMap_3;
    116 #endif
    117 #ifdef NORMALMAP_4
    118   uniform sampler2D m_NormalMap_4;
    119 #endif
    120 #ifdef NORMALMAP_5
    121   uniform sampler2D m_NormalMap_5;
    122 #endif
    123 #ifdef NORMALMAP_6
    124   uniform sampler2D m_NormalMap_6;
    125 #endif
    126 #ifdef NORMALMAP_7
    127   uniform sampler2D m_NormalMap_7;
    128 #endif
    129 #ifdef NORMALMAP_8
    130   uniform sampler2D m_NormalMap_8;
    131 #endif
    132 #ifdef NORMALMAP_9
    133   uniform sampler2D m_NormalMap_9;
    134 #endif
    135 #ifdef NORMALMAP_10
    136   uniform sampler2D m_NormalMap_10;
    137 #endif
    138 #ifdef NORMALMAP_11
    139   uniform sampler2D m_NormalMap_11;
    140 #endif
    141 
    142 
    143 #ifdef TRI_PLANAR_MAPPING
    144   varying vec4 wVertex;
    145   varying vec3 wNormal;
    146 #endif
    147 
    148 
    149 
    150 float tangDot(in vec3 v1, in vec3 v2){
    151     float d = dot(v1,v2);
    152     #ifdef V_TANGENT
    153         d = 1.0 - d*d;
    154         return step(0.0, d) * sqrt(d);
    155     #else
    156         return d;
    157     #endif
    158 }
    159 
    160 
    161 float lightComputeDiffuse(in vec3 norm, in vec3 lightdir, in vec3 viewdir){
    162     return max(0.0, dot(norm, lightdir));
    163 }
    164 
    165 float lightComputeSpecular(in vec3 norm, in vec3 viewdir, in vec3 lightdir, in float shiny){
    166     #ifdef WARDISO
    167         // Isotropic Ward
    168         vec3 halfVec = normalize(viewdir + lightdir);
    169         float NdotH  = max(0.001, tangDot(norm, halfVec));
    170         float NdotV  = max(0.001, tangDot(norm, viewdir));
    171         float NdotL  = max(0.001, tangDot(norm, lightdir));
    172         float a      = tan(acos(NdotH));
    173         float p      = max(shiny/128.0, 0.001);
    174         return NdotL * (1.0 / (4.0*3.14159265*p*p)) * (exp(-(a*a)/(p*p)) / (sqrt(NdotV * NdotL)));
    175     #else
    176        // Standard Phong
    177        vec3 R = reflect(-lightdir, norm);
    178        return pow(max(tangDot(R, viewdir), 0.0), shiny);
    179     #endif
    180 }
    181 
    182 vec2 computeLighting(in vec3 wvPos, in vec3 wvNorm, in vec3 wvViewDir, in vec3 wvLightDir){
    183    float diffuseFactor = lightComputeDiffuse(wvNorm, wvLightDir, wvViewDir);
    184    float specularFactor = lightComputeSpecular(wvNorm, wvViewDir, wvLightDir, m_Shininess);
    185    specularFactor *= step(1.0, m_Shininess);
    186 
    187    float att = vLightDir.w;
    188 
    189    return vec2(diffuseFactor, specularFactor) * vec2(att);
    190 }
    191 
    192 
    193 #ifdef ALPHAMAP
    194 
    195   vec4 calculateDiffuseBlend(in vec2 texCoord) {
    196     vec4 alphaBlend   = texture2D( m_AlphaMap, texCoord.xy );
    197     
    198     #ifdef ALPHAMAP_1
    199       vec4 alphaBlend1   = texture2D( m_AlphaMap_1, texCoord.xy );
    200     #endif
    201     #ifdef ALPHAMAP_2
    202       vec4 alphaBlend2   = texture2D( m_AlphaMap_2, texCoord.xy );
    203     #endif
    204 
    205     vec4 diffuseColor = texture2D(m_DiffuseMap, texCoord * m_DiffuseMap_0_scale);
    206     diffuseColor *= alphaBlend.r;
    207     #ifdef DIFFUSEMAP_1
    208       vec4 diffuseColor1 = texture2D(m_DiffuseMap_1, texCoord * m_DiffuseMap_1_scale);
    209       diffuseColor = mix( diffuseColor, diffuseColor1, alphaBlend.g );
    210       #ifdef DIFFUSEMAP_2
    211         vec4 diffuseColor2 = texture2D(m_DiffuseMap_2, texCoord * m_DiffuseMap_2_scale);
    212         diffuseColor = mix( diffuseColor, diffuseColor2, alphaBlend.b );
    213         #ifdef DIFFUSEMAP_3
    214           vec4 diffuseColor3 = texture2D(m_DiffuseMap_3, texCoord * m_DiffuseMap_3_scale);
    215           diffuseColor = mix( diffuseColor, diffuseColor3, alphaBlend.a );
    216           #ifdef ALPHAMAP_1
    217               #ifdef DIFFUSEMAP_4
    218                 vec4 diffuseColor4 = texture2D(m_DiffuseMap_4, texCoord * m_DiffuseMap_4_scale);
    219                 diffuseColor = mix( diffuseColor, diffuseColor4, alphaBlend1.r );
    220                 #ifdef DIFFUSEMAP_5
    221                   vec4 diffuseColor5 = texture2D(m_DiffuseMap_5, texCoord * m_DiffuseMap_5_scale);
    222                   diffuseColor = mix( diffuseColor, diffuseColor5, alphaBlend1.g );
    223                   #ifdef DIFFUSEMAP_6
    224                     vec4 diffuseColor6 = texture2D(m_DiffuseMap_6, texCoord * m_DiffuseMap_6_scale);
    225                     diffuseColor = mix( diffuseColor, diffuseColor6, alphaBlend1.b );
    226                     #ifdef DIFFUSEMAP_7
    227                       vec4 diffuseColor7 = texture2D(m_DiffuseMap_7, texCoord * m_DiffuseMap_7_scale);
    228                       diffuseColor = mix( diffuseColor, diffuseColor7, alphaBlend1.a );
    229                       #ifdef ALPHAMAP_2
    230                           #ifdef DIFFUSEMAP_8
    231                             vec4 diffuseColor8 = texture2D(m_DiffuseMap_8, texCoord * m_DiffuseMap_8_scale);
    232                             diffuseColor = mix( diffuseColor, diffuseColor8, alphaBlend2.r );
    233                             #ifdef DIFFUSEMAP_9
    234                               vec4 diffuseColor9 = texture2D(m_DiffuseMap_9, texCoord * m_DiffuseMap_9_scale);
    235                               diffuseColor = mix( diffuseColor, diffuseColor9, alphaBlend2.g );
    236                               #ifdef DIFFUSEMAP_10
    237                                 vec4 diffuseColor10 = texture2D(m_DiffuseMap_10, texCoord * m_DiffuseMap_10_scale);
    238                                 diffuseColor = mix( diffuseColor, diffuseColor10, alphaBlend2.b );
    239                                 #ifdef DIFFUSEMAP_11
    240                                   vec4 diffuseColor11 = texture2D(m_DiffuseMap_11, texCoord * m_DiffuseMap_11_scale);
    241                                   diffuseColor = mix( diffuseColor, diffuseColor11, alphaBlend2.a );
    242                                 #endif
    243                               #endif
    244                             #endif
    245                           #endif
    246                       #endif
    247                     #endif
    248                   #endif
    249                 #endif
    250               #endif
    251           #endif
    252         #endif
    253       #endif
    254     #endif
    255     return diffuseColor;
    256   }
    257 
    258   vec3 calculateNormal(in vec2 texCoord) {
    259     vec3 normal = vec3(0,0,1);
    260     vec3 n = vec3(0,0,0);
    261 
    262     vec4 alphaBlend = texture2D( m_AlphaMap, texCoord.xy );
    263 
    264     #ifdef ALPHAMAP_1
    265       vec4 alphaBlend1 = texture2D( m_AlphaMap_1, texCoord.xy );
    266     #endif
    267     #ifdef ALPHAMAP_2
    268       vec4 alphaBlend2 = texture2D( m_AlphaMap_2, texCoord.xy );
    269     #endif
    270 
    271     #ifdef NORMALMAP
    272       n = texture2D(m_NormalMap, texCoord * m_DiffuseMap_0_scale).xyz;
    273       normal += n * alphaBlend.r;
    274     #endif
    275 
    276     #ifdef NORMALMAP_1
    277       n = texture2D(m_NormalMap_1, texCoord * m_DiffuseMap_1_scale).xyz;
    278       normal += n * alphaBlend.g;
    279     #endif
    280 
    281     #ifdef NORMALMAP_2
    282       n = texture2D(m_NormalMap_2, texCoord * m_DiffuseMap_2_scale).xyz;
    283       normal += n * alphaBlend.b;
    284     #endif
    285 
    286     #ifdef NORMALMAP_3
    287       n = texture2D(m_NormalMap_3, texCoord * m_DiffuseMap_3_scale).xyz;
    288       normal += n * alphaBlend.a;
    289     #endif
    290 
    291     #ifdef ALPHAMAP_1
    292         #ifdef NORMALMAP_4
    293           n = texture2D(m_NormalMap_4, texCoord * m_DiffuseMap_4_scale).xyz;
    294           normal += n * alphaBlend1.r;
    295         #endif
    296 
    297         #ifdef NORMALMAP_5
    298           n = texture2D(m_NormalMap_5, texCoord * m_DiffuseMap_5_scale).xyz;
    299           normal += n * alphaBlend1.g;
    300         #endif
    301 
    302         #ifdef NORMALMAP_6
    303           n = texture2D(m_NormalMap_6, texCoord * m_DiffuseMap_6_scale).xyz;
    304           normal += n * alphaBlend1.b;
    305         #endif
    306 
    307         #ifdef NORMALMAP_7
    308           n = texture2D(m_NormalMap_7, texCoord * m_DiffuseMap_7_scale).xyz;
    309           normal += n * alphaBlend1.a;
    310         #endif
    311     #endif
    312 
    313     #ifdef ALPHAMAP_2
    314         #ifdef NORMALMAP_8
    315           n = texture2D(m_NormalMap_8, texCoord * m_DiffuseMap_8_scale).xyz;
    316           normal += n * alphaBlend2.r;
    317         #endif
    318 
    319         #ifdef NORMALMAP_9
    320           n = texture2D(m_NormalMap_9, texCoord * m_DiffuseMap_9_scale);
    321           normal += n * alphaBlend2.g;
    322         #endif
    323 
    324         #ifdef NORMALMAP_10
    325           n = texture2D(m_NormalMap_10, texCoord * m_DiffuseMap_10_scale);
    326           normal += n * alphaBlend2.b;
    327         #endif
    328 
    329         #ifdef NORMALMAP_11
    330           n = texture2D(m_NormalMap_11, texCoord * m_DiffuseMap_11_scale);
    331           normal += n * alphaBlend2.a;
    332         #endif
    333     #endif
    334 
    335     normal = (normal.xyz * vec3(2.0) - vec3(1.0));
    336     return normalize(normal);
    337   }
    338 
    339   #ifdef TRI_PLANAR_MAPPING
    340 
    341     vec4 getTriPlanarBlend(in vec4 coords, in vec3 blending, in sampler2D map, in float scale) {
    342       vec4 col1 = texture2D( map, coords.yz * scale);
    343       vec4 col2 = texture2D( map, coords.xz * scale);
    344       vec4 col3 = texture2D( map, coords.xy * scale);
    345       // blend the results of the 3 planar projections.
    346       vec4 tex = col1 * blending.x + col2 * blending.y + col3 * blending.z;
    347       return tex;
    348     }
    349 
    350     vec4 calculateTriPlanarDiffuseBlend(in vec3 wNorm, in vec4 wVert, in vec2 texCoord) {
    351         // tri-planar texture bending factor for this fragment's normal
    352         vec3 blending = abs( wNorm );
    353         blending = (blending -0.2) * 0.7;
    354         blending = normalize(max(blending, 0.00001));      // Force weights to sum to 1.0 (very important!)
    355         float b = (blending.x + blending.y + blending.z);
    356         blending /= vec3(b, b, b);
    357 
    358         // texture coords
    359         vec4 coords = wVert;
    360 
    361         // blend the results of the 3 planar projections.
    362         vec4 tex0 = getTriPlanarBlend(coords, blending, m_DiffuseMap, m_DiffuseMap_0_scale);
    363 
    364         #ifdef DIFFUSEMAP_1
    365           // blend the results of the 3 planar projections.
    366           vec4 tex1 = getTriPlanarBlend(coords, blending, m_DiffuseMap_1, m_DiffuseMap_1_scale);
    367         #endif
    368         #ifdef DIFFUSEMAP_2
    369           // blend the results of the 3 planar projections.
    370           vec4 tex2 = getTriPlanarBlend(coords, blending, m_DiffuseMap_2, m_DiffuseMap_2_scale);
    371         #endif
    372         #ifdef DIFFUSEMAP_3
    373           // blend the results of the 3 planar projections.
    374           vec4 tex3 = getTriPlanarBlend(coords, blending, m_DiffuseMap_3, m_DiffuseMap_3_scale);
    375         #endif
    376         #ifdef DIFFUSEMAP_4
    377           // blend the results of the 3 planar projections.
    378           vec4 tex4 = getTriPlanarBlend(coords, blending, m_DiffuseMap_4, m_DiffuseMap_4_scale);
    379         #endif
    380         #ifdef DIFFUSEMAP_5
    381           // blend the results of the 3 planar projections.
    382           vec4 tex5 = getTriPlanarBlend(coords, blending, m_DiffuseMap_5, m_DiffuseMap_5_scale);
    383         #endif
    384         #ifdef DIFFUSEMAP_6
    385           // blend the results of the 3 planar projections.
    386           vec4 tex6 = getTriPlanarBlend(coords, blending, m_DiffuseMap_6, m_DiffuseMap_6_scale);
    387         #endif
    388         #ifdef DIFFUSEMAP_7
    389           // blend the results of the 3 planar projections.
    390           vec4 tex7 = getTriPlanarBlend(coords, blending, m_DiffuseMap_7, m_DiffuseMap_7_scale);
    391         #endif
    392         #ifdef DIFFUSEMAP_8
    393           // blend the results of the 3 planar projections.
    394           vec4 tex8 = getTriPlanarBlend(coords, blending, m_DiffuseMap_8, m_DiffuseMap_8_scale);
    395         #endif
    396         #ifdef DIFFUSEMAP_9
    397           // blend the results of the 3 planar projections.
    398           vec4 tex9 = getTriPlanarBlend(coords, blending, m_DiffuseMap_9, m_DiffuseMap_9_scale);
    399         #endif
    400         #ifdef DIFFUSEMAP_10
    401           // blend the results of the 3 planar projections.
    402           vec4 tex10 = getTriPlanarBlend(coords, blending, m_DiffuseMap_10, m_DiffuseMap_10_scale);
    403         #endif
    404         #ifdef DIFFUSEMAP_11
    405           // blend the results of the 3 planar projections.
    406           vec4 tex11 = getTriPlanarBlend(coords, blending, m_DiffuseMap_11, m_DiffuseMap_11_scale);
    407         #endif
    408 
    409         vec4 alphaBlend   = texture2D( m_AlphaMap, texCoord.xy );
    410 
    411         #ifdef ALPHAMAP_1
    412           vec4 alphaBlend1   = texture2D( m_AlphaMap_1, texCoord.xy );
    413         #endif
    414         #ifdef ALPHAMAP_2
    415           vec4 alphaBlend2   = texture2D( m_AlphaMap_2, texCoord.xy );
    416         #endif
    417 
    418         vec4 diffuseColor = tex0 * alphaBlend.r;
    419         #ifdef DIFFUSEMAP_1
    420           diffuseColor = mix( diffuseColor, tex1, alphaBlend.g );
    421           #ifdef DIFFUSEMAP_2
    422             diffuseColor = mix( diffuseColor, tex2, alphaBlend.b );
    423             #ifdef DIFFUSEMAP_3
    424               diffuseColor = mix( diffuseColor, tex3, alphaBlend.a );
    425               #ifdef ALPHAMAP_1
    426                   #ifdef DIFFUSEMAP_4
    427                     diffuseColor = mix( diffuseColor, tex4, alphaBlend1.r );
    428                     #ifdef DIFFUSEMAP_5
    429                       diffuseColor = mix( diffuseColor, tex5, alphaBlend1.g );
    430                       #ifdef DIFFUSEMAP_6
    431                         diffuseColor = mix( diffuseColor, tex6, alphaBlend1.b );
    432                         #ifdef DIFFUSEMAP_7
    433                           diffuseColor = mix( diffuseColor, tex7, alphaBlend1.a );
    434                           #ifdef ALPHAMAP_2
    435                               #ifdef DIFFUSEMAP_8
    436                                 diffuseColor = mix( diffuseColor, tex8, alphaBlend2.r );
    437                                 #ifdef DIFFUSEMAP_9
    438                                   diffuseColor = mix( diffuseColor, tex9, alphaBlend2.g );
    439                                   #ifdef DIFFUSEMAP_10
    440                                     diffuseColor = mix( diffuseColor, tex10, alphaBlend2.b );
    441                                     #ifdef DIFFUSEMAP_11
    442                                       diffuseColor = mix( diffuseColor, tex11, alphaBlend2.a );
    443                                     #endif
    444                                   #endif
    445                                 #endif
    446                               #endif
    447                           #endif
    448                         #endif
    449                       #endif
    450                     #endif
    451                   #endif
    452               #endif
    453             #endif
    454           #endif
    455         #endif
    456 
    457         return diffuseColor;
    458     }
    459 
    460     vec3 calculateNormalTriPlanar(in vec3 wNorm, in vec4 wVert,in vec2 texCoord) {
    461       // tri-planar texture bending factor for this fragment's world-space normal
    462       vec3 blending = abs( wNorm );
    463       blending = (blending -0.2) * 0.7;
    464       blending = normalize(max(blending, 0.00001));      // Force weights to sum to 1.0 (very important!)
    465       float b = (blending.x + blending.y + blending.z);
    466       blending /= vec3(b, b, b);
    467 
    468       // texture coords
    469       vec4 coords = wVert;
    470       vec4 alphaBlend = texture2D( m_AlphaMap, texCoord.xy );
    471 
    472     #ifdef ALPHAMAP_1
    473       vec4 alphaBlend1 = texture2D( m_AlphaMap_1, texCoord.xy );
    474     #endif
    475     #ifdef ALPHAMAP_2
    476       vec4 alphaBlend2 = texture2D( m_AlphaMap_2, texCoord.xy );
    477     #endif
    478 
    479       vec3 normal = vec3(0,0,1);
    480       vec3 n = vec3(0,0,0);
    481 
    482       #ifdef NORMALMAP
    483           n = getTriPlanarBlend(coords, blending, m_NormalMap, m_DiffuseMap_0_scale).xyz;
    484           normal += n * alphaBlend.r;
    485       #endif
    486 
    487       #ifdef NORMALMAP_1
    488           n = getTriPlanarBlend(coords, blending, m_NormalMap_1, m_DiffuseMap_1_scale).xyz;
    489           normal += n * alphaBlend.g;
    490       #endif
    491 
    492       #ifdef NORMALMAP_2
    493           n = getTriPlanarBlend(coords, blending, m_NormalMap_2, m_DiffuseMap_2_scale).xyz;
    494           normal += n * alphaBlend.b;
    495       #endif
    496 
    497       #ifdef NORMALMAP_3
    498           n = getTriPlanarBlend(coords, blending, m_NormalMap_3, m_DiffuseMap_3_scale).xyz;
    499           normal += n * alphaBlend.a;
    500       #endif
    501 
    502       #ifdef ALPHAMAP_1
    503           #ifdef NORMALMAP_4
    504               n = getTriPlanarBlend(coords, blending, m_NormalMap_4, m_DiffuseMap_4_scale).xyz;
    505               normal += n * alphaBlend1.r;
    506           #endif
    507 
    508           #ifdef NORMALMAP_5
    509               n = getTriPlanarBlend(coords, blending, m_NormalMap_5, m_DiffuseMap_5_scale).xyz;
    510               normal += n * alphaBlend1.g;
    511           #endif
    512 
    513           #ifdef NORMALMAP_6
    514               n = getTriPlanarBlend(coords, blending, m_NormalMap_6, m_DiffuseMap_6_scale).xyz;
    515               normal += n * alphaBlend1.b;
    516           #endif
    517 
    518           #ifdef NORMALMAP_7
    519               n = getTriPlanarBlend(coords, blending, m_NormalMap_7, m_DiffuseMap_7_scale).xyz;
    520               normal += n * alphaBlend1.a;
    521           #endif
    522       #endif
    523 
    524       #ifdef ALPHAMAP_2
    525           #ifdef NORMALMAP_8
    526               n = getTriPlanarBlend(coords, blending, m_NormalMap_8, m_DiffuseMap_8_scale).xyz;
    527               normal += n * alphaBlend2.r;
    528           #endif
    529 
    530           #ifdef NORMALMAP_9
    531               n = getTriPlanarBlend(coords, blending, m_NormalMap_9, m_DiffuseMap_9_scale).xyz;
    532               normal += n * alphaBlend2.g;
    533           #endif
    534 
    535           #ifdef NORMALMAP_10
    536               n = getTriPlanarBlend(coords, blending, m_NormalMap_10, m_DiffuseMap_10_scale).xyz;
    537               normal += n * alphaBlend2.b;
    538           #endif
    539 
    540           #ifdef NORMALMAP_11
    541               n = getTriPlanarBlend(coords, blending, m_NormalMap_11, m_DiffuseMap_11_scale).xyz;
    542               normal += n * alphaBlend2.a;
    543           #endif
    544       #endif
    545 
    546       normal = (normal.xyz * vec3(2.0) - vec3(1.0));
    547       return normalize(normal);
    548     }
    549   #endif
    550 
    551 #endif
    552 
    553 
    554 
    555 void main(){
    556 
    557     //----------------------
    558     // diffuse calculations
    559     //----------------------
    560     #ifdef DIFFUSEMAP
    561       #ifdef ALPHAMAP
    562         #ifdef TRI_PLANAR_MAPPING
    563             vec4 diffuseColor = calculateTriPlanarDiffuseBlend(wNormal, wVertex, texCoord);
    564         #else
    565             vec4 diffuseColor = calculateDiffuseBlend(texCoord);
    566         #endif
    567       #else
    568         vec4 diffuseColor = texture2D(m_DiffuseMap, texCoord);
    569       #endif
    570     #else
    571       vec4 diffuseColor = vec4(1.0);
    572     #endif
    573 
    574         float spotFallOff = 1.0;
    575         if(g_LightDirection.w!=0.0){
    576               vec3 L=normalize(lightVec.xyz);
    577               vec3 spotdir = normalize(g_LightDirection.xyz);
    578               float curAngleCos = dot(-L, spotdir);             
    579               float innerAngleCos = floor(g_LightDirection.w) * 0.001;
    580               float outerAngleCos = fract(g_LightDirection.w);
    581               float innerMinusOuter = innerAngleCos - outerAngleCos;
    582 
    583               spotFallOff = (curAngleCos - outerAngleCos) / innerMinusOuter;
    584 
    585               if(spotFallOff <= 0.0){
    586                   gl_FragColor = AmbientSum * diffuseColor;
    587                   return;
    588               }else{
    589                   spotFallOff = clamp(spotFallOff, 0.0, 1.0);
    590               }
    591         }
    592     
    593     //---------------------
    594     // normal calculations
    595     //---------------------
    596     #if defined(NORMALMAP) || defined(NORMALMAP_1) || defined(NORMALMAP_2) || defined(NORMALMAP_3) || defined(NORMALMAP_4) || defined(NORMALMAP_5) || defined(NORMALMAP_6) || defined(NORMALMAP_7) || defined(NORMALMAP_8) || defined(NORMALMAP_9) || defined(NORMALMAP_10) || defined(NORMALMAP_11)
    597       #ifdef TRI_PLANAR_MAPPING
    598         vec3 normal = calculateNormalTriPlanar(wNormal, wVertex, texCoord);
    599       #else
    600         vec3 normal = calculateNormal(texCoord);
    601       #endif
    602     #else
    603       vec3 normal = vNormal;
    604     #endif
    605 
    606 
    607     //-----------------------
    608     // lighting calculations
    609     //-----------------------
    610     vec4 lightDir = vLightDir;
    611     lightDir.xyz = normalize(lightDir.xyz);
    612 
    613     vec2 light = computeLighting(vPosition, normal, vViewDir.xyz, lightDir.xyz)*spotFallOff;
    614 
    615     vec4 specularColor = vec4(1.0);
    616 
    617     //--------------------------
    618     // final color calculations
    619     //--------------------------
    620     gl_FragColor =  AmbientSum * diffuseColor +
    621                     DiffuseSum * diffuseColor  * light.x +
    622                     SpecularSum * specularColor * light.y;
    623 
    624     //gl_FragColor.a = alpha;
    625 }