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 11// #define gouraud 12 13void main() { 14 g_position = u_worldTrans * applySkinning(g_position); 15 gl_Position = u_projViewTrans * g_position; 16 17 // Pass the attributes values to the fragment shader 18 pushPosition(); 19 20#ifdef normalTextureFlag 21 calculateTangentVectors(); 22 pushBinormal(); 23 pushTangent(); 24#endif 25 26 passNormalValue(normalize(u_normalMatrix * applySkinning(g_normal))); 27 pushColor(); 28 pushTexCoord0(); 29 30 passShadowMapUV(calcShadowMapUV(g_position)); 31 passFog(calculateFog(g_position, u_cameraPosition)); 32 33 #ifdef gouraud 34 applyLights(g_position, normalize(u_cameraPosition.xyz - g_position.xyz), g_normal, u_shininess); 35 passLights(); 36 #endif 37} 38 39 40[FS] 41#ifdef GL_ES 42#define LOWP lowp 43#define MED mediump 44#define HIGH highp 45precision mediump float; 46#else 47#define MED 48#define LOWP 49#define HIGH 50#endif 51 52#include "g_attributes.glsl:FS" 53#include "u_uniforms.glsl" 54#include "common.glsl:FS" 55#include "common.glsl:colorDiffuseFS" 56#include "common.glsl:colorSpecularFS" 57#include "lights.glsl:FS" 58#include "light_gouraud.glsl" 59#include "shadowmap.glsl:FS" 60 61#ifdef fogFlag 62uniform vec4 u_fogColor; 63varying float v_fog; 64#endif // fogFlag 65 66// #define gouraud 67 68void main() { 69 pullColor(); 70 pullTexCoord0(); 71 pullNormal(); 72 73#ifdef normalTextureFlag 74 pullBinormal(); 75 pullTangent(); 76 77 vec3 normal = normalize(texture2D(u_normalTexture, g_texCoord0).xyz * 2.0 - 1.0); 78 g_normal = normalize((g_tangent * normal.x) + (g_binormal * normal.y) + (g_normal * normal.z)); 79#endif 80 81 #ifdef gouraud 82 pullLights(); 83 #else 84 applyLights(g_position, normalize(u_cameraPosition.xyz - g_position.xyz), g_normal, u_shininess); 85 #endif 86 87 vec4 diffuse = applyColorDiffuse(g_color); 88 89 #if (!defined(lightingFlag)) 90 gl_FragColor.rgb = diffuse.rgb; 91 #elif (!defined(specularFlag)) 92 #if defined(ambientFlag) && defined(separateAmbientFlag) 93 #ifdef shadowMapFlag 94 gl_FragColor.rgb = (diffuse.rgb * (g_lightAmbient + getShadow() * g_lightDiffuse)); 95 //gl_FragColor.rgb = texture2D(u_shadowTexture, v_shadowMapUv.xy); 96 #else 97 gl_FragColor.rgb = (diffuse.rgb * (g_lightAmbient + g_lightDiffuse)); 98 #endif //shadowMapFlag 99 #else 100 #ifdef shadowMapFlag 101 gl_FragColor.rgb = getShadow() * (diffuse.rgb * g_lightDiffuse); 102 #else 103 gl_FragColor.rgb = (diffuse.rgb * g_lightDiffuse); 104 #endif //shadowMapFlag 105 #endif 106 #else 107 vec3 specular = applyColorSpecular(g_lightSpecular); 108 109 #if defined(ambientFlag) && defined(separateAmbientFlag) 110 #ifdef shadowMapFlag 111 gl_FragColor.rgb = (diffuse.rgb * (getShadow() * g_lightDiffuse + g_lightAmbient)) + specular; 112 //gl_FragColor.rgb = texture2D(u_shadowTexture, v_shadowMapUv.xy); 113 #else 114 gl_FragColor.rgb = (diffuse.rgb * (g_lightDiffuse + g_LightAmbient)) + specular; 115 #endif //shadowMapFlag 116 #else 117 #ifdef shadowMapFlag 118 gl_FragColor.rgb = getShadow() * ((diffuse.rgb * g_lightDiffuse) + specular); 119 #else 120 gl_FragColor.rgb = (diffuse.rgb * g_lightDiffuse) + specular; 121 #endif //shadowMapFlag 122 #endif 123 #endif //lightingFlag 124 125 #ifdef fogFlag 126 gl_FragColor.rgb = mix(gl_FragColor.rgb, u_fogColor.rgb, v_fog); 127 #endif // end fogFlag 128 129 #ifdef blendedFlag 130 gl_FragColor.a = diffuse.a * v_opacity; 131 #ifdef alphaTestFlag 132 if (gl_FragColor.a <= v_alphaTest) 133 discard; 134 #endif 135 #endif 136 137} 138