Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. // https://tutorialsplay.com/opengl/2014/09/26/lesson-15-water-with-opengl-on-the-gpu-with-glsl/
  2.  
  3. uniform float waveTime;
  4. uniform float waveWidth;
  5. uniform float waveHeight;
  6. uniform float waveLength;
  7.  
  8. varying vec3 Normal;
  9. varying vec3 EyeDir;
  10.  
  11. uniform int lighttype;
  12. varying vec4 diffuse,ambientGlobal,ambient,ecPos;
  13. varying vec3 normal,halfVector;
  14.  
  15. void main(void)
  16. {
  17. if (lighttype == 1) // directional light
  18. {
  19. /* first transform the normal into eye space and normalize the result */
  20. normal = normalize(gl_NormalMatrix * gl_Normal);
  21.  
  22. /* pass the halfVector to the fragment shader */
  23. halfVector = gl_LightSource[0].halfVector.xyz;
  24.  
  25. /* Compute the diffuse, ambient and globalAmbient terms */
  26. diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
  27. ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
  28. ambient += gl_LightModel.ambient * gl_FrontMaterial.ambient;
  29. }
  30.  
  31. if (lighttype == 2 || lighttype == 3) // point or spot light
  32. {
  33. vec3 aux;
  34.  
  35. /* first transform the normal into eye space and normalize the result */
  36. normal = normalize(gl_NormalMatrix * gl_Normal);
  37.  
  38. /* compute the vertex position in camera space. */
  39. ecPos = gl_ModelViewMatrix * gl_Vertex;
  40.  
  41. /* Normalize the halfVector to pass it to the fragment shader */
  42. halfVector = gl_LightSource[0].halfVector.xyz;
  43.  
  44. /* Compute the diffuse, ambient and globalAmbient terms */
  45. diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse;
  46. ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
  47. ambientGlobal = gl_LightModel.ambient * gl_FrontMaterial.ambient;
  48. }
  49.  
  50. // wave deformation
  51. //vec4 v = vec4(gl_Vertex);
  52. //v.y = sin(waveWidth * v.x + waveTime) * cos(waveLength * v.z + waveTime) * waveHeight;
  53. //gl_Position = gl_ModelViewProjectionMatrix * v;
  54. gl_Position = gl_ModelViewProjectionMatrix;
  55. gl_TexCoord[0] = gl_MultiTexCoord0;
  56.  
  57. // specular cubemap
  58. Normal = normalize(-(gl_NormalMatrix * gl_Normal));
  59. EyeDir = (gl_ModelViewMatrix * gl_Vertex).xyz;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement