/////////////////////////////////////////////////////////// // Attributes attribute vec3 a_position; attribute vec2 a_texCoord; attribute vec4 a_color; /////////////////////////////////////////////////////////// // Uniforms uniform mat4 u_projectionMatrix; /////////////////////////////////////////////////////////// // Varyings varying vec2 v_texCoord; varying vec4 v_color; #if defined(TEXTURE_REPEAT) uniform vec2 u_textureRepeat; #endif #if defined(TEXTURE_OFFSET) uniform vec2 u_textureOffset; #endif #if defined(NO_Z_FIGHTING) // Éî¶ÈÆ«ÒÆÖµ uniform float u_depthOffset; #endif varying float v_fogFactor; //fog factor //fog parameter uniform vec4 u_fogparam; // .x, .y, .z, .w stand for fog density, fog start, fog end, fog type. fog type 0, no fog, fog type 1 linear fog, fog type 2 exp fog, fog type 3 exp2 fog void main() { gl_Position = u_projectionMatrix * vec4(a_position, 1); v_texCoord = a_texCoord; v_color = a_color; #if defined(NO_Z_FIGHTING) gl_Position.z -= u_depthOffset; #endif #if defined(TEXTURE_REPEAT) v_texCoord *= u_textureRepeat; #endif #if defined(TEXTURE_OFFSET) v_texCoord += u_textureOffset; #endif #if defined(FOG) // linear fog #if FOG == 1 float z = gl_Position.z;//(u_worldViewMatrix * position).z; v_fogFactor = (u_fogparam.z - z) / (u_fogparam.z - u_fogparam.y); v_fogFactor = clamp(v_fogFactor, 0.0, 1.0); // exp fog #elif FOG == 2 float z = gl_Position.z;//(u_worldViewMatrix * position).z; const float LOG2 = 1.442695; v_fogFactor = exp2( -u_fogparam.x * z * LOG2 ); v_fogFactor = clamp(v_fogFactor, 0.0, 1.0); // exp2 fog #elif FOG == 3 float z = gl_Position.z;//(u_worldViewMatrix * position).z; const float LOG2 = 1.442695; v_fogFactor = exp2( -u_fogparam.x * u_fogparam.x * z * z * LOG2 ); v_fogFactor = clamp(v_fogFactor, 0.0, 1.0); #endif #endif }