1[VS] 2#include "g_attributes.glsl:VS" 3#include "u_uniforms.glsl" 4#include "skinning.glsl" 5#include "common.glsl:VS" 6#include "common.glsl:tangentVectorsVS" 7#include "lights.glsl:VS" 8#include "light_gouraud.glsl" 9#include "shadowmap.glsl:VS" 10 11void main() { 12 g_position = u_worldTrans * applySkinning(g_position); 13 gl_Position = u_projViewTrans * g_position; 14 15 applyLights(g_position, 16 normalize(u_cameraPosition.xyz - g_position.xyz), 17 normalize(u_normalMatrix * applySkinning(g_normal)), 18 u_shininess); 19 20 // Pass attributes values to the fragment shader 21 passLights(); 22 pushColor(); 23 pushTexCoord0(); 24 passFog(calculateFog(g_position, u_cameraPosition)); 25 passShadowMapUV(calcShadowMapUV(g_position)); 26} 27 28 29[FS] 30#ifdef GL_ES 31#define LOWP lowp 32#define MED mediump 33#define HIGH highp 34precision mediump float; 35#else 36#define MED 37#define LOWP 38#define HIGH 39#endif 40 41#include "g_attributes.glsl:FS" 42#include "u_uniforms.glsl" 43#include "common.glsl:FS" 44#include "common.glsl:colorDiffuseFS" 45#include "common.glsl:colorSpecularFS" 46#include "lights.glsl:FS" 47#include "shadowmap.glsl:FS" 48 49#ifdef fogFlag 50uniform vec4 u_fogColor; 51varying float v_fog; 52#endif // fogFlag 53 54void main() { 55 pullLights(); 56 pullColor(); 57 pullTexCoord0(); 58 59 vec4 diffuse = applyColorDiffuse(g_color); 60 61 #if (!defined(lightingFlag)) 62 gl_FragColor.rgb = diffuse.rgb; 63 #elif (!defined(specularFlag)) 64 #if defined(ambientFlag) && defined(separateAmbientFlag) 65 #ifdef shadowMapFlag 66 gl_FragColor.rgb = (diffuse.rgb * (g_lightAmbient + getShadow() * g_lightDiffuse)); 67 //gl_FragColor.rgb = texture2D(u_shadowTexture, v_shadowMapUv.xy); 68 #else 69 gl_FragColor.rgb = (diffuse.rgb * (g_lightAmbient + g_lightDiffuse)); 70 #endif //shadowMapFlag 71 #else 72 #ifdef shadowMapFlag 73 gl_FragColor.rgb = getShadow() * (diffuse.rgb * g_lightDiffuse); 74 #else 75 gl_FragColor.rgb = (diffuse.rgb * g_lightDiffuse); 76 #endif //shadowMapFlag 77 #endif 78 #else 79 vec3 specular = applyColorSpecular(g_lightSpecular); 80 81 #if defined(ambientFlag) && defined(separateAmbientFlag) 82 #ifdef shadowMapFlag 83 gl_FragColor.rgb = (diffuse.rgb * (getShadow() * g_lightDiffuse + g_lightAmbient)) + specular; 84 //gl_FragColor.rgb = texture2D(u_shadowTexture, v_shadowMapUv.xy); 85 #else 86 gl_FragColor.rgb = (diffuse.rgb * (g_lightDiffuse + g_LightAmbient)) + specular; 87 #endif //shadowMapFlag 88 #else 89 #ifdef shadowMapFlag 90 gl_FragColor.rgb = getShadow() * ((diffuse.rgb * g_lightDiffuse) + specular); 91 #else 92 gl_FragColor.rgb = (diffuse.rgb * g_lightDiffuse) + specular; 93 #endif //shadowMapFlag 94 #endif 95 #endif //lightingFlag 96 97 #ifdef fogFlag 98 gl_FragColor.rgb = mix(gl_FragColor.rgb, u_fogColor.rgb, v_fog); 99 #endif // end fogFlag 100 101 #ifdef blendedFlag 102 gl_FragColor.a = diffuse.a * v_opacity; 103 #ifdef alphaTestFlag 104 if (gl_FragColor.a <= v_alphaTest) 105 discard; 106 #endif 107 #endif 108 109} 110