VertShader.vsh 949 B

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