Delta

GLSL shaders

Apr 3rd, 2011
478
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script type="x-shader/x-vertex" id="vs">
  2. attribute vec3 VertexPosition;
  3. attribute vec3 VertexNormal;
  4. attribute vec2 TextureCoord;
  5.  
  6. uniform mat4 World;
  7. uniform mat4 View;
  8. uniform mat4 Projection;
  9.  
  10. uniform vec3 AmbientLight;
  11. uniform float AmbientLightIntensity;
  12.  
  13. uniform vec3 DiffuseLight;
  14. uniform float DiffuseLightIntensity;
  15. uniform vec3 DiffuseLightSource;
  16. uniform mat4 WorldTransposedInverse;
  17.  
  18. varying vec2 TexCoord;
  19. varying vec4 Lighting;
  20.  
  21. void main(void)
  22. {
  23. gl_Position = Projection * View * World * vec4(VertexPosition, 1.0);
  24. TexCoord = TextureCoord;
  25.  
  26. vec4 Normal = normalize(WorldTransposedInverse * vec4(VertexNormal, 1.0));
  27. float DiffuseLightVertexIntensity = dot(Normal, normalize(vec4(DiffuseLightSource, 1.0)));
  28.  
  29. Lighting = vec4(AmbientLight * AmbientLightIntensity + DiffuseLight * DiffuseLightIntensity * DiffuseLightVertexIntensity, 1.0);
  30. }
  31. </script>
  32.  
  33. <script type="x-shader/x-fragment" id="fs">
  34. #ifdef GL_ES
  35. precision highp float;
  36. #endif
  37.  
  38. varying vec2 TexCoord;
  39. varying vec4 Lighting;
  40.  
  41. uniform sampler2D SamplerState;
  42. uniform bool EnableLighting;
  43.  
  44. void main(void)
  45. {
  46. vec4 textureColor = vec4(texture2D(SamplerState, TexCoord).rgb, 1.0);
  47. if(EnableLighting)
  48. gl_FragColor = clamp(textureColor + Lighting, 0.0, 1.0);
  49. else
  50. gl_FragColor = textureColor;
  51. }
  52. </script>
RAW Paste Data