#version 120 // Varying. varying vec3 worldNormal; varying vec3 worldPos; // Misc uniforms. uniform vec3 camPos; uniform mat4 obj2World; uniform mat4 world2Cam; // Surface calculations, including specular power. varying vec2 texCoord; vec4 viewDelta; // Fogging. uniform vec4 fogBaseColor; uniform vec4 fogConsts; uniform sampler2D fogTex; varying vec2 fogCoords; void main() { // Bricks always in world space. worldPos = (obj2World * vec4(gl_Vertex.xyz, 1.0f)).xyz; worldNormal = ((obj2World * vec4(gl_Normal.xyz, 0.0f)).xyz); if(length(gl_Normal.xyz) < 1.1f) worldNormal.xyz = normalize(worldNormal.xyz); // Do some camera delta math. viewDelta.xyz = worldPos - camPos; viewDelta.w = length(viewDelta.xyz); viewDelta.xyz = -normalize(viewDelta.xyz); worldPos.z -= pow(viewDelta.w*-0.012, 2); // Fog can be done per-vertex. fogCoords.x = clamp((fogConsts.y - viewDelta.w) * fogConsts.x, 0.0f, 1.0f); fogCoords.y = clamp((worldPos.z - fogConsts.z) * fogConsts.w, 0.0f, 1.0f); // Project the brick pos and normal. gl_Position = gl_ProjectionMatrix * world2Cam * vec4(worldPos, 1.0f); // Pass color through. gl_FrontColor = gl_Color; // Pass texcoords through. texCoord = gl_MultiTexCoord0.st; }