1 attribute highp vec3 inVertex; 2 attribute mediump vec3 inNormal; 3 attribute mediump vec2 inTexCoord; 4 5 uniform highp mat4 MVPMatrix; 6 uniform mediump vec3 LightDirection; 7 uniform mediump float DisplacementFactor; 8 9 varying lowp float LightIntensity; 10 varying mediump vec2 TexCoord; 11 12 uniform sampler2D sDisMap; 13 14 void main() 15 { 16 /* 17 Calculate the displacemnt value by taking the colour value from our texture 18 and scale it by out displacement factor. 19 */ 20 mediump float disp = texture2D(sDisMap, inTexCoord).r * DisplacementFactor; 21 22 /* 23 Transform position by the model-view-projection matrix but first 24 move the untransformed position along the normal by our displacement 25 value. 26 */ 27 gl_Position = MVPMatrix * vec4(inVertex + (inNormal * disp), 1.0); 28 29 // Pass through texcoords 30 TexCoord = inTexCoord; 31 32 // Simple diffuse lighting in model space 33 LightIntensity = dot(inNormal, -LightDirection); 34 }