#version 330 // Input vertex attributes in vec3 vertexPosition; in vec2 vertexTexCoord; in vec3 vertexNormal; in vec4 vertexColor; // Input uniform values uniform mat4 mvp; uniform mat4 matModel; uniform sampler2D texture0; // Output vertex attributes (to fragment shader) out vec2 fragTexCoord; out vec4 fragColor; // NOTE: Add your custom variables here out vec3 worldPosition; out vec3 worldNormal; void main() { // Send vertex attributes to fragment shader fragTexCoord = vertexTexCoord; fragColor = vertexColor; float l = textureOffset(texture0, vertexTexCoord, ivec2(-1, 0)).x; float r = textureOffset(texture0, vertexTexCoord, ivec2(1, 0)).x; float u = textureOffset(texture0, vertexTexCoord, ivec2(0, -1)).x; float d = textureOffset(texture0, vertexTexCoord, ivec2(0, 1)).x; vec3 lr = normalize(vec3(1, 0, r - l)); vec3 ud = normalize(vec3(0, 1, u - d)); vec3 normal = normalize(cross(lr, ud)); vec3 localPos = vertexPosition + vec3(0, texture2D(texture0, vertexTexCoord).x * 0.1, 0); // Calculate final vertex position gl_Position = mvp*vec4(localPos, 1.0); worldPosition = (matModel * vec4(localPos, 1.0)).xyz; worldNormal = mat3(matModel) * normal; }